You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dylan Stamat <dy...@gmail.com> on 2005/09/14 22:31:45 UTC

Keeping Session small using Validation

I have an Action which sets a populated List in a DynaValidatorForm Bean.
The "input" of the ActionMapping in the struts-config simply points back to 
the .jsp page (actually a tile def) and uses <html:errors/> to print out the 
error messages.

If no validation problems occur, there aren't any problems.
However, if the validation fails, I get an error within the .jsp page 
complaining that my List is null.

Question:
1) The Action populated this List and explicitly set it in the Form Bean... 
so, shouldn't the "input" page have access to this populated field ?

Answers:
1) Yes, I could set the List in the Session, but I'm trying to avoid this.
2) I could also use a basic Form Bean instead of a Dyna, but I want to use a 
Dyna.


This seems like such a simple and common task, but can't for the life of me 
get it to work.
Any help would be greatly appreciated !
Thanks !
==
Dylan

Re: Keeping Session small using Validation

Posted by Kishore Senji <ki...@gmail.com>.
If you only want to use a DynaActionForm, you could use TilesController and 
set the list in the form using BeanUtils.

In you tiles controller get the ActionForm for the module and set the 
corresponding form property.

ActionConfig actionConfig = (ActionConfig)request.getAttribute(
Globals.MAPPING_KEY);
DyanActionForm form = null;
if(StringUtils.equals(actionConfig.getScope(), "request")){
form = (DynaActionForm) request.getAttribute(actionConfig.getAttribute());
} else {
// similarly read from session
}

form.set("optionsCollectionProperty", optionsCollectionProperty); 

Since the tiles controller is always executed just before rendering the jsp, 
you are guaranteed to have the options collection always populated even in 
the "validation failure" case

On 9/14/05, Dylan Stamat <dy...@gmail.com> wrote:
> 
> I have an Action which sets a populated List in a DynaValidatorForm Bean.
> The "input" of the ActionMapping in the struts-config simply points back 
> to
> the .jsp page (actually a tile def) and uses <html:errors/> to print out 
> the
> error messages.
> 
> If no validation problems occur, there aren't any problems.
> However, if the validation fails, I get an error within the .jsp page
> complaining that my List is null.
> 
> Question:
> 1) The Action populated this List and explicitly set it in the Form 
> Bean...
> so, shouldn't the "input" page have access to this populated field ?
> 
> Answers:
> 1) Yes, I could set the List in the Session, but I'm trying to avoid this.
> 2) I could also use a basic Form Bean instead of a Dyna, but I want to use 
> a
> Dyna.
> 
> 
> This seems like such a simple and common task, but can't for the life of 
> me
> get it to work.
> Any help would be greatly appreciated !
> Thanks !
> ==
> Dylan
> 
>

Re: Keeping Session small using Validation

Posted by Sudhaker Raj <su...@gmail.com>.
What about keeping the list in form-bean? It is DynaForm, so you can
populate using form.set("mylist", mylisy); and retrieve back using
${form.map.mylist} (or RT equivalent of it).

If you put in session, you have to take care of removal. In this case
Struts will take care of it and recycle it.


On 9/14/05, Sudhaker Raj <su...@gmail.com> wrote:
>   /----------\
>   |  Action  | populates list
>   \----------/
>        |
>        V
>   /----------\
>   | JSP/Tiles|
>   \----------/
> 
> The list is not being populated when validation fails as framework is
> throwing back request to JSP/Tiles without running the population
> code. This is very well expected behavior.
> 
> A simple work-around can be assigning input to the action which is
> generating the page. If you don't want to execute the population code
> again and again, you gotta to hold it somewhere.
> 
> Cheers,
> Sudhaker
> 


-- 
Cheers,
Sudhaker Raj
http://thej2ee.com

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


Re: Keeping Session small using Validation

Posted by Sudhaker Raj <su...@gmail.com>.
  /----------\
  |  Action  | populates list
  \----------/
       | 
       V
  /----------\
  | JSP/Tiles|
  \----------/
  
The list is not being populated when validation fails as framework is
throwing back request to JSP/Tiles without running the population
code. This is very well expected behavior.

A simple work-around can be assigning input to the action which is
generating the page. If you don't want to execute the population code
again and again, you gotta to hold it somewhere.

Cheers,
Sudhaker

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