Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Subject: Re: Need Help Struts 2.0.8

Subject: Re: Need Help Struts 2.0.8

2007-11-01       - By Raghuveer Rawat

 Back
I found an Article on this in Ian Roughley's book. Posting here if someone
is implementing Tabular Data Entry support in their apps.

*Utilize Tabular Data Entry Support*

Struts2 provides support for using lists to transfer tabulated data

easily between the HTML user interface and actions. Let's take a

look at an example. Here is a class for Person; each attribute has

a getter and setter (not shown):

public class Person {

int id;

String name;

int age;

float height;

}

Our action would then use the person class in a list:

public class MyAction {

public List getPeopleList() { ? }

public void setPeopleList( List peopleList ) { ? }

?

}

Before we can use the Person class as an element in MyAction,

we need to add configuration information. This is achieved with

the "MyAction-conversion.properties" file, which is created in

the same package as MyAction. The name follows the same

convention as for validation, the name of the action followed by

a "*-conversion.properties" suffix. The file contents are:

Element_peopleList=Person

The prefix "Element_" is constant, with the last part of the lefthand

value being the name of the list property in the action class.

The right-hand side value is the full class name (including

package) of the class that is placed into the list.

To finish the example we need to render the list to the user:

<ww:iterator value="peopleList" status="stat">

<s:property value="peopleList[#stat.index].id" />

<s:property value="peopleList[#stat.index].name" />

<s:property value="peopleList[#stat.index].age" />

<s:property value="peopleList[#stat.index].height"/>

</ww:iterator>

Lists are indexed, so we use the index property of the iterators

status object to reference the element being displayed. This is

not the most efficient way of achieving this particular result, as

the value of the <s:property ? /> tags could have been simply

"id", "name", "age" and "height" respectively. What it does

show is a clean form of what is needed for an editable form.

For a tabular editable form using the same objects, the JSP is:

<s:form action="update" method="post" >

<s:iterator value="peopleList" status="stat">

<s:hidden

name="peopleList[%{#stat.index}].id"

value="%{peopleList[#stat.index].id}"/>

<s:textfield label="Name"

name="peopleList[%{#stat.index}].name"

value="%{peopleList[#stat.index].name}"/>

<s:textfield label="Age"

name="peopleList[%{#stat.index}].age"

value="%{peopleList[#stat.index].age}" />

<s:textfield label="Height"

name="peopleList[%{#stat.index}].height"

value="%{peopleList[#stat.index].height}"/>

<br/>

</s:iterator>

<s:submit value="Update"/>

</s:form>

Notice that the "name" and "value" attribute of this code is

similar to the "value" attribute above. The difference being in

the "name" we need to provide the actual index by surrounding

"#stat.index" with the correct token to obtain a value, and the

"value" attribute has the entire expression surrounded. Using

this code, Struts2 will create an ArrayList with populated

People objects, and set the list on the action using the

setPeopleList() method.

To allow Struts2 to create new objects in the list (perhaps you

are dynamically creating elements in the user interface), add the

following line to "MyAction-conversion.properties"

configuration file:

CreateIfNull_peopleList = true






On 11/1/07, John Doe <bashmakov@(protected)> wrote:
>
> The simplest way (if I'have understood your problem right) is to create 10
> variables in your action class (with getters and setters of course) and on
> the form. So it'll be
>
> private String firstName1;
> private String firstName2;
> private String firstName3;
> ...
> private String firstName10;
>
> in the action class and :
>
> <s:textfield name="firstName1"  size="25" maxlength ="20"/>
> <s:textfield name="firstName2"  size="25" maxlength ="20"/>
> <s:textfield name="firstName3"  size="25" maxlength ="20"/>
> ...
> <s:textfield name="firstName10"  size="25" maxlength ="20"/>
>
> Struts fills action variables values automatically using reflection.
>
> On 11/1/07, Raghuveer Rawat <raghuveer.rawat@(protected)> wrote:
> >
> > Hi, still looking for help.
> >
> >
> > On 10/31/07, Raghuveer Rawat <raghuveer.rawat@(protected)> wrote:
> > >
> > > Hi, I have form which allows user to invite other users. A user can
> > invite
> > > a max of 10 users at a time. A row contain First Name, Last Name, and
> > Email
> > > Address.
> > > How should I name these textfields (OGNL expression) and how should I
> > > retrieve these values in Action Class?
> > >
> > >
> > > <table>
> > >
> > > <
> > > tr>
> > >
> > > <td>First Name</ td>
> > >
> > > <td>Last Name</ td>
> > >
> > > <td>Email Address</ td>
> > >
> > > </tr>
> > >
> > > <tr>
> > >
> > > <s:textfield name="firstName"  size="25" maxlength ="20"/></td>
> > >
> > > <s:textfield name="lastName" size="25" maxlength ="20"/></td>
> > >
> > > <s:textfield name="email" size="25" maxlength= "20"/></td>
> > >
> > > </tr>
> > >
> > >  similarly 9 more rows like this.
> > >
> > > </table>
> > >
> > >
> > >
> >
>
>
>
> --
> Best regards,
> Bashma?ov Anton
>

©2008 junlu.com - Jax Systems, LLC, U.S.A.