Invalid selections mono
I have a selectonemenu that includes some items. And a zero item to show "please select one" .. My goal is to ask for some data when I select one of them. And if I choose "please pick one", do something else.
But in the end the change event is fired for normal values, but if I select "please select one" it will not be fired. Thank you for your help. Here is my code.
<p:selectOneMenu style="width: 200px" id="positionForward" value="#{hrProcessController.queryCriteria.positionForward}" converter="listConverter"
effect="fade" var="u" filter="true" filterMatchMode="startsWith" validator="#{hrProcessController.isOpenPositionForwValid}">
<f:selectItem itemLabel="#{menu['onemenu.choose']}" itemValue="#{null}"/>
<f:selectItems value="#{hrProcessController.positionList}" var="position" itemLabel="#{position.name}" itemValue="#{position}" />
<p:ajax event="change" listener="#{hrProcessController.onPositionSelect}" update="openPositionForward"/>
<p:column>
<h:outputText value="#{u==null ? menu['onemenu.choose'] : u.name}" />
</p:column>
</p:selectOneMenu>
public void onPositionSelect()
{
if(queryCriteria.getPositionForward()!=null)
{
OpenPositionQueryCriteria criteria = new OpenPositionQueryCriteria();
criteria.setPosition(queryCriteria.getPositionForward());
List<OpenPosition> openPositions = openPositionService.searchOpenPosition(criteria);
setOpenPositionList(openPositions);
}
else
{
List<OpenPosition> positions = openPositionService.getActiveOpenPositionList();
setOpenPositionList(positions);
}
}
source to share
I had the same problem. Change the event DO NOT DELETE by choosing the default value. Why is it so far from me. This is usually normal. I haven't found a real solution. You should try to write a custom validator and converter for this. Try this: Using "Please select" f: selectItem with null / empty value inside p: selectOneMenu
OK, I finally found a solution to this!
you need to add immediate = "true" to the ajax call. The addition immediately tells ajax to ignore any possible validation errors and call onChange anyway. Try it.
source to share