• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Using dropDown in jsf

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can any one please guide me in using the dropDown in jsf.
The requirement is as and when my page loads the dropDown needs to be loaded with the values from database, for this in JSF how can i achieve.

Thanks in adavance,
Subrahmanyam.
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there Subrahmanyam,

You need to look at <h:selectOneMenu> as well as <f:selectItem / selectItems.

Check out some samples of these and you'll get it. It's pretty easy. In your jsp you have a <h:selectOneMenu which contains a <f:selectItems whose value is an ArrayList on your bean of SelectItems.

cheers
Darryl
 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is simple. You can use <h:selectOneListBox> in your jsp page and can bind the value attribute with the SelectItem array or LIst whatever you want. In the getter you can write the code which populated your list or Array object.


This can be in your jsp file




And this can be part of your Backing Bean



 
Subrahmanyam Baratam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, It worked but another problem with this for listBox i have used the below code in jsp,

<h:selectManyListbox size="3" id="oneListBox">
<f:selectItems value="#{Register.oneListValues}" />
</h:selectManyListbox>

//code in the bean (setter & getter for the above )

private String[] oneListBox;

public String[] getOneListBox() {
return oneListBox;
}

public void setOneListBox(String[] oneListBox) {
this.oneListBox = oneListBox;
}

When the user selects multiple items in the list box and when he submits the button, in the backend i need to get the values which are selected only.
For this i have written one method in the bean, when user hits the submit button control will go to the below method,

public String process(){
System.out.println("IN PROCESS METHOD");
System.out.println("Selected list box values>>>"+getOneListBox());
//in the about sysout i am getting null,
return "formRegist";
}

How can i get those values which are selected in the list box.
It would be better if any one give solution for this, because with this my first jsp will be finished and can move to the next.

Thanks in advance,
Subrahmanyam.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simple use value attribute in your <h:selectOneListbox> like

<h:selectOneListbox value="#{beanName.propertyName}">


and make a corresponding property of SelectItems arrayList.

Hope this will solve your problem.
 
Subrahmanyam Baratam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, the problem is solved, i am getting ready to design
the next page which is also related to list boxes. I want your help to fullfill the requirement.

There are two list boxes and in the middle of the list boxes, there will be 4 buttons like ( >>, >, <<, < ).
If i select >> i need to send all the values from first list box to second list box,
If i select << i need to send all the values from second list box to first list box,
If i select > i need to send all the values which are selected in first list box to second list box,
If i select < i need to send all the values which are selected in second list box to first list box,

Please tell me if there is any predefined tag in JSF (third party is not recommeded for our client) if not, kindly guide me how to proceed further.


Thanks in advance,
Subrahmanyam.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is one component which you are talking about in RichFaces which implements AJAX features. If you don't want to use any third party element then you can write a JavaScript for that or on onchange event submit the form and get the selected values and then perform all the required operations.
 
reply
    Bookmark Topic Watch Topic
  • New Topic