简体   繁体   中英

Ajax not rendering new data for <h:selectOneMenu>

I am trying to update a selectOneMenu from the results of another selectOneMenu.

When group is selected the user menu should be updated.

I have verified that the data for the user menu is being updated. It is not being rendered however.

Currently running Primefaces 3.4.2 and JSF 2.1

<ui:composition>
<br/><br/>
<h:form id="transferForm">            
    <h:panelGrid columns="1" style="width: 500px;margin: auto;text-align: center"  >
        <h:panelGroup>
            <h:outputLabel for="group" value="Group" />
            <h:selectOneMenu id="group" value="#{projectBean.transferUtil.selectedTransferGroup}" >
                <f:selectItems value="#{projectBean.transferUtil.transferGroups}" />     
                <f:ajax execute="group" render="user" />
            </h:selectOneMenu>


            <br />

            <h:outputLabel for="user" value="User" />
            <h:selectOneMenu id="user" value="#{projectBean.transferUtil.selectedTransferUser}" required="true" requiredMessage="Select User" >
                <f:selectItems value="#{projectBean.transferUtil.transferUsers}" />
            </h:selectOneMenu>
        </h:panelGroup>
        <p:commandButton id="projectTransferButton" action="#{projectBean.transferUtil.transfer}" value="Transfer" update=":projtabs,:growlForm:growlMesg">
            <f:setPropertyActionListener target="#{projectBean.activeTab}" value="#{projectBean.project_tab_index}" />
        </p:commandButton>
    </h:panelGrid>
</h:form>
<br/><br/>

[EDIT]

Alright this is the error I am getting.

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class java.lang.IllegalArgumentException</error-name><error-message><![CDATA[rss02.1 OPERA]]></error-message></error></partial-response>

And this is the code in question.

    <p:dataGrid var="area" value="#{projectBean.projectUtil.project.rssAreas}" columns="1">
        <p:column>
            <h:selectBooleanCheckbox id="rss#{area.shortName}" label="#{area.name}" value="#{area.active}" />
            <h:outputText value="#{area.name}" />
        </p:column>
    </p:dataGrid>  

You should not perform business logic in getters/setters. They are invoked multiple times in JSF lifecycle and are intented to get and set the property. You should perform business logic in action(listener) methods instead.

The following construct should work:

<h:selectOneMenu id="group" value="#{projectBean.transferUtil.selectedTransferGroup}" >
    <f:selectItems value="#{projectBean.transferUtil.transferGroups}" />     
    <f:ajax execute="group" listener="#{projectBean.transferGroupChanged}" render="user" />
</h:selectOneMenu>
<h:selectOneMenu id="user" value="#{projectBean.transferUtil.selectedTransferUser}" required="true" requiredMessage="Select User" >
    <f:selectItems value="#{projectBean.transferUtil.transferUsers}" />
</h:selectOneMenu>

With

public void transferGroupChanged(AjaxBehaviorEvent event) {
    // Change the transferUsers here.
}

The getters and setters should not contain any business logic. They should merely get and set the property.

See also:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM