Inserting values in to a dropdown list in visual web jsf

Posted on 2009-02-21
Last Modified: 2013-11-24
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
Question by:Somuchowdary
    1 Comment
    LVL 19

    Accepted Solution

    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!")


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This video teaches viewers about errors in exception handling.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now