0
votes

I have a composite component

       <co:interface>
            <co:attribute name="editAction"     required="false"  targets="edit"   method-signature="java.lang.String f()"/>
            <co:attribute name="saveAction"     required="false"  targets="save"   method-signature="java.lang.String f()"/>
            <co:attribute name="isBrowseModus"  required="true"/>
            <co:attribute name="user"           required="true"/>
            <co:attribute name="editListener"   targets="edit" method-signature="void f(javax.faces.event.ActionEvent)" />
            <co:actionSource name="save"/>
        </co:interface>
        <co:implementation>
............
        <p:inplace id="inpLand" editor="true" 
            toggleable="#{not cc.attrs.isBrowseModus}" 
            style="#{cc.attrs.isBrowseModus ? 'color: black' : 'color: blue'}">  
                <p:inputText value="#{cc.attrs.user.land}" label="text"/>  
        </p:inplace>  
...........
        <c:if test="#{cc.attrs.isBrowseModus}">
           <p:commandButton id="edit" value="#{msgs.co_userdata_button_edit}" icon="ui-icon-unlocked" actionListener="#{cc.attrs.editListener}"/>
        </c:if>

Actually this composite component is called by a view calling myData.xhtml:

    <h:form id="dataForm">  
        <mc:UserData user="#{dataBean.user}" 
               isBrowseModus="#{dataBean.browseModus}"
               saveAction="#{dataBean.save}" 
               editListener="#{dataBean.editActionListener}">
        </mc:UserData>   
    </h:form>  

What is my aim: Within that composite component an user is able by clicking the "edit" button to change any user data. I prefer using the inplace tag of PRIMEFACES. After clicking the edit button all the changeable fields should be shown in blue color (see composite component).

My problem is that I don't know how to update the isBrowseModus flag (define as cc-attribute) to false. Actually I do it within the editActionListener (define in the managedBean) but unfortunately without any results.

Extract from managed bean (dataBean):

....
    public boolean isBrowseModus() {
        return browseModus;
    }

    public void setBrowseModus(boolean browseModus) {
        this.browseModus = browseModus;
    }


    public void editActionListener(ActionEvent event) {
        browseModus = false;
        FacesContext.getCurrentInstance().renderResponse();
    }
....

Im not as familiar in JSF as it's maybe necessary because I've been working with JSF since one month. Maybe there is a more convenient method to achive this result. But unfortunately I don't know how. Is there anybody who could help me to solve this problem?

Many thanks in advance. Regards, Bodo

1

1 Answers

0
votes

boolean variable is getting passed by data, cc.attrs.isBrowseModus has nothing to do with browseModus in your databean . Ideal solution would be to keep Boolean object so that the reference is passed , but since Boolean wrapper in Java is also immutable , you need to use something which holds a boolean value , like MutableBoolean class from commons-lang.

<h:form id="dataForm">  
        <mc:UserData user="#{dataBean.user}" 
               isBrowseModus="#{dataBean.browseModus}"
               saveAction="#{dataBean.save}" 
               editListener="#{dataBean.editActionListener}">
        </mc:UserData>   
    </h:form>

...
 <p:inplace id="inpLand" editor="true" 
            toggleable="#{not cc.attrs.isBrowseModus.value}" 
            style="#{cc.attrs.isBrowseModus ? 'color: black' : 'color: blue'}">  
                <p:inputText value="#{cc.attrs.user.land}" label="text"/>  
        </p:inplace>  
...



....
MutableBoolean browseModus = new MutableBoolean();

    public MutableBoolean isBrowseModus() {
        return browseModus;
    }

    public void setBrowseModus(MutableBoolean browseModus) {
        this.browseModus = browseModus;
    }


    public void editActionListener(ActionEvent event) {
        browseModus.setValue(true);
        FacesContext.getCurrentInstance().renderResponse();
    }
....