Please help me to get knowledge about struts tags(html,bean,logic).

hai Friends,

I know basics of struts. I have done basic examples.

I have to know , how to get dynamic values in "view".

Instead of writing like this..

<html:select property="color1" size="4" >

<html:option value="red">red</html:option>

<html:option value="blue">blue</html:option>

<html:option value="green">green</html:option>

<html:option value="orange">orange</html:option>

<html:option value="red">red</html:option>

<html:option value="pink">pink</html:option>

</html:select>

How to use <html:options> tag to get dynamic values.

I have to get knowledge about this tags, so please suggest some

sites (or) send some materials (or) send some live examples("awm_riaz@yahoo.com"). It will very useful..

thanks friends....

take care...

bye.....

will be very useful for me...

[978 byte] By [awm_riaza] at [2007-10-2 23:53:19]
# 1

you have to have a list of label and value pairs in you ActionForm then define it in your jsp to able able to use it in your <html:options> tag

ActionForm

public final class ColorForm extends ActionForm {

...

public String color;

public void setColor(String color) {

this.color = color;

}

public String getColor() {

return this.color;

}

public List getColorList() {

List l = new ArrayList();

ColorLabelValueBean lvRed = new ColorLabelValueBean();

lv.setLabel("Red");

lv.setValue("R");

l.add(lv);

ColorLabelValueBean lvGreen = new ColorLabelValueBean();

lv.setLabel("Green");

lv.setValue("G");

l.add(lv);

ColorLabelValueBean lvBlue = new ColorLabelValueBean();

lv.setLabel("Blue");

lv.setValue("B");

l.add(lv);

return l;

}

...

}

Label - Value Bean

public final class ColorLabelValueBean implements Serializable {

private String label;

private String value;

public void setLabel(String label) {

this.label = label;

}

public String getLabel() {

return this.label;

}

public void setValue(String value) {

this.value = value;

}

public String getValue() {

return this.value;

}

}

JSP

...

<bean:define id="colorListOption" name="ColorForm" property="colorList" type="java.util.List" />

<html:select property="color">

<html:option value=""></html:option>

<html:options collection="colorListOption" labelProperty="label" property="value" />

</html:select>

...

Good luck!

p6_united25a at 2007-7-14 16:39:13 > top of Java-index,Other Topics,Patterns & OO Design...