How clean bean fields on a flow scope when this finish? - spring

I got a annotated service bean which is used to store form values on newSpace_1 page when I navigate to another flow I wish cleaning this bean because if I return to newSpace_1 page I would like showing empty fields because I got navigate buttons that depend on the value of the fields.
I tried to declare this bean as var on flow definition and a #service bean, then set method works but get method retrieve null for each properties. So I need to use as #service for set/get methods work properly on newSpace_1 page.
<flow...>
<var name="spaceFields" class="x.y.x.Spacields" />
<view-state>
......
</view-state>
</flow>
SpaceFields
#Service("spaceFields")
public class SpaceFields implements Serializable {
private static final long serialVersionUID = 1L;
#Min(value=1)
#Max(value=194)
private Integer idCountry;
#Min(value=1)
#Max(value=5)
private Integer idContinent;
....
....
}
Flow definition
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
parent="commons-header">
<secured attributes="ROLE_USER" />
<view-state id="adminSpace" view="admin_spaces.xhtml">
<transition on="new" to="step1" />
</view-state>
<view-state id="step1" view="newSpace_1.xhtml">
<on-entry>
<evaluate expression="place.findContinents()" result="flowScope.continents" />
</on-entry>
<transition on="next" to="step2" />
</view-state>
<view-state id="step2" view="newSpace_2.xhtml">
<on-entry>
<evaluate expression="category.findCategories()" result="flowScope.categories" />
</on-entry>
<transition on="back" to="step1" />
<transition on="next" to="step3" />
</view-state>
<view-state id="step3" view="newSpace_3.xhtml">
<transition on="back" to="step2" />
<transition on="next" to="step4" />
</view-state>
newSpace_1 code
<ui:composition template="/WEB-INF/templates/mainPage.xhtml">
<ui:define name="title">
<h:outputText value="${msg['newSpace.title']}" />
</ui:define>
<ui:define name="centerContainer">
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_info" styleClass="creatingSpaceContainer_step1_info">
<h1>
<h:outputText value="#{msg['newSpace.step1.main.header']}" />
</h1>
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_info_msg" styleClass="creatingSpaceContainer_step1_info_msg">
<h:outputText value="#{msg['newSpace.step1.main.msg']}" />
</h:panelGroup>
</h:panelGroup>
<h:form>
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_fields" styleClass="creatingSpaceContainer_step1_fields">
<h:outputLabel for="continent" value="#{msg['continent.txt']}" styleClass="labelInput" />
<h:selectOneMenu id="continent" value="#{spaceFields.idContinent}" title="#{msg['continent.select.title']}" tabindex="1">
<f:selectItem itemLabel="#{msg['continent.select.zeroption']}" itemValue="0" noSelectionOption="true" />
<f:selectItems var="continent" value="#{continents}" itemLabel="#{continent.name}" itemValue="#{continent.primaryKey.continent.idContinent}" />
<f:ajax render="#this country messageContinentError" listener="#{place.findCountries(flowRequestContext)}" event="change" />
<f:validateBean for="idContinent" />
</h:selectOneMenu>
<h:message id="messageContinentError" for="continent" styleClass="messageError" />
<h:outputLabel for="country" value="#{msg['country.txt']}" styleClass="labelInput" />
<h:selectOneMenu id="country" value="#{spaceFields.idCountry}" title="#{msg['country.select.title']}" tabindex="2">
<f:selectItem itemLabel="#{msg['country.select.zeroption']}" itemValue="0" noSelectionOption="true" />
<f:selectItems var="countryLocale" value="#{countries}" itemLabel="#{countryLocale.name}" itemValue="#{countryLocale.primaryKey.country.idCountry}" />
<f:ajax render="#this -controls-creatingSpaceContainer_step1_controls messageCountryError" event="change" />
<f:validateBean for="idCountry" />
</h:selectOneMenu>
<h:message id="messageCountryError" for="country" styleClass="messageError" />
</h:panelGroup>
</h:form>
<h:form id="controls">
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_controls" styleClass="creatingSpaceContainer_step1_controls">
<h:commandLink action="next" value="#{msg['next.button.txt']}" title="#{msg['next.button.title']}" alt="#{msg['next.button.alt']}" tabindex="3" rendered="#{spaceFields.idCountry>0}" />
</h:panelGroup>
</h:form>
</ui:define>
</ui:composition>

