• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Issue with jsf value change listener

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..

<h:outputText value="State*"></h:outputText>

<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" />
</p:selectOneMenu>
<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"/>

<h:outputText value="City*"></h:outputText>
<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" />
</p:selectOneMenu>
<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();
setRetList(retList);
tr.commit();
}

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

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



u8Vr0.png
[Thumbnail for u8Vr0.png]
screen shot
 
Saloon Keeper
Posts: 25653
183
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Sathez! You can make your code and XML more readable using this advice: https://coderanch.com/how-to/java/UseCodeTags

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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic