Question

Update via ajax seems to work fine but I can't get richfaces polling working. To be precise: output element with id someoutput2 doesn't get updated after 1000ms by a4j:poll element Here is the code of the page:

<h:body>
    <h:form id="baseForm">
        <h:outputText value="Input field"/>
        <br/>
        <h:inputText value="#{valueBean.value}"> 
            <f:ajax event="keyup" render="baseForm:someOutput"/> 
        </h:inputText>
        <br/>
        <br/>
        <h:outputText value="Updated via AJAX:" style="color:red"/>
        <br/>
        <h:outputText id="someOutput" value="#{valueBean.value}" />
        <br/>

        <h:outputText value="Updated via Polling:" style="color:green"/>
        <br/>
        <!-- Polling target -->
        <h:outputText id="someOutput2" value="#{valueBean.value}" />
    </h:form> 

    <a4j:region>
        <h:form id="pollForm">
           <a4j:poll id="poll" interval="1000" timeout="500" enabled="true" reRender="pollForm:poll baseForm:someOutput2"/>
        </h:form>
    </a4j:region>
</h:body>

Here is the code of the value bean (nothing fancy here):

@ManagedBean
@SessionScoped
public class ValueBean {
    private String value = "";

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
Was it helpful?

Solution

You cannot update components such as <h:outputText> directly, you have to call the reRender on their parent. In this case you'd probably want to wrap the output in <a4j:outputPanel> and rerender the panel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top