Use on-exit action in the view state to clear the bean while navigating away from view as:
<view-state id="step1" view="newSpace_1.xhtml">
<on-entry>
....
</on-entry>
<transition on="next" to="step2">
<on-exit>
<evaluate expression="someaction.clear(flowScope.spaceFields)"/>
</on-exit>
</view-state>
This way when you re-enter view all your bean fields are empty.
You can find more details about on-exit action here.

Related

Spring webflow cleaning form fields

I use the same bean field, a string called email, for different purposes (register, recovery password, login). So, I wish navigate between views/flows and bean fields must clean automatically, but this behavior don't happen.
It's a JSF2/Spring project
Flow definition
<var name="viewScope.loginFields" class="es.project.viewBean.ConnectionFields" />
<view-state id="login" view="login.xhtml" model="loginFields">
<transition on="entry" to="connect"/>
<transition on="recoveryPass" to="recovery" />
</view-state>
<view-state id="recovery" view="recovery.xhtml" model="loginFields">
<transition on="return" to="login" />
<transition on="sendPass" to="recoveryPass" />
</view-state>
Bean definition
#Service("loginFields")
public class ConnectionFields implements Serializable {
private static final long serialVersionUID = 1L;
private static Logger logger=LogManager.getLogger(ConnectionFields.class);
#NotNull(message="{field.notEmpty.validation}")
#Email(message="{field.email.validation}")
private String email;
#NotNull(message="{field.notEmpty.validation}")
#Size(min=6,max=12,message="{field.size.validation}")
#Pattern(regexp="^[a-zA-Z0-9]*$",message="{field.onlyAlpha.validation}")
private String password;
#NotNull(message="{field.notEmpty.validation}")
#Size(min=6,max=12,message="{field.size.validation}")
#Pattern(regexp="^[a-zA-Z0-9]*$",message="{field.onlyAlpha.validation}")
private String passwordRepeated;
#NotNull(message="{field.notEmpty.validation}")
#Email(message="{field.email.validation}")
private String emailRepeated;
...........
...........
...........
}
recovery.xhtml
<h:form id="formRecovery">
<h:panelGroup layout="block" id="containerFormRecovery" styleClass="containerFormRecovery">
<p:focus />
<h:panelGroup layout="block" styleClass="formRecovery-row">
<h:outputLabel for="email" value="#{msg['email.txt']}" />
<h:inputText id="email" value="#{loginFields.email}" title="#{msg['email.txt.title']}" alt="#{msg['email.txt.alt']}" styleClass="#{component.valid ? '' : 'invalid'}" size="35" tabindex="1">
<f:validateBean for="email" />
<p:ajax event="blur" update="#this emailError"/>
</h:inputText>
<h:message for="email" id="emailError" styleClass="messageError" />
</h:panelGroup>
<h:panelGroup layout="block" styleClass="formRecovery-row">
<p:captcha id="captcha" theme="white" requiredMessage="#{msg['captcha.required']}" tabindex="2">
</p:captcha>
<h:message for="captcha" id="captchaError" styleClass="messageError"/>
</h:panelGroup>
<h:panelGroup layout="block" id="containerRecoveryButtons" styleClass="containerRecoveryButtons">
<h:commandButton value="#{msg['send.btn']}" title="#{msg['send.btn.title']}" alt="#{msg['send.btn.title']}" action="sendPass" tabindex="3" />
</h:panelGroup>
</h:panelGroup>
</h:form>
<h:panelGroup>
<h:commandLink value="#{msg['return.btn']}" title="#{msg['return.btn.title']}" alt="#{msg['return.btn.alt']}" action="return" tabindex="4" />
</h:panelGroup>
login.xthml
<h:form id="formLogin">
<h:panelGroup layout="block" id="containerFormLogin" styleClass="containerFormLogin">
<p:focus />
<h:panelGroup layout="block" styleClass="formLogin-row">
<h:outputLabel for="email" value="#{msg['email.txt']}" />
<h:inputText id="email" value="#{loginFields.email}" title="#{msg['email.txt.title']}" alt="#{msg['email.txt.alt']}" styleClass="#{component.valid ? '' : 'invalid'}" size="35" tabindex="2">
<f:validateBean for="email" />
<p:ajax event="blur" update="#this emailError" />
</h:inputText>
<h:message for="email" id="emailError" styleClass="messageError" />
</h:panelGroup>
<h:panelGroup layout="block" styleClass="formLogin-row">
<h:outputLabel for="password" value="#{msg['pass.txt']}" />
<p:password id="password" value="#{loginFields.password}" title="#{msg['pass.txt.title']}" alt="#{msg['pass.txt.alt']}"
styleClass="#{component.valid ? '' : 'invalid'}" size="35" tabindex="3">
<f:validateBean for="password" />
<p:ajax event="blur" update="#this passwordError" />
</p:password>
<h:message for="password" id="passwordError" styleClass="messageError" />
</h:panelGroup>
<p>
<h:outputLabel for="remember" value="#{msg['rememberSession.msg.check']}" />
<h:selectBooleanCheckbox id="remember" value="#{loginFields.remember}" tabindex="4" title="#{msg['rememberSession.title.check']}" />
</p>
<h:panelGroup layout="block" id="containerLoginButtons" styleClass="containerLoginButtons">
<h:commandButton value="#{msg['login.long.btn']}" action="entry" tabindex="5" title="#{msg['login.long.btn.title']}" alt="#{msg['login.long.btn.alt']}" />
</h:panelGroup>
</h:panelGroup>
</h:form>
<p>
<h:form>
<h:commandLink value="#{msg['recoveryPassword.msg.link']}" action="recoveryPass" />
</h:form>
</p>
On above example, my idea is to navigate to RecoveryPassword page from Login page and viceversa, and I would like email field reset value itself when I change view, but email never reset the value.
One approach would be to clear the value in the <transition> or the <on-entry> of your states. Either with just a setter method or with a custom method (e.g. reset()). We do this for various other conditions where entering a state requires clearing a field.
e.g.
<view-state id="recovery">
<on-entry>
<set name="loginFields.email" value="''"/>
</on-entry>
...
</view-state>

