You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Asif Rahman <ar...@worlddata.com> on 2004/06/15 23:00:46 UTC

Struts alternative to using request.getParameterValues in an actionform?

Hi Im using <logic:iterate> shown below to iterate through an arraylist (sitesList) in my actionform (OpportunitySitesForm).  This arraylist contains a number of Site objects which have the properties siteName, address1, and city.  This is getting displayed correctly.  Now when processing the form, I am wondering whether in struts there is a way to retrieve these as objects and automatically populate setSitesList(ArrayList) method, rather than manually use request.getParameterValues for siteName, address1, city, create individual Site objects, add the site objects to an arraylist  with Site objects and finally pass the list into setSitesList(arraylist).   

    <logic:iterate id="myCollectionElement" name="OpportunitySitesForm" property="sitesList" >
      <tr> 
        <td colspan="2"><input type="text" name="siteName" value='<bean:write name="myCollectionElement" property="siteName" />'></td>
        <td colspan="2"><input type="text" name="address1" value='<bean:write name="myCollectionElement" property="address1" />'></td>
        <td colspan="2"><input type="text" name="city" value='<bean:write name="myCollectionElement" property="city" />'></td>
      <tr>
    </logic:iterate>

Any help would be most appreciated.  Thanks!

-Asif

Re: How to handle refresh

Posted by mike <mi...@michaelmcgrady.com>.
Sorry, I forgot that tags do not show in these emails.  This should have 
read "IF YOU USE &lt;html:form &gt;"

At 07:27 AM 6/21/2004, mike wrote:
>You need to just look at the code and get the idea.  The idea is that you 
>have to have tokens that match.  One token is kept in the 
>session.  Another token is kept in the request.  The Action class has 
>three methods that are important: isTokenValid(request), 
>resetToken(request) and saveToken(request).  When you are going to a page 
>that has a form you want to protect, you need to run it through an action 
>and call the saveToken method.  This puts a token into the session.  You 
>cannot put a token into the request from the Action class.  When you do 
>this, IF YOU USE , the token gets put into the request as a HIDDEN FORM 
>FIELD. AFter you check whether a token is valid, you should reset the 
>token. There are lots of good explanations of this in more detail. On 
>tokens, I recommend the one in "The Struts Framework: Practical Guide for 
>Programmers", by Sue Spielman. Sue is a great teacher, as are other 
>authors of Struts books. Michael At 11:45 PM 6/20/2004, suhash.c@tcs.com 
>wrote: >Hi Mike, > >We are aware that the transactional token needs to be 
>used for this purpose. >But we don't know the details thereof. >Need some 
>more info on that. >Searched a lot but could not find any details. >Had 
>tried the resetToken method of the Action class but nothing 
>happened. > >Suhash > > >mike > >06/21/2004 12:02 PM >Please respond 
>to >"Struts Users Mailing List" > >To >"Struts Users Mailing List" , 
>"Struts Users >Mailing List" >cc >Subject >Re: How to handle 
>refresh > > > > >This is somewhat impossible to answer without more 
>information, but the >basic Idea is probably to not allow records to be 
>saved with a refresh or a >resubmittal of a form through the use of a 
>token in your action classes. > >At 11:22 PM 6/20/2004, suhash.c@tcs.com 
>wrote: > > >Hi all, > > > > We wish to customise the behaviour of IE 
>refresh by just making > > it fetch the latest data from the db. > > It 
>works fine in list and edit screens where the last action > > was a 
>fetch. > > But if the user has previously saved a record, refresh 
>causes > > the save action to be executed once again, contrary to what we 
>wish to > > achieve. > > Is there any way in which we customise this 
>behaviour? > > > > > >TIA, > > > >Suhash > > > >--------------------------- 
>------------------------------------------ > >To unsubscribe, e-mail: 
>user-unsubscribe@struts.apache.org > >For additional commands, e-mail: 
>user-help@struts.apache.org > >ForwardSourceID:NT000056BE > >-------------- 
>------------------------------------------------------- >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: How to handle refresh

Posted by mike <mi...@michaelmcgrady.com>.
You need to just look at the code and get the idea.  The idea is that you 
have to have tokens that match.  One token is kept in the session.  Another 
token is kept in the request.  The Action class has three methods that are 
important: isTokenValid(request), resetToken(request) and 
saveToken(request).  When you are going to a page that has a form you want 
to protect, you need to run it through an action and call the saveToken 
method.  This puts a token into the session.  You cannot put a token into 
the request from the Action class.  When you do this, IF YOU USE 
<html:form>, the token gets put into the request as a HIDDEN FORM 
FIELD.  AFter you check whether a token is valid, you should reset the 
token.  There are lots of good explanations of this in more detail.  On 
tokens, I recommend the one in "The Struts Framework: Practical Guide for 
Programmers", by Sue Spielman.  Sue is a great teacher, as are other 
authors of Struts books.

Michael

At 11:45 PM 6/20/2004, suhash.c@tcs.com wrote:

>Hi Mike,
>
>We are aware that the transactional token needs to be used for this purpose.
>But we don't know the details thereof.
>Need some more info on that.
>Searched a lot but could not find any details.
>Had tried the resetToken method of the Action class but nothing happened.
>
>Suhash
>
>
>mike <mi...@michaelmcgrady.com>
>
>06/21/2004 12:02 PM
>Please respond to
>"Struts Users Mailing List" <us...@struts.apache.org>
>
>To
>"Struts Users Mailing List" <us...@struts.apache.org>, "Struts Users 
>Mailing List" <us...@struts.apache.org>
>cc
>Subject
>Re: How to handle refresh
>
>
>
>
>This is somewhat impossible to answer without more information, but the
>basic Idea is probably to not allow records to be saved with a refresh or a
>resubmittal of a form through the use of a token in your action classes.
>
>At 11:22 PM 6/20/2004, suhash.c@tcs.com wrote:
>
> >Hi all,
> >
> >           We wish to customise the behaviour of IE refresh by just making
> > it fetch the latest data from the db.
> >           It works fine in list and edit screens where the last action
> > was a fetch.
> >           But if the user has previously saved a record, refresh causes
> > the save action to be executed once again, contrary to what we wish to
> > achieve.
> >           Is there any way in which we customise this behaviour?
> >
> >
> >TIA,
> >
> >Suhash
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
>
>ForwardSourceID:NT000056BE
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org

Re: How to handle refresh

Posted by su...@tcs.com.
Hi Mike,

We are aware that the transactional token needs to be used for this 
purpose.
But we don't know the details thereof.
Need some more info on that.
Searched a lot but could not find any details.
Had tried the resetToken method of the Action class but nothing happened.

Suhash 



mike <mi...@michaelmcgrady.com> 
06/21/2004 12:02 PM

Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
"Struts Users Mailing List" <us...@struts.apache.org>, "Struts Users 
Mailing List" <us...@struts.apache.org>
cc

Subject
Re: How to handle refresh






This is somewhat impossible to answer without more information, but the 
basic Idea is probably to not allow records to be saved with a refresh or 
a 
resubmittal of a form through the use of a token in your action classes.

At 11:22 PM 6/20/2004, suhash.c@tcs.com wrote:

>Hi all,
>
>           We wish to customise the behaviour of IE refresh by just 
making 
> it fetch the latest data from the db.
>           It works fine in list and edit screens where the last action 
> was a fetch.
>           But if the user has previously saved a record, refresh causes 
> the save action to be executed once again, contrary to what we wish to 
> achieve.
>           Is there any way in which we customise this behaviour?
>
>
>TIA,
>
>Suhash
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org

ForwardSourceID:NT000056BE 

Re: How to handle refresh

Posted by mike <mi...@michaelmcgrady.com>.
This is somewhat impossible to answer without more information, but the 
basic Idea is probably to not allow records to be saved with a refresh or a 
resubmittal of a form through the use of a token in your action classes.

At 11:22 PM 6/20/2004, suhash.c@tcs.com wrote:

>Hi all,
>
>           We wish to customise the behaviour of IE refresh by just making 
> it fetch the latest data from the db.
>           It works fine in list and edit screens where the last action 
> was a fetch.
>           But if the user has previously saved a record, refresh causes 
> the save action to be executed once again, contrary to what we wish to 
> achieve.
>           Is there any way in which we customise this behaviour?
>
>
>TIA,
>
>Suhash
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org

How to handle refresh

Posted by su...@tcs.com.
Hi all,

          We wish to customise the behaviour of IE refresh by just making 
it fetch the latest data from the db.
          It works fine in list and edit screens where the last action was 
a fetch.
          But if the user has previously saved a record, refresh causes 
the save action to be executed once again, contrary to what we wish to 
achieve.
          Is there any way in which we customise this behaviour? 
 

TIA,

Suhash

Re: [SOLVED] Re: Struts alternative to using request.getParameterValues in an actionform?

Posted by atta-ur rehman <at...@numetrics.com>.
You're welcome, Asif!

Now you why didn't I copy-pasted some code for you ;)

ATTA

----- Original Message ----- 
From: "Asif Rahman" <ar...@worlddata.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Thursday, June 17, 2004 8:17 AM
Subject: [SOLVED] Re: Struts alternative to using request.getParameterValues
in an actionform?


> Thanks a million Atta-ur!! Indexed properties worked!  I tried using the
> struts nested tagblibs first, but couldnt get it to work with that, it
> seemed good only for display, but not retrieving objects into the
actionform
> from the jsp page when submitting.  Indexed properties definitely did the
> trick.  I found the following links helpful:
>
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg96800.html
>
> and
>
> http://www.sudsy.net/technology/struts-advanced.html
>
>
> All I did with my code was....
>
>
> JSP snippet:
>   ......
>  <logic:iterate id="site" name="OpportunitySitesForm" property="sitesList"
> >
>    <tr>
>     <td colspan="2"><html:text name="site" property="siteName"
> indexed="true" /></td>
>
>      .......
>
> ActionForm snippet:
>
> public SitesDTO getSite(int index) {
>
> return (SitesDTO) sitesList.get(index);
>
> }
>
>
> public void setSite(int index, SitesDTO site) {
>
> this.sitesList.add(index,site);
>
> }
>
>
> where "site" in the logic:iterate has a matching "site" SiteDTO object in
> the actionform.
>
> -Asif
>
>
>
> ----- Original Message ----- 
> From: "atta-ur rehman" <at...@numetrics.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>; "Asif Rahman"
> <ar...@worlddata.com>
> Sent: Tuesday, June 15, 2004 5:14 PM
> Subject: Re: Struts alternative to using request.getParameterValues in an
> actionform?
>
>
> > Hellow Asif,
> >
> > "Indexed Properties" is exactly what you need here. For more info,
please
> > search thru the mail archive at:
> >
> > http://www.mail-archive.com/user@struts.apache.org/
> >
> > or at:
> >
> >
> > ----- Original Message ----- 
> > From: "Asif Rahman" <ar...@worlddata.com>
> > To: <us...@struts.apache.org>
> > Sent: Tuesday, June 15, 2004 2:00 PM
> > Subject: Struts alternative to using request.getParameterValues in an
> > actionform?
> >
> >
> > Hi Im using <logic:iterate> shown below to iterate through an arraylist
> > (sitesList) in my actionform (OpportunitySitesForm).  This arraylist
> > contains a number of Site objects which have the properties siteName,
> > address1, and city.  This is getting displayed correctly.  Now when
> > processing the form, I am wondering whether in struts there is a way to
> > retrieve these as objects and automatically populate
> setSitesList(ArrayList)
> > method, rather than manually use request.getParameterValues for
siteName,
> > address1, city, create individual Site objects, add the site objects to
an
> > arraylist  with Site objects and finally pass the list into
> > setSitesList(arraylist).
> >
> >     <logic:iterate id="myCollectionElement" name="OpportunitySitesForm"
> > property="sitesList" >
> >       <tr>
> >         <td colspan="2"><input type="text" name="siteName"
> > value='<bean:write name="myCollectionElement" property="siteName"
> />'></td>
> >         <td colspan="2"><input type="text" name="address1"
> > value='<bean:write name="myCollectionElement" property="address1"
> />'></td>
> >         <td colspan="2"><input type="text" name="city"
value='<bean:write
> > name="myCollectionElement" property="city" />'></td>
> >       <tr>
> >     </logic:iterate>
> >
> > Any help would be most appreciated.  Thanks!
> >
> > -Asif
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>



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


