• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 732
  • Last Modified:

Inserting values in to a dropdown list in visual web jsf

Hi, I want to insert values in to a dropdown list thru code using setter methods in visual web jsf and im using woddstock components, can u tell me how to enter values usingg setter methods
0
Somuchowdary
Asked:
Somuchowdary
1 Solution
 
Jim CakalicSenior Developer/ArchitectCommented:
Hi. Sorry it took so long to respond.

So, you probably have a JSP page with a tag similar to this:
    <webuijsf:dropDown id="dropDown1" items="#{Page1.dropDown1DefaultOptions.options}" />

The items property of the tag is how JSF determines where to get the options to display in the dropdown. I'm telling JSF to get them from the options property of a managed component named dropDown1DefaultOptions in the bean that has been registered under the name Page1.

You should also have a page bean for this page. In my case, it's called Page1 (creative, eh?) In the page bean code you should see a managed component declaration similar to this:
    private SingleSelectOptionsList dropDown1DefaultOptions = new SingleSelectOptionsList();

There will also be a getter and setter for this component. Here's what you need to do. Find the init method in the page bean and add code to create a new Option[]. The Option constructor takes two args: the value of the option and the label to display. Then, call the setOptions method on the managed component:
        Option[] options = new Option[] {
            new Option("1", "This is option 1"),
            new Option("2", "Option 2"),
            new Option("3", "Option 3"),
            new Option("4", "Pick me!")
        };
        dropDown1DefaultOptions.setOptions(options);

Regards,
Jim
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now