popupPanel Richfaces doesn't work

I am working with RicheFaces, when i click to have popupPanel "Edit User Details" i don't get the form to Edit User Details.
Here is my code:
<ui:define name="title">
<h:outputText value="Users Management" />
</ui:define>
<!-- <h:outputText value="#{collaborateurBo.getAllCollaborateur().size()}" /> -->
<ui:define name="content">
<center>
<a4j:status onstart="#{rich:component('statPane')}.show()"
onstop="#{rich:component('statPane')}.hide()" />
<h:form id="form">
<a4j:outputPanel id="tableaa" layout="block">
<rich:dataTable value="#{PosteBean.getCollaborateurList()}" var="pr" iterationStatusVar="it" id="table"rows="15">
<rich:column>
<f:facet name="header">#</f:facet> #{it.index} </rich:column>
<rich:column>
<f:facet name="header">Last name</f:facet>
<h:outputText value="#{pr.getNom()}" />
</rich:column>
<rich:column>
<f:facet name="header">First name</f:facet>
<h:outputText value="#{pr.getPrenom()}" />
</rich:column>
<rich:column>
<a4j:commandLink styleClass="no-decor" execute="#this"render="#none"
oncomplete="#{rich:component('confirmPane')}.show()">
<h:graphicImage value="/css/images/delete.gif" alt="delete" />
<a4j:param value="#{it.index}"
assignTo="#{PosteBean.currentProjectIndex}" />
<f:setPropertyActionListener target="#{PosteBean.Collaborateurr}"value="#{p}" />
</a4j:commandLink>
<a4j:commandLink styleClass="no-decor" render="editGrid" execute="#this"
oncomplete="#{rich:component('editPane')}.show()">
<h:graphicImage value="/css/images/edit.gif" alt="edit" />
<a4j:param value="#{it.index}"
assignTo="#{PosteBean.currentProjectIndex}" />
<f:setPropertyActionListener target="#{PosteBean.Collaborateurr}" value="#{p}" />
</a4j:commandLink>
</rich:column>
<f:facet name="footer">
<rich:dataScroller id="scroller" />
</f:facet>
</rich:dataTable>
<a4j:commandButton styleClass="no-decor" render="addGrid"
oncomplete="#{rich:component('addPane1')}.show()"
value="Add new User">
</a4j:commandButton>
</a4j:outputPanel>
<a4j:jsFunction name="remove" action="Collaborateurr.remove()"
render="tableaa" execute="#this"
oncomplete="#{rich:component('confirmPane')}.hide();" />
<rich:popupPanel id="statPane" autosized="true">
<h:graphicImage value="/css/images/ai.gif" alt="ai" />
Please wait...
</rich:popupPanel>
<rich:popupPanel id="confirmPane" autosized="true">
Are you sure you want to delete the row?
<a4j:commandButton value="Cancel"
onclick="#{rich:component('confirmPane')}.hide(); return false;" />
<a4j:commandButton value="Delete" onclick="remove()" />
</rich:popupPanel>
<rich:popupPanel header="Edit User Details" id="editPane"
domElementAttachment="parent" width="400" height="200">
<rich:graphValidator id="gvv">
<rich:messages for="gvv" />
<rich:messages globalOnly="true" />
<!-- edit -->
<h:panelGrid columns="3" id="editGrid">
<h:outputText value="Last name" />
<h:inputText value="PosteBean.Collaborateurr" />
<h:panelGroup />
<h:outputText value="First name" />
<h:inputText value="" />
<h:panelGroup />
<h:outputText value="Email" />
<h:inputText value="" id="emaa" />
<rich:message for="emaa" />
</h:panelGrid>
<h:selectOneRadio id="koko" value="PosteBean.sflag">
<f:selectItem itemValue="ROLE_ADMIN" itemLabel="Manager" />
<f:selectItem itemValue="ROLE_USER" itemLabel="Tester" />
</h:selectOneRadio>
<a4j:commandButton value="Store" action="PosteBean.store"
render="table" execute="editPane"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('editPane')}.hide();}" />
<a4j:commandButton value="Cancel"
onclick="#{rich:component('editPane')}.hide(); return false;" />
</rich:graphValidator>
</rich:popupPanel>
<rich:popupPanel header="Add User " id="addPane1"
domElementAttachment="parent" width="400" height="200">
<rich:graphValidator id="gv">
<rich:messages for="gv" />
<rich:messages globalOnly="true" />
<h:panelGrid columns="3" id="addGrid">
<h:outputText value="Last name" />
<h:inputText value="" />
<h:panelGroup />
<h:outputText value="First name" />
<!-- <h:inputText value="#{PosteBean.Collaborateurr}" /> -->
<h:panelGroup />
<h:outputText value="Email" />
<!-- <h:inputText value="#{PosteBean.Collaborateurr}" id="ema" /> -->
<rich:message for="ema" />
</h:panelGrid>
<h:selectOneRadio id="kokoo" value="#{PosteBean.sflag}">
<f:selectItem itemValue="ROLE_ADMIN" itemLabel="Manager" />
<f:selectItem itemValue="ROLE_USER" itemLabel="Tester" />
</h:selectOneRadio>
<a4j:commandButton value="Add" action="#{PosteBean.add}"
render="table" execute="addPane1"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('addPane1')}.hide();}" />
<a4j:commandButton value="Cancel"
onclick="#{rich:component('addPane1')}.hide(); return false;" />
</rich:graphValidator>
</rich:popupPanel>
</h:form>
</center>
</ui:define>
</ui:composition>
Thanks in advance for helpping me, i wanna have the form of editing,
1) rich:popupPanel should be moved outside of existing h:form;
2) inside each rich:popupPanel should be added h:form.
Reason: Popup panel always had requirement either
to be placed outside forms and have one inside
or
to have domElementAttachment attribute to set properly.