[SOLVED] Re: Struts alternative to using request.getParameterValues in an actionform?

Posted by Asif Rahman <ar...@worlddata.com>.
Thanks a million Atta-ur!! Indexed properties worked!  I tried using the
struts nested tagblibs first, but couldnt get it to work with that, it
seemed good only for display, but not retrieving objects into the actionform
from the jsp page when submitting.  Indexed properties definitely did the
trick.  I found the following links helpful:

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg96800.html

and

http://www.sudsy.net/technology/struts-advanced.html


All I did with my code was....


JSP snippet:
  ......
 <logic:iterate id="site" name="OpportunitySitesForm" property="sitesList"
>
   <tr>
    <td colspan="2"><html:text name="site" property="siteName"
indexed="true" /></td>

     .......

ActionForm snippet:

public SitesDTO getSite(int index) {

return (SitesDTO) sitesList.get(index);

}


public void setSite(int index, SitesDTO site) {

this.sitesList.add(index,site);

}


where "site" in the logic:iterate has a matching "site" SiteDTO object in
the actionform.

-Asif



----- Original Message ----- 
From: "atta-ur rehman" <at...@numetrics.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>; "Asif Rahman"
<ar...@worlddata.com>
Sent: Tuesday, June 15, 2004 5:14 PM
Subject: Re: Struts alternative to using request.getParameterValues in an
actionform?


> Hellow Asif,
>
> "Indexed Properties" is exactly what you need here. For more info, please
> search thru the mail archive at:
>
> http://www.mail-archive.com/user@struts.apache.org/
>
> or at:
>
>
> ----- Original Message ----- 
> From: "Asif Rahman" <ar...@worlddata.com>
> To: <us...@struts.apache.org>
> Sent: Tuesday, June 15, 2004 2:00 PM
> Subject: Struts alternative to using request.getParameterValues in an
> actionform?
>
>
> Hi Im using <logic:iterate> shown below to iterate through an arraylist
> (sitesList) in my actionform (OpportunitySitesForm).  This arraylist
> contains a number of Site objects which have the properties siteName,
> address1, and city.  This is getting displayed correctly.  Now when
> processing the form, I am wondering whether in struts there is a way to
> retrieve these as objects and automatically populate
setSitesList(ArrayList)
> method, rather than manually use request.getParameterValues for siteName,
> address1, city, create individual Site objects, add the site objects to an
> arraylist  with Site objects and finally pass the list into
> setSitesList(arraylist).
>
>     <logic:iterate id="myCollectionElement" name="OpportunitySitesForm"
> property="sitesList" >
>       <tr>
>         <td colspan="2"><input type="text" name="siteName"
> value='<bean:write name="myCollectionElement" property="siteName"
/>'></td>
>         <td colspan="2"><input type="text" name="address1"
> value='<bean:write name="myCollectionElement" property="address1"
/>'></td>
>         <td colspan="2"><input type="text" name="city" value='<bean:write
> name="myCollectionElement" property="city" />'></td>
>       <tr>
>     </logic:iterate>
>
> Any help would be most appreciated.  Thanks!
>
> -Asif
>
>
>
> ---------------------------------------------------------------------
> 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: Struts alternative to using request.getParameterValues in an actionform?

