my dog learned polymorphism*
The moose likes JSF and the fly likes Using dropDown in jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Using dropDown in jsf" Watch "Using dropDown in jsf" New topic
Author

Using dropDown in jsf

Subrahmanyam Baratam
Greenhorn

Joined: Nov 24, 2008
Posts: 13
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.
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
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
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

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





My Blog SCJP 5 SCWCD 5
Subrahmanyam Baratam
Greenhorn

Joined: Nov 24, 2008
Posts: 13
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

Joined: Aug 18, 2008
Posts: 598

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

Joined: Nov 24, 2008
Posts: 13
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

Joined: Aug 18, 2008
Posts: 598

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using dropDown in jsf
 
Similar Threads
JSF
Setting current value in SelectItem
JSF drop down.
Need Help with Editable Combo/Dropdown Box in JSF
checkbox in dropdown list