commandButton Richfaces doesn't work

I am working with RicheFaces, when i click on commandButton "Add new User" i don't get the form to add new user.
Here is my code:
<ui:define name="title">
<h:outputText value="Users Management" />
</ui:define>
<!-- <h:outputText value="#{collaborateurBo.getAllCollaborateur().size()}" /> -->
<ui:define name="content">
<center>
<a4j:status onstart="#{rich:component('statPane')}.show()"
onstop="#{rich:component('statPane')}.hide()" />
<h:form id="form">
<a4j:outputPanel id="tableaa" layout="block">
<rich:dataTable value="#{PosteBean.getCollaborateurList()}" var="pr" iterationStatusVar="it" id="table"rows="15">
<rich:column>
<f:facet name="header">#</f:facet> #{it.index} </rich:column>
<rich:column>
<f:facet name="header">Last name</f:facet>
<h:outputText value="#{pr.getNom()}" />
</rich:column>
<rich:column>
<f:facet name="header">First name</f:facet>
<h:outputText value="#{pr.getPrenom()}" />
</rich:column>
<rich:column>
<a4j:commandLink styleClass="no-decor" execute="#this"render="#none"
oncomplete="#{rich:component('confirmPane')}.show()">
<h:graphicImage value="/css/images/delete.gif" alt="delete" />
<a4j:param value="#{it.index}"
assignTo="#{PosteBean.currentProjectIndex}" />
<f:setPropertyActionListener target="#{PosteBean.Collaborateurr}"value="#{p}" />
</a4j:commandLink>
<a4j:commandLink styleClass="no-decor" render="editGrid" execute="#this"
oncomplete="#{rich:component('editPane')}.show()">
<h:graphicImage value="/css/images/edit.gif" alt="edit" />
<a4j:param value="#{it.index}"
assignTo="#{PosteBean.currentProjectIndex}" />
<f:setPropertyActionListener target="#{PosteBean.Collaborateurr}" value="#{p}" />
</a4j:commandLink>
</rich:column>
<f:facet name="footer">
<rich:dataScroller id="scroller" />
</f:facet>
</rich:dataTable>
<a4j:commandButton styleClass="no-decor" render="addGrid"
oncomplete="#{rich:component('addPane1')}.show()"
value="Add new User">
</a4j:commandButton>
</a4j:outputPanel>
<a4j:jsFunction name="remove" action="Collaborateurr.remove()"
render="tableaa" execute="#this"
oncomplete="#{rich:component('confirmPane')}.hide();" />
<rich:popupPanel id="statPane" autosized="true">
<h:graphicImage value="/css/images/ai.gif" alt="ai" />
Please wait...
</rich:popupPanel>
<rich:popupPanel id="confirmPane" autosized="true">
Are you sure you want to delete the row?
<a4j:commandButton value="Cancel"
onclick="#{rich:component('confirmPane')}.hide(); return false;" />
<a4j:commandButton value="Delete" onclick="remove()" />
</rich:popupPanel>
<rich:popupPanel header="Edit User Details" id="editPane"
domElementAttachment="parent" width="400" height="200">
<rich:graphValidator id="gvv">
<rich:messages for="gvv" />
<rich:messages globalOnly="true" />
<!-- edit -->
<h:panelGrid columns="3" id="editGrid">
<h:outputText value="Last name" />
<h:inputText value="PosteBean.Collaborateurr" />
<h:panelGroup />
<h:outputText value="First name" />
<h:inputText value="" />
<h:panelGroup />
<h:outputText value="Email" />
<h:inputText value="" id="emaa" />
<rich:message for="emaa" />
</h:panelGrid>
<h:selectOneRadio id="koko" value="PosteBean.sflag">
<f:selectItem itemValue="ROLE_ADMIN" itemLabel="Manager" />
<f:selectItem itemValue="ROLE_USER" itemLabel="Tester" />
</h:selectOneRadio>
<a4j:commandButton value="Store" action="PosteBean.store"
render="table" execute="editPane"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('editPane')}.hide();}" />
<a4j:commandButton value="Cancel"
onclick="#{rich:component('editPane')}.hide(); return false;" />
</rich:graphValidator>
</rich:popupPanel>
<rich:popupPanel header="Add User " id="addPane1"
domElementAttachment="parent" width="400" height="200">
<rich:graphValidator id="gv">
<rich:messages for="gv" />
<rich:messages globalOnly="true" />
<h:panelGrid columns="3" id="addGrid">
<h:outputText value="Last name" />
<h:inputText value="" />
<h:panelGroup />
<h:outputText value="First name" />
<!-- <h:inputText value="#{PosteBean.Collaborateurr}" /> -->
<h:panelGroup />
<h:outputText value="Email" />
<!-- <h:inputText value="#{PosteBean.Collaborateurr}" id="ema" /> -->
<rich:message for="ema" />
</h:panelGrid>
<h:selectOneRadio id="kokoo" value="#{PosteBean.sflag}">
<f:selectItem itemValue="ROLE_ADMIN" itemLabel="Manager" />
<f:selectItem itemValue="ROLE_USER" itemLabel="Tester" />
</h:selectOneRadio>
<a4j:commandButton value="Add" action="#{PosteBean.add}"
render="table" execute="addPane1"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('addPane1')}.hide();}" />
<a4j:commandButton value="Cancel"
onclick="#{rich:component('addPane1')}.hide(); return false;" />
</rich:graphValidator>
</rich:popupPanel>
</h:form>
</center>
</ui:define>
</ui:composition>
Thanks in advance for helpping me, i want the button to give me the form,
1) rich:popupPanel should be moved outside of existing h:form;
2) inside each rich:popupPanel should be added h:form.
Reason: Popup panel always had requirement either
1) to be placed outside forms and have one inside
or
2) to have domElementAttachment attribute to set properly.

