problem with double drop down

UI Components for JSF
Post Reply
mustufa
Posts: 31
Joined: 06 Mar 2010, 06:49
Location: India
Contact:

27 Mar 2010, 10:30

Hello cagatay civici,

I am using p:ajax for the double drop down. When i am into the edit mode for a particular record and change the value in drop down of country the sates drop down values get changed properly but then when i submit the page it gives me an error of "j_idt15:stateName: Validation Error: Value is not valid" though i have not kept any validations on the page.

And one more thing while in the process of debugging i found that the values that get changed in states when i change the country they are not found in the view page source.

Can you please provide some help on this.

Thanks

mustufa
Posts: 31
Joined: 06 Mar 2010, 06:49
Location: India
Contact:

29 Mar 2010, 08:46

Hey Cagatay i wanted to know one thing that when i am using <p:ajax > the method stated in the actionListner is getting called when i change the country name in the drop down but the problem that i am getting is the the id for country or name of the country i am not getting them in my bean where the actionListner method is written.
Can u suggest me how to get the value in the bean.


The code of the xhtml page.

<tr valign="top" align="left">
<td width="30%" bgcolor="#ffe6cc" align="right" class="Aril12B"><div align="right"><font color="#000000" size="2"><font color="#ff0000">*</font> Select Country </font><strong>:</strong> </div></td>
<td bgcolor="#fff2e6">


<h:selectOneMenu id="countryId" value="#{CityBean.countryId}">

<f:selectItems id="countries" value="#{CityBean.getcountrylist()}" itemValue="#{c.countryId}" itemLabel="#{c.countryName}" var="c"/>
<p:ajax actionListener="#{CityBean.handleCityChange(CityBean.countryId)}" event="change" update="stateName" />
</h:selectOneMenu>
<h:inputHidden value="#{CityBean.countryId}"/>

</td>
</tr>
<tr valign="top" align="left">
<td bgcolor="#ffe6cc" align="right" class="Aril12B"><div align="right"><font color="#000000" size="2"><font color="#ff0000">*</font> Select State </font><strong>:</strong> </div> </td>
<td width="70%" bgcolor="#fff2e6">

<h:selectOneMenu id="stateName" value="#{CityBean.stateId}" style="width: 100px">
<f:selectItems id="states" value="#{CityBean.handleCityChange(CityBean.countryId)}" itemValue="#{s.stateId}" itemLabel="#{s.stateName}" var="s"/>
</h:selectOneMenu>

</td>
</tr>

The bean code is as follows.


public ArrayList handleCityChange(int countryId)
{
ArrayList list = new ArrayList();
CityDAO cityDAO = new CityDAO();
CityBean city = new CityBean();
this.countryId = city.getCountryId();
this.countryName = city.getCountryName();
System.out.println("Handle City Change This is the country name ---->>"+countryName);
System.out.println("Handle City Change This is the country id ---->>"+countryId);
try
{
if(countryId!=0)
{
list = cityDAO.readAllState(countryId);
System.out.println(list.toString());
}
}
catch(Exception e)
{
e.printStackTrace();
}

return list;

}

Please provide your valueable feedbacks

Thanks
Mustufa

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

01 Apr 2010, 01:23

Hi,

Value is not valid in select component usually means the selectItems displayed are not available in next request.

What is the scope of your CityBean?

mustufa
Posts: 31
Joined: 06 Mar 2010, 06:49
Location: India
Contact:

05 Apr 2010, 11:35

hello cagatay ,

Thanks for the reply, you have asked for the scope.

the scenario is i have two dropdowns
1) Country
2) States
In both the drop downs the values are coming from database.
Now in the first drop down the list of all the countries are coming.Now what i want to achieve is that if i select a particular country all the states of the country shld come from the database. Now to achieve this i have to get the country id that i have selected into my bean which i am not able to get.

Thanks

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

05 Apr 2010, 13:11

These examples can help;

http://www.primefaces.org:8080/prime-sh ... Select.jsf

Make sure CityBean's scope is longer than request scope.

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

16 Jun 2010, 11:29

Unfortunately the "Double Combo" code is missing from the source listing from the component
showcase, any chance of getting hold of it?

Thanks,

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

16 Jun 2010, 20:32

We can add it for sure, for now you can get the source by downloading the showcase, sources are included in war.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 40 guests