Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with jsf value change listener  RSS feed

sathez kumar
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using jsf2.0 with primefaces. In my application there is one registration form ,in that i have city and state field.. when i am select the state it automatically retrieve the corresponding city on the city field, after selecting the city i am always getting the error message like 'City: Validation Error: Value is not valid';

here is my xhtml code..

<hutputText value="State*"></hutputText>

<p:selectOneMenu id="currentState"
value="#{volunteerBean.currentState}" required="true"
immediate="true" requiredMessage="Select your state" valueChangeListener="#{functions.valuechagemethod}"
label="State" style="width:196px">
<f:ajax execute="@this" render="currentCity"></f:ajax>
<f:selectItem itemLabel="select" itemValue=""></f:selectItem>
<f:selectItems value="#{volunteerBean.stateList}" var="item"
itemLabel="#{item}" itemValue="#{item}"></f:selectItems>
<p:ajax event="change" update="msg16" />
<h:message for="currentState" id="msg16" styleClass="alert" />
<p:tooltip for="currentState" value="Select Your State" style="color:blue;font-size:80%;" showEffect="fade" hideEffect="fade"/>

<hutputText value="City*"></hutputText>
<p:selectOneMenu id="currentCity"
value="#{volunteerBean.currentCity}" required="true"
immediate="true" requiredMessage="Select your city"
label="Country" style="width:196px">
<f:selectItem itemLabel="Select" />
<f:selectItems value="#{functions.retList}" var="item"
itemLabel="#{item}" itemValue="#{item}"></f:selectItems>
<p:ajax event="change" update="msg15" />
<h:message for="currentCity" id="msg15" styleClass="alert" />
<p:tooltip for="currentCity" value="Select Your City" style="color:blue;font-size:80%;" showEffect="fade" hideEffect="fade"/>

here is my bean method

public void valuechagemethod(ValueChangeEvent e)
String sval=e.getNewValue().toString();
Session session = null;
SessionFactory sessionFactory = HibernateUtil.getInstance();
session = sessionFactory.getCurrentSession();
Transaction tr= session.beginTransaction();
long sid=(Long) session.createQuery("select state_id from
StateBean where state_name='"+sval+"'").uniqueResult();
retList = session.createQuery("select city_name from CityPojo
where state_id='"+sid+"'").list();

public List<VolunteerBean> getRetList() {
return retList;

public void setRetList(List<VolunteerBean> retList) {
this.retList = retList;
public List<VolunteerBean> retList;

[Thumbnail for u8Vr0.png]
screen shot
Tim Holloway
Posts: 18705
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Sathez! You can make your code and XML more readable using this advice:

Selection controls will throw a validation error when the list of valid values (as defined by its selectItems) doesn't contain the selected value. This can happen, for example, when the backing bean was defined with Request scope (which is almost entirely useless in JSF).

You coded "immediate=true" on your control, however, and that can be a problem, since "immediate" doesn't mean "right now", it means "submit the form, but not the data values". Which means that your updated control value won't be sent to the server.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!