You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sean jones <se...@ubs.com> on 2004/02/13 18:00:10 UTC
Using a java.util.List with a HTML:SELECT
is it possible to use a java.util.List object with an HTML:SELECT control.
import java.util.List;
import java.util.ArrayList;
public final class Roles extends Ojbect {
public Roles() {}
public static List getRoles() {
List r = new ArrayList();
r.add("ADMIN");
r.add("SUPERADMIN");
r.add("CLERK");
r.add("SUPERCLERK");
return r;
}
}
in jsp
i would use
<html:form action="....." >
<html:select property="formprop">
<!-- what goest inside the html:select aattribute -->
<html:options......
<html:select>
</html:form>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Using a java.util.List with a HTML:SELECT
Posted by sean jones <se...@ubs.com>.
i am aware of this option but DAO only returns a list of Strings and i prefer
that to a list of beans. The reason is i am more interested in the role name
than the role_id.
I plan to delete all the roles then put them back with a batchupdate.
This allows the user to selected all the roles to get rid of in one shot -vs-
one at a time.
Also roles cannot be deleted if they are in use (USER_ROLES - {user_id,
role_id})
Maybe i am wrong, and should change the DAO to return a List
of LabelValueBeans
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Using a java.util.List with a HTML:SELECT
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
The <html:options....> and <html:optionsCollection...> tags expect a
collection of beans - not String values.
If you put the values in beans then you it goes something like
<html:select name="myForm" property="roleName">
<html:optionsCollection name="myForm" property="roleList"
label="roleName" value="roleId"/>
</html:select>
So you store the list of roles in your action form under the property
"roleList" and that contains a List of beans which
have roleName and roleId properties.
Niall
----- Original Message -----
From: "sean jones" <se...@ubs.com>
To: <st...@jakarta.apache.org>
Sent: Friday, February 13, 2004 5:00 PM
Subject: Using a java.util.List with a HTML:SELECT
>
> is it possible to use a java.util.List object with an HTML:SELECT control.
>
> import java.util.List;
> import java.util.ArrayList;
>
> public final class Roles extends Ojbect {
> public Roles() {}
> public static List getRoles() {
> List r = new ArrayList();
> r.add("ADMIN");
> r.add("SUPERADMIN");
> r.add("CLERK");
> r.add("SUPERCLERK");
> return r;
> }
> }
>
> in jsp
>
> i would use
> <html:form action="....." >
> <html:select property="formprop">
>
> <!-- what goest inside the html:select aattribute -->
> <html:options......
>
> <html:select>
> </html:form>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Using a java.util.List with a HTML:SELECT
Posted by Oliver Thiel <th...@gmx.de>.
Hi,
You can try something like this:
1. Instead of return r ---> request.setAttribute("formprop",r);
2. In your JSP
<select name="formprop">
<logic:iterate id="field" name="formprop">
<option value="<bean:write name="field"
property="formprop[]"/>"><bean:write name="field" property="formprop[]"/></option>
</logic:iterate>
</select>
If you want your property|value pair to be different,
you should use a HashMap.
Oliver
>
> is it possible to use a java.util.List object with an HTML:SELECT control.
>
> import java.util.List;
> import java.util.ArrayList;
>
> public final class Roles extends Ojbect {
> public Roles() {}
> public static List getRoles() {
> List r = new ArrayList();
> r.add("ADMIN");
> r.add("SUPERADMIN");
> r.add("CLERK");
> r.add("SUPERCLERK");
> return r;
> }
> }
>
> in jsp
>
> i would use
> <html:form action="....." >
> <html:select property="formprop">
>
> <!-- what goest inside the html:select aattribute -->
> <html:options......
>
> <html:select>
> </html:form>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
--
GMX ProMail (250 MB Mailbox, 50 FreeSMS, Virenschutz, 2,99 EUR/Monat...)
jetzt 3 Monate GRATIS + 3x DER SPIEGEL +++ http://www.gmx.net/derspiegel +++
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org