Setting ListBox values?

Thank you for your help on a previous question.

Our application handles forms and their data is saved in an object so

the user can return to a form and have the original data intact. All

the JATO HTML objects return the data fine except for the ListBox

(whether mult-select or not). Originally there was no data

transmitted when the form was submitted or returned. I added a hacked

getHTML method to return the selected values:

public String getSelected()

{

String optionListStr = "";

Option[] options = getOptions().toOptionArray();

for(int i=0; i<options.length; i++) {

boolean isSelected

= isSelected(options.getValue());

if(isSelected) {

optionListStr += "\n " +

options.getValue();

}

}

// I could return this to listbox in any format

return optionListStr;

}

I can not find a method for setting the returned values in the

ListBox, nor does there appear to be a setHTML method. Could

someone point me in the right direction on how to display these

returned ListBox values?

Troy Colyer

425.234.2424

>

[1231 byte] By [Guest] at [2007-11-25 9:31:15]
# 1

Hi Troy--

I'm not really sure what you're trying to accomplish, but you may be

confusing the API for working with the set of possible values (Options) with

the API for getting the current value(s). ListBox, like any other field,

has getValue()/setValue() & getValues()/setValues() methods. These are the

methods used to both select the current value(s), and get the value(s)

submitted from the client. When you receive a request, you should be able

to just do this:

Object[] values = getDisplayField("mylistbox").getValues();

to get all the values of the listbox. If you know there is only one value

for a listbox, you can do this instead:

Object value = getDisplayField("mylistbox").getValue();

To set the selected value before or during display, you must set a *value*

that appears in the ListBox's associated OptionList. For example, let's say

you have an OptionList that looks like this:

Label Value

--

One 1

Two 2

Three 3

If you want to select the second item, you need to do this:

getDisplayField("mylistbox").setValue("2");

If you set the value to "Two" or something besides one of the values in the

option list, no values will be selected in the rendered page.

Does this make sense?

Todd

-- Original Message --

From: <<a href="/group/SunONE-JATO/post?protectID=029233044185067213090168066248100253094 145066046167121181">moun10sun@y...</a>>

Sent: Thursday, August 02, 2001 8:37 AM

Subject: [iPlanet-JATO] Setting ListBox values?

> Thank you for your help on a previous question.

>

> Our application handles forms and their data is saved in an object so

> the user can return to a form and have the original data intact. All

> the JATO HTML objects return the data fine except for the ListBox

> (whether mult-select or not). Originally there was no data

> transmitted when the form was submitted or returned. I added a hacked

> getHTML method to return the selected values:

>

> public String getSelected()

> {

> String optionListStr = "";

> Option[] options = getOptions().toOptionArray();

>

> for(int i=0; i<options.length; i++) {

> boolean isSelected

> = isSelected(options.getValue());

>

> if(isSelected) {

> optionListStr += "\n " +

> options.getValue();

> }

> }

> // I could return this to listbox in any format

> return optionListStr;

> }

>

> I can not find a method for setting the returned values in the

> ListBox, nor does there appear to be a setHTML method. Could

> someone point me in the right direction on how to display these

> returned ListBox values?

>

> Troy Colyer

> 425.234.2424

>

>

>

> <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>

>

>

>

>

>

Guest at 2007-7-1 18:24:03 > top of Java-index,Development Tools,Java Tools...