I get a result set from a query which has id and description, now I have to show the it in select tag some thing like this

Paul Sijpkes

Hi Ashish,

You will need to do something like this.

<html:select name="myPreselectedItemBean">
<html:options name="myCollection" property="myValue"
labelProperty="myLabel"/>
</html:select>

Notice that the select tag has a "myPreselectedItemBean" bean associated with it, this bean must be in some scope ie. session, request etc..

The same goes for the "myCollection" bean, this is a bit more complex. Took me a while to get my head around...

"myCollection" should be either be an Object extending java.util.Collection or an array of Objects. It can't be a simple type (eg. int[]).

"myCollection" should be made up of other beans, with a getMyValue() and getMyLabelProperty() method.

eg.
public class OptionItem
{
public OptionItem()
{
}

String myValue;
String myLabel;

public String getMyValue()
{
return myValue;
}

public void setMyValue(String myValue)
{
this.myValue = myValue;
}

public String getMyLabel()
{
return myLabel;
}

public void setMyLabel(String myLabel)
{
this.myLabel = myLabel;
}
}

I normally create a Vector and then populate it with these sort of beans.

I hope this is helpful to you.

cheers,
Paul Sijpkes
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact