struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Thompson <elephant...@gmail.com>
Subject Re: Confused about Drop down lists (database generated)
Date Thu, 12 Nov 2009 15:08:16 GMT
Just add something like the following to the methods that execute before JSP
processing.

this.roles = service.getRoles();

You might also look into the Preparable interface, depending on application
design.

-Brian




On Thu, Nov 12, 2009 at 8:02 AM, Sommers, Elizabeth <SommersE@pragmatics.com
> wrote:

> 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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message