You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Raghuveer Rawat <ra...@gmail.com> on 2007/11/01 00:13:12 UTC
Need Help Struts 2.0.8
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>
Re: Need Help Struts 2.0.8
Posted by Antonio Petrelli <an...@gmail.com>.
2007/11/1, Raghuveer Rawat <ra...@gmail.com>:
>
> Hi, still looking for help.
Here it is:
http://struts.apache.org/2.x/docs/home.html
In other words, RTFM :-)
Antonio
Re: Need Help Struts 2.0.8
Posted by Dave Newton <ne...@yahoo.com>.
Not really, and it's probably not a big deal anyway.
In the future it might make more sense to post a link
to the book if you feel compelled to do something like
that or post the code that you used.
Or you could create or add to a page on one of the
struts wikis.
d.
--- Raghuveer Rawat <ra...@gmail.com> wrote:
> Oh, Didn't notice that. Can this message be deleted?
>
> On 11/1/07, Dave Newton <ne...@yahoo.com>
> wrote:
> >
> > --- Raghuveer Rawat wrote:
> > > I found an Article on this in Ian Roughley's
> book.
> > > Posting here if someone is implementing Tabular
> Data
> >
> > > Entry support in their apps.
> >
> > You know it's copyrighted, right?
> >
> > d.
> >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> user-help@struts.apache.org
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Need Help Struts 2.0.8
Posted by Raghuveer Rawat <ra...@gmail.com>.
Oh, Didn't notice that. Can this message be deleted?
On 11/1/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Raghuveer Rawat wrote:
> > I found an Article on this in Ian Roughley's book.
> > Posting here if someone is implementing Tabular Data
>
> > Entry support in their apps.
>
> You know it's copyrighted, right?
>
> d.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: Need Help Struts 2.0.8
Posted by Dave Newton <ne...@yahoo.com>.
--- Raghuveer Rawat wrote:
> I found an Article on this in Ian Roughley's book.
> Posting here if someone is implementing Tabular Data
> Entry support in their apps.
You know it's copyrighted, right?
d.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Need Help Struts 2.0.8
Posted by Raghuveer Rawat <ra...@gmail.com>.
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 <ba...@gmail.com> 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 <ra...@gmail.com> wrote:
> >
> > Hi, still looking for help.
> >
> >
> > On 10/31/07, Raghuveer Rawat <ra...@gmail.com> 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
>
Re: Need Help Struts 2.0.8
Posted by Raghuveer Rawat <ra...@gmail.com>.
Thanks Jim for link. Yeah, I have to upgrade to newer version 2.0.11.
On 11/1/07, Jim Cushing <ji...@mac.com> wrote:
>
> It's not necessary to do declare 10 variables. Here's an example:
>
> http://struts.apache.org/2.x/docs/tabular-inputs.html
>
> By the way, Struts 2.0.11 is out, so Raguveer, you might want to
> upgrade. The answer to your particular question doesn't change, but
> there are some bug and security fixes you should have.
>
> On Nov 1, 2007, at 7:14 AM, John Doe 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 <ra...@gmail.com> wrote:
> >>
> >> Hi, still looking for help.
> >>
> >>
> >> On 10/31/07, Raghuveer Rawat <ra...@gmail.com> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: Need Help Struts 2.0.8
Posted by Jim Cushing <ji...@mac.com>.
It's not necessary to do declare 10 variables. Here's an example:
http://struts.apache.org/2.x/docs/tabular-inputs.html
By the way, Struts 2.0.11 is out, so Raguveer, you might want to
upgrade. The answer to your particular question doesn't change, but
there are some bug and security fixes you should have.
On Nov 1, 2007, at 7:14 AM, John Doe 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 <ra...@gmail.com> wrote:
>>
>> Hi, still looking for help.
>>
>>
>> On 10/31/07, Raghuveer Rawat <ra...@gmail.com> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Need Help Struts 2.0.8
Posted by John Doe <ba...@gmail.com>.
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 <ra...@gmail.com> wrote:
>
> Hi, still looking for help.
>
>
> On 10/31/07, Raghuveer Rawat <ra...@gmail.com> 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
Re: Need Help Struts 2.0.8
Posted by Raghuveer Rawat <ra...@gmail.com>.
Hi, still looking for help.
On 10/31/07, Raghuveer Rawat <ra...@gmail.com> 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>
>
>
>