0

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>  
Berek Bryan
  • 13,755
  • 10
  • 32
  • 43
  • *"It is not being rendered however"* How did you confirm this? Is the desired HTML missing in the ajax response? Or did something else (not) happen instead? – BalusC Jan 09 '13 at 16:22
  • I simply put a printout statement in the method and displayed the size of the user list at the start and end of the method. The user list is populated in the setter method of the selectedTransferGroup member. – Berek Bryan Jan 09 '13 at 16:25
  • 1
    Uhm. Press F12 in Chrome/IE9/Firebug. Open *Net(work)* tab. Look in the ajax response. How does the HTML representation of `` look like? Does it contain the updated items? – BalusC Jan 09 '13 at 16:26
  • i agree. this is inherited code. i will move the logic into a separate method and get back to you. thanks for the help. – Berek Bryan Jan 09 '13 at 16:42
  • Is the bean's scope correct (i.e. at least viewScoped)? – perissf Jan 09 '13 at 16:46
  • yes it is. i think i found the issue. that is not the response. i was looking at the wrong one. this is the response i am getting 'class java.lang.IllegalArgumentException'. this is in a tab view and it seems i have an error in another tab that is messing with the ajax – Berek Bryan Jan 09 '13 at 16:51
  • i removed the id from the selectBooleanCheckbox and the user selectOneMenu is working now. – Berek Bryan Jan 09 '13 at 17:20

1 Answers1

1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555