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 file开发者_JAVA技巧Number term"
render="otherElement" />
</h:commandButton>
</h:form>
Any ideas? Thanks
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:
- Difference between View and Request scope in managed beans
- How to choose the right bean scope?
精彩评论