2

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?

4

1 回答 1

2

如果您将属性 immediate="true" 添加到您的输入元素,这些值将在“应用请求值”阶段应用,因此会在您的操作执行之前出现。您可能需要也可能不需要将 commandButton 上的 immediate 属性设置为 true。

于 2010-05-27T04:35:35.563 回答