struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas De Loof" <nicolas.del...@cgey.com>
Subject Re: A few questions about <html:select> and <html:option> tags
Date Mon, 02 Jun 2003 07:33:35 GMT


> 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


Mime
View raw message