• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to retreive (or Hold) these values from JSF page

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have following code

details:
* This page creates n number of dropdown menus.
* MainMenuBean is backing bean specified in faces-config.xml and OrgBean is part of MainMenuBean
* MainMenuBean's getOrganizations() method returns a List of OrgBeans. So 'orgBean' is a object of class OrgBean.

My questions is : when I make selections in all these dropdown menus , how do I retrieve them ?
If I had followign code , I know that OrgBean's data1 attribute is holding the value. but in this case it's all dynamic so How do I get those values ?

Thanks in advance
- Anand
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please tell me what's the datatype of MainMenuBean.organizations property ?

Assuming organiztions is list.
You can solve this as below.
1. Creae pojo class which contains the properties for orgTypeDesc(String), orgList(SelectItem List) and orgSelected(String).
2. Create objects and set the values from organizations list(the list which you are passing to datatable) and create Arraylist of the newly created class.
3. Use the updated arraylist for iterating the datatable.
4. Bind the select many list box value with orgSelected property of the newly created pojo class.
5. After form submit selected value in select manylist box will set to orgSelected property.
6. Iterate the updated arraylist to get to know the orgSelected property for each row.

Please let me know if you have any confusion.
 
Anand Gondhiya
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.

I think I am doign similar to what you are mentioning but still missign the key part.

Can you please tell me what's the datatype of MainMenuBean.organizations property ?



Ans: The array list organizations is populated with 'OrgBean' a class which has orgTypeid and orgtypedesc properties.

6. Iterate the updated arraylist to get to know the orgSelected property for each row.



But which variable in the backing bean will be holding the selected values ? is it organizations ??




Is it possible that you write some code , or may be c hange above code just so that I can understand your steps more clearly ??

Thanks again !
- Anand
 
Srini Mutpur
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MainMenuBean {

List<OrgBean> organiztions;
// getter for organizations
}

Class OrgBean(){

String orgTypeId;
String orgTypeDesc;
String orgType; // bind to the selectmanylist box value property

// getter & setters for all the properties
}

So now for each row in your datatable mapped to one orgBean object from the organizations list.

<h:dataTable id="stepTwoTable" value="#{mainMenuBean.organizations}" var="orgBean" >
<h:column>
<h:outputText rendered="#{orgBean.emptyListFlag}" value="#{orgBean.orgTypeDesc}" ></h:outputText>
</h:column>
<h:column>
<h:selectManyListbox rendered="#{orgBean.emptyListFlag}" id="orgList" value="#{orgBean.orgType}">
<f:selectItems value="#{orgBean.list}" />
</h:selectManyListbox>
</h:column>
</h:dataTable>

After form submit, all the values will be updated to respective bean properties.
In your action method iterate the organizations list and the value for the each row and sent it to business layer where it can update in the Database.

for(OrgBean obj: organizations){
String orgType = obj.getOrgType();
}


Please let me know if you have any confusion.

Thanks
Srini
 
Anand Gondhiya
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srini,


As We are using SelectManyListBox (as opposed to SelectOneListBox) so Did you mean String[] OrgType instead of String OrgType ? I tried using that it works as expected and fine now !!!

This was a fun exercise. And thanks again for working with me !

Also , I am using complete Reference Java Server Faces book , if you know any good book for intermediate level , please let me know.

have fun !
- Anand
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic