1 Reply Latest reply on Aug 22, 2007 7:51 AM by Pete Muir

    toggle button for read only/editable text area-how to do?

    Mike Kohout Newbie

      Hello all-

      Being more of a JSF/Seam newbie...What is the best way to accomplish what I'm doing?

      I've got a textfield on a page, and I want to toggle it's editability via a set of buttons on the page.

      This is my first attempt which doesn't work:
      I've got an event scoped action/backing bean-like object named ViewTeam(that extends EntityHome) that has a Boolean property named goalReadOnly. The purpose of this property is to control the
      "readonly" attribute of a h:inputTextarea component.

      Within my form, I've got 2 a4j:commandButtons that control the value of ViewTeam.goalReadOnly-they themselves are only rendered when appropriate( when ViewTeam.goalReadOnly == true, the button that sets it to false is displayed and for the other button when the converse is true ).
      I've also got a hidden form field who's value is the ViewTeam.goalReadOnly

      This code fails in two ways-
      1) After clicking the "edit goal" button, the textbox becomes editable and the "end edit goal" button becomes visible. However, when the "end edit goal" button is clicked, the value of ViewTeam.goalReadOnly does not change.
      2) any values entered into the textbox when the box is editable are not persisted.

      here's the facelet:

       <s:decorate id="teamGoalDecoration" template="edit.xhtml">
       <ui:define name="label">Goals</ui:define>
       <ui:define name="required">false</ui:define>
       <h:inputTextarea id="goalText" readonly="false" value="#{viewTeamAction.instance.goal}" />
       <a4j:commandButton type="submit" value="Finish Edit Goal" immediate="true" reRender="viewTeamPanel" action="#{viewTeamAction.setGoalReadOnly(true)}" rendered="#{viewTeamAction.goalReadOnly eq false}" />
       <a4j:commandButton type="submit" value="Edit Goal" immediate="true" reRender="viewTeamPanel" action="#{viewTeamAction.setGoalReadOnly(false)}" rendered="#{viewTeamAction.goalReadOnly eq true}"/>
       <h:inputHidden id="hidden" value="#{viewTeamAction.goalReadOnly}" />

      here's a portion of the action:
      @Name(value = "viewTeamAction")
      @Scope(value = ScopeType.EVENT)
      public class ViewTeam extends TeamHome { //TeamHome extends EntityHome
      @In(required = true)
       User user;
       Long teamID;
       Log log;
       private Boolean goalReadOnly;
       public void create() {
       goalReadOnly = new Boolean(true);
       public Team getInstance() {
       log.error("passed in teamID is " + this.getTeamID());
       if ((this.instance == null )||(!this.teamID.equals(this.instance.getId()))) {
       Team t = this.getEntityManager().find(Team.class, teamID);
       if (user.getTeams().contains(t)) {
       this.instance = t;
       } else {
       throw new RuntimeException("This user is not a member of this team!");
       return this.instance;
       public Boolean getGoalReadOnly() {
       return goalReadOnly;
       public void setGoalReadOnly(Boolean editGoal) {
       log.error("setting editGoal=" + editGoal);
       this.goalReadOnly = editGoal;

      Any ideas?