You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nadja Senoucci <se...@21st.de> on 2003/06/02 09:20:30 UTC
A few questions about and tags
Hello,
I have a few question about those tags.
1) How can I preselect a value in a dropdown? Meaning: I already have a
value (one that was selected before) and I want that to be selected when the
form gets displayed.
2) I want to have one dropdown that changes another one when something gets
selected. I know, you have to use JavaScript for that and use the onChange
event. But can I still use struts for that? I have the different options in
different Java Collections. How would I go about that?
3) My collections (with the different options) are kind of archives holding
objects of a certain type. Now I want a default value in the dropdown like
'Please choose one of the following...' or something like that. Can I have
that without putting it into my collection?
I would be very grateful about any information...
Greetings,
Nadja
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: A few questions about and tags
Posted by Nadja Senoucci <se...@21st.de>.
Thanks for the info! I am currently trying those things out when I can't get
it running I'll let you know. ;)
Greetings,
Nadja
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: A few questions about and tags
Posted by Nicolas De Loof <ni...@cgey.com>.
> Hello,
>
> I have a few question about those tags.
>
> 1) How can I preselect a value in a dropdown? Meaning: I already have a
> value (one that was selected before) and I want that to be selected when the
> form gets displayed.
if your formbean has a property "foo", using :
<html:select property="foo">
<html:option value="0">none</html:option>
<html:option value="1">one</html:option>
<html:option value="2">two</html:option>
</html:select>
will display a select list with item selected from property value.
> 2) I want to have one dropdown that changes another one when something gets
> selected. I know, you have to use JavaScript for that and use the onChange
> event. But can I still use struts for that? I have the different options in
> different Java Collections. How would I go about that?
>
You will have to use javascript for that. You can use struts iterate tags to build javascript code from your datas
collections :
<script type="text/javascript">
<bean:size id="size" name="myCollection"/>
var datas = new Array[<bean:write name="size"/>];
<logic:iterate id="item" name="myCollection" indexId="index"/>
datas[<bean:write name="index"/>] = "<bean:write name="item"/>";
</logic:iterate>
</script>
> 3) My collections (with the different options) are kind of archives holding
> objects of a certain type. Now I want a default value in the dropdown like
> 'Please choose one of the following...' or something like that. Can I have
> that without putting it into my collection?
>
You can use this :
<html:select property="foo">
<option value="nothing has been selected!">Please choose one ...</option>
<html:option value="...">...</html:option>
</html:select>
If foo is null or no html:option value is same, first item in list will be displayed by many browsers as 'current'.
Nico.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org