JSF 2 f:ajax lifecycle problem

Posted by gerry on Stack Overflow See other posts from Stack Overflow or by gerry
Published on 2010-05-21T13:17:01Z Indexed on 2010/05/21 13:20 UTC
Read the original article Hit count: 319

Filed under:
|
|
|
|

The problem is, that if a property is changed during an f:ajax request and a binded panelGroup should be newly created depending on that changed value, the old value is used.

This code will explain the problem.

Here is the backingbean TestBean:

public String getFirst() {
        return first;
    }
    public void setFirst(String first) {
        this.first = first;
    }
    public String getLast() {
        return last;
    }
    public void setLast(String last) {
        this.last = last;
    }

    public String getName(){
        return first+" "+last; 
    }
public void setDynamicPanel(HtmlPanelGroup panel){ }

    public HtmlPanelGroup getDynamicPanel(){
        Application app = FacesContext.getCurrentInstance().getApplication();
        HtmlPanelGroup component = (HtmlPanelGroup)app.createComponent(HtmlPanelGroup.COMPONENT_TYPE);

        HtmlOutputLabel label1 = (HtmlOutputLabel)app.createComponent(HtmlOutputLabel.COMPONENT_TYPE);
        label1.setValue(" --> "+getFirst()+" "+getLast());
        component.getChildren().add(label1);
        return component;
    }

and now the jsf/facelet code:

<h:form id="form">
    <h:panelGrid columns="1">
        <h:inputText id="first" value="#{testBean.first}" />
        <h:inputText id="last" value="#{testBean.last}" />
        <h:commandButton value="Show">
            <f:ajax execute="first last" render="name dyn" />
        </h:commandButton>
    </h:panelGrid>
    <h:outputText id="name" value="#{testBean.name}" />
    <h:panelGroup id="dyn" binding="#{testBean.dynamicPanel}" />
</h:form>

After the page was initially loaded the outputText and panelGroup shows both "null" as first and last. But after the button is pressed, the outputText is updated well, but the the panelgroup shows again only "null". This is due to the problem, that the "binded method" dynamicPanel is executed before the update of the first and last properties.

how can workaround this behaviour or what is wrong with my code?

© Stack Overflow or respective owner

Related posts about jsf

Related posts about jsf2