Hi Vijay,
There are some "tricks" the JSFTemplating allows you to do w/ listbox
(and dropDown) that you can't do with the standard Woodstock
components. This makes it MUCH easier to use than the normal
components. What Anissa said below works in JSFT, and you can get
working w/ a ManagedBean in standard JSF development using JSP (or
Facelets). However, this will work in JSFTemplating only:
<sun:listbox labels={"foo", "bar"} values={"1", "2"}
selected="#{requestScope.selected}" />
This will produce a listbox w/ "foo" and "bar" as choices (you can
expand this to whatever you want) and "1" and "2" as values. And this
will save the value in the request attribute map (you can target this at
any bean / place you want). So it is simple to use a listbox in
JSFTemplating w/o writing any code.
Good luck!
Ken
Anissa Lam wrote:
>
>
> Vijay Ramachandran wrote:
>> Hi Anissa,
>>
>> Thanks for the earlier pointer. I have something up and running. One
>> question :
>>
>> What is the equivalent for a list box ?
> If you are using the woodstock components, it will be <sun:listbox>
>>
>> In html, I will do the following :
>>
>> <select id="usecquestion" value="#{pageSession.usecquestion}">
>> <option itemValue="1">Mother's maiden name</option>
>> <option value="2">Last 4 digits of you social security
>> number</option>
>> <option value="3">City where you were born</option>
>> <option value="4">Your favorite restaurant</option>
>> <option value="5">City where you met your spouse</option>
>> </select>
>>
>>
>> How do I do the same in the JSFTemplating environment ? One way is to
>> put the above piece of code within in <f:verbatim> but will that
>> allow us export values to the handlers ?
> There are couple samples of this in the Admin Console code. Just
> search for <sun:listbox> under admin-gui/src/docroot
> For your above sample, it will be something like:
> <sun:listbox id="usequestion"
> immediate="#{true}"
> items="#{availableQuestions}"
> multiple="#{false}"
> rows="$int{6}"
> selected="#{usequestion}"
> >
>
>
> listbox is a little tricky, you have to use a handler to create the
> Option to specify that as the items.
>
> We have a utility method to create the Options in GuiUtil.java, it
> looks like:
>
> public static Option[] getSunOptions(Collection<String> c) {
> Option[] sunOptions = (c != null ? new Option[c.size()]:null);
> int index=0;
> for(String str:c) {
> sunOptions[index++] = new Option(str, str); }
> return sunOptions;
> }
>
> So, you will need to write a handler that returns the sunOptions to be
> used as the 'items' for the list box.
> When the page submit, you can call a handler that takes in
> #{usequestion} to see what value the user selected.
> The handler input for this will be String[].
> @HandlerInput(name="usequestion", type=String[].class )
>
>
> Let me know if you have any other questions and free feel to post
> questions to the dev_at_jsftemplating.dev.java.net, the alias is very
> helpful.
>
> Anissa
>
>> Please let me know
>>
>> Thanks
>>
>> Vijay
>>