Posted by atta-ur rehman <at...@numetrics.com>.
okay, the other link was

http://jakarta.apache.org/struts/userGuide/building_view.html#indexed

hope this helps.

ATTA
----- Original Message ----- 
From: "atta-ur rehman" <at...@numetrics.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>; "Asif Rahman"
<ar...@worlddata.com>
Sent: Tuesday, June 15, 2004 2:14 PM
Subject: Re: Struts alternative to using request.getParameterValues in an
actionform?


> Hellow Asif,
>
> "Indexed Properties" is exactly what you need here. For more info, please
> search thru the mail archive at:
>
> http://www.mail-archive.com/user@struts.apache.org/
>
> or at:
>
>
> ----- Original Message ----- 
> From: "Asif Rahman" <ar...@worlddata.com>
> To: <us...@struts.apache.org>
> Sent: Tuesday, June 15, 2004 2:00 PM
> Subject: Struts alternative to using request.getParameterValues in an
> actionform?
>
>
> Hi Im using <logic:iterate> shown below to iterate through an arraylist
> (sitesList) in my actionform (OpportunitySitesForm).  This arraylist
> contains a number of Site objects which have the properties siteName,
> address1, and city.  This is getting displayed correctly.  Now when
> processing the form, I am wondering whether in struts there is a way to
> retrieve these as objects and automatically populate
setSitesList(ArrayList)
> method, rather than manually use request.getParameterValues for siteName,
> address1, city, create individual Site objects, add the site objects to an
> arraylist  with Site objects and finally pass the list into
> setSitesList(arraylist).
>
>     <logic:iterate id="myCollectionElement" name="OpportunitySitesForm"
> property="sitesList" >
>       <tr>
>         <td colspan="2"><input type="text" name="siteName"
> value='<bean:write name="myCollectionElement" property="siteName"
/>'></td>
>         <td colspan="2"><input type="text" name="address1"
> value='<bean:write name="myCollectionElement" property="address1"
/>'></td>
>         <td colspan="2"><input type="text" name="city" value='<bean:write
> name="myCollectionElement" property="city" />'></td>
>       <tr>
>     </logic:iterate>
>
> Any help would be most appreciated.  Thanks!
>
> -Asif
>
>
>
> ---------------------------------------------------------------------
> 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: Struts alternative to using request.getParameterValues in an actionform?

Posted by atta-ur rehman <at...@numetrics.com>.
Hellow Asif,

"Indexed Properties" is exactly what you need here. For more info, please
search thru the mail archive at:

http://www.mail-archive.com/user@struts.apache.org/

or at:


----- Original Message ----- 
From: "Asif Rahman" <ar...@worlddata.com>
To: <us...@struts.apache.org>
Sent: Tuesday, June 15, 2004 2:00 PM
Subject: Struts alternative to using request.getParameterValues in an
actionform?


Hi Im using <logic:iterate> shown below to iterate through an arraylist
(sitesList) in my actionform (OpportunitySitesForm).  This arraylist
contains a number of Site objects which have the properties siteName,
address1, and city.  This is getting displayed correctly.  Now when
processing the form, I am wondering whether in struts there is a way to
retrieve these as objects and automatically populate setSitesList(ArrayList)
method, rather than manually use request.getParameterValues for siteName,
address1, city, create individual Site objects, add the site objects to an
arraylist  with Site objects and finally pass the list into
setSitesList(arraylist).

    <logic:iterate id="myCollectionElement" name="OpportunitySitesForm"
property="sitesList" >
      <tr>
        <td colspan="2"><input type="text" name="siteName"
value='<bean:write name="myCollectionElement" property="siteName" />'></td>
        <td colspan="2"><input type="text" name="address1"
value='<bean:write name="myCollectionElement" property="address1" />'></td>
        <td colspan="2"><input type="text" name="city" value='<bean:write
name="myCollectionElement" property="city" />'></td>
      <tr>
    </logic:iterate>

Any help would be most appreciated.  Thanks!

-Asif



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