JSF Primefaces form errors after failed validation

I am new to JSF/Java in general but have been trying to solve this for a few days now.
I have a form which gets stuck on validation. When all the entries are valid, it all works well. The minute I break validation (such as don't provide a required value), then the form gets stuck. One thing that happens is I cant correct the invalid entry it seems and repost. Also, where I had a cascading ajax call of a selectOneMenu, that suddenly starts failing...even though this is not the invalidated part of the form.
I notice that the cascading drop down seems to be throwing null pointer exceptions in its overridden equals method.
I am at a loss.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/templates/layout.xhtml">
<ui:define name="content">
<p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>
<p:dialog modal="true" widgetVar="statusDialog" header="Status"
draggable="false" closable="false">
<p:graphicImage value="/resources/images/ajaxloadingbar.gif" />
</p:dialog>
<h:form id="form">
<p:panel id="panel"
header="Please ensure your personal details are accurate"
style="margin-bottom:10px;">
<p:messages id="msgs" />
<h:outputText
value="Please ensure your personal details are up to date and accurate within the Admin Direct system. Please note that this application only supports GMD customers, so unless you are within GMD, or are a user of the GMD Admin Direct service, please do not enter your details or attempt to use the application for administrative support." />
<h:panelGrid columns="3" cellpadding="5" id="grid">
<h:outputText value="First Name:" style="font-weight:bold" />
<p:inputText id="firstName"
value="#{personalDetailsBean.user.firstName}"
requiredMessage="First name is required..." style="width:250px" />
<p:message id="firstNameMessage" for="firstName" />
<h:outputText value="Last Name:" style="font-weight:bold" />
<p:inputText id="lastName"
value="#{personalDetailsBean.user.lastName}"
requiredMessage="Last name is required..." style="width:250px" />
<p:message id="lastNameMessage" for="lastName" />
<h:outputText value="Select Function:" style="font-weight:bold" />
<p:selectOneMenu id="functions"
value="#{personalDetailsBean.user.function}"
style="width:250px">
<f:selectItem itemLabel="Select Function" itemValue="" />
<f:selectItems value="#{personalDetailsBean.functions}" var="func"
itemLabel="#{func.functionName}" itemValue="#{func}" />
<f:converter converterId="functionConverter" />
</p:selectOneMenu>
<p:message id="functionMessage" for="functions" />
<h:outputText value="Select Site" style="font-weight:bold" />
<p:selectOneMenu id="sites"
value="#{personalDetailsBean.user.site}"
style="width:250px">
<f:selectItem itemLabel="Select Site" itemValue="" />
<f:selectItems value="#{personalDetailsBean.sites}" var="sit"
itemLabel="#{sit.siteName}" itemValue="#{sit}" />
<f:converter converterId="siteConverter" />
<p:ajax update="region" event="change" process="#this"/>
</p:selectOneMenu>
<p:message id="siteMessage" for="sites" />
<h:outputText value="Region" style="font-weight:bold" />
<h:outputText id="region"
value="#{personalDetailsBean.user.site.region.regionName}" />
<p:message id="regionMessage" for="region" />
<h:outputText value="Email" style="font-weight:bold" />
<p:inputText id="email" value="#{personalDetailsBean.user.email}"
required="true"
validatorMessage="Invalid email address format"
style="width:250px">
<f:validateRegex
pattern="[\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
<f:validateLength minimum="2" />
</p:inputText>
<p:message id="emailMessage" for="email" />
</h:panelGrid>
<p:separator />
<p:commandButton value="Save" id="btnSubmit" actionListener="#{personalDetailsBean.saveUser}" process="#all" update="panel" />
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</html>
any advice greatly appreciated.
Regards
SM

Ajax not rendering new data for <h:selectOneMenu>

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>
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:
Why JSF calls getters multiple times
How to load and display dependent h:selectOneMenu on change of a h:selectOneMenu

Resources