a4j:selectOneMenu triggering rerendering
ufonaut Jun 8, 2010 4:22 AMI've got a form, one panel of which is dynamically loaded. The user makes a choice from a selectOneMenu. Based on that choice, an "add" a4j:commandButton may be rendered. If it is and the user hits it, the dynamically loaded panel is then opened with the appropriate xhtml.
So, the code is as follows:
{code:xml}
<a4j:form id="myForm">
<h:panelGroup id="detailsPanel" layout="block">
<a4j:region>
<c:set var="beanName" value="#{myController.beanName}" />
<a4j:include viewId="somepath/#{beanName}.xhtml"
id="#{beanName}Include"
ajaxRendered="false"/>
</a4j:region></h:panelGroup>
<a4j:region>
<h:selectOneMenu id="level1"
value="#{myController.level1Value}"
>
<a4j:support event="onchange"
limitToList="true" reRender="addButton"
ajaxSingle="true" />
<s:selectItems
value="#{myController.level1ValueList}"
var="t" label="#{t.code}"
noSelectionLabel="${msgs.noSelectionMessage}"
hideNoSelectionLabel="true" />
</h:selectOneMenu>
</a4j:region>
<a4j:commandButton id="addButton" value="#{msgs.add}"
ajaxSingle="true"
disabled="#{myController.addButtonDisabled}"
action="#{myController.openDetails}"
reRender="detailsPanel"
/>
</a4j:form>{code}
myController is a very simple bean - none of the methods here reference FacesContext, etc.
What's happening is :
- Page opens
- User makes a selection from "level1", and addButton becomes enabled
- User hits addButton, and detailsPanel is rendered correctly
- User makes another selection from "level1" (that would also enable the addButton)
And an exception is thrown by the detailsPanel Note that this is the onchange from the selectOneMenu - the user has not hit the addButton !
I'm not actually bothered about the exception (it's just a consequence of the 'openDetails' method not being called).
What I am bothered about is that detailsPanel is being rendered from this selectOneMenu onchange event. All I want out of that event is to reRender the addButton - no more! That's why I've tried wrapping it in a4j:regions, put in limitToList, etc.
Why is the detailsPanel even being looked at when the selectOneMenu's onchange event is fired? and what more can I do to get it to not be looked at?