3

I am having trouble with multiple ajax calls on the same page. The first ajax call on a "blur" event populates a drop down. Then when the button is clicked, the page is supposed to display "otherElement" based upon the values in the form. The problem is when "term" is in the execute of the last ajax call, It also causes the term, CompanyCode and fileNumber to be null in the FormBean. When I statically populate the terms, it works.

<h:form id="createRequest">

            <h:selectOneMenu id="CompanyCode" required="true"
                value="#{FormBean.CompanyCode}"> 
                <f:selectItems value="#{utility.Companies}" />
            </h:selectOneMenu>
            <br/>

            <h:inputText id="fileNumber" styleClass="field"
                value="#{FormBean.fileNumber}"
                required="true">
                <f:ajax event="blur" execute="CompanyCode fileNumber"
                    render="term" />
            </h:inputText>
            <br />

            <h:selectOneMenu id="term" required="true"
                value="#{FormBean.term}">
                <f:selectItems value="#{FormBean.terms}" />
            </h:selectOneMenu>

            <br />

            <h:commandButton class="button" style="button"
                value="#{resources['btn.common.submitRequest']}">
                <f:ajax event="click"
                    execute="CompanyCode fileNumber term"
                    render="otherElement" />
            </h:commandButton>

        </h:form>

Any ideas? Thanks

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ryan
  • 1,370
  • 1
  • 13
  • 31

1 Answers1

2

Your bean is likely request scoped which causes that it get recreated again and again on every HTTP request (ajax or not). All changes/properties set by ajax requests get lost then on subsequent requests. You need to put the bean in the view scope.

@ManagedBean
@ViewScoped
public class FormBean implements Serializable {
    // ...
}

This way the bean will live as long as you return void or null from action methods.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Brilliant! That was it. I figured the solution was fairly simple, I just couldn't find it. Thanks a lot. – Ryan May 04 '11 at 15:11