You can use org.apache.struts2.util.ListEntry , a default object to hold key
value in Roles list box for JSP page dropdowns.

<s:select label="Role:" name="roleId" list="roles" />

Regards,
Raghuveer Vellanki
-----Original Message-----
From: Sommers, Elizabeth [mailto:somme...@pragmatics.com] 
Sent: Thursday, November 12, 2009 7:32 PM
To: Struts Users Mailing List
Subject: Confused about Drop down lists (database generated)

All the drop down lists in my application need to be generated from the
database.  Some of these lists will be needed for more than one JSP.
So, in order to work with the <s:select> tag I am building an action for
each list.

I know this has to be wrong.  Especially because some JSP's will need
multiple drop down lists.  What is the best way of doing this in struts
2.1.8?  Here is an example create method that I am using and the JSP
that feeds it.  Should I be using a better way to get to create from a
JSP?  I want to be able to use the roles drop down in multiple JSP's.

public String createUser()
        {
                User user = new User();
                user.setUserName(userName);
                user.setPassword(password);
                user.setFirstName(firstName);
                user.setLastName(lastName);
                user.setPhone(phone);
                user.setEmail(email);
                service.createUser(user);
                String userId = service.getUserId(user.getUserName());
                roleUser = new RoleUser();
                roleUser.setRoleId(roleId);
                roleUser.setUserId(userId);
                service.createRoleUser(roleUser);
                roleUser = null;
                user = null;
                return SUCCESS;
}

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<s:head />
<body>
<font color="red"><html:errors /></font>
<s:form action="createUserAction">
        <div class="inputs">
        <s:hidden name="id" /> 
        <s:textfield label="User Name:" name="userName" /> 
        <s:password label="Password:"
                name="password" /> 
        <s:password label="Repeat Password"
                name="password2" /></div>
        <s:textfield label="First Name:" name="firstName"></s:textfield>
        <s:textfield label="Last Name:" name="lastName"/>
        <s:textfield label="Email:" name="email"/>
        <s:textfield label="Phone:" name="phone"/>
        <s:select label="Role:" name="roleId" list="roles" listKey="id"
listValue="name"/>
        <s:submit></s:submit>
        </div>
</s:form>
</body>

Elizabeth Sommers
Build and Release Engineer
Pragmatics, Inc.
703.761.4033

www.pragmatics.com 

Practical. Reliable. Secure.

This e-mail message, including any attachments, is intended only for the
identified recipient(s). It may contain proprietary or otherwise legally
protected information of Pragmatics, Inc. Any unauthorized review, use,
copying, disclosure or distribution is strictly prohibited. If you have
received this communication in error and are not the intended recipient,
please immediately notify the sender of this message by reply e-mail and
delete or otherwise destroy the e-mail, attachments, and any copies.

 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to