Re: DynaValidatorForm 'forgets' request-attribute on redisplay after validation

2004-11-28 Thread Joe Germuska
At 11:31 AM + 11/24/04, Adam Hardy wrote:
On 11/23/2004 02:20 PM Joe Germuska wrote:
Your action isn't executed if validation fails.  However, the 
validation is performed on a second request, so the object placed 
into the scope before the form was presented is no longer there.

If your categories are really relatively static, consider managing 
them in Application scope rather than request.  I often have one or 
more plugins which initialize common menus like states and 
provinces or months of the year and place them into the application 
scope (I like to use the DigestingPlugIn).  Your code doesn't look 
like there's anything particularly request-sensitive about the 
category tree.

Some people make lists a property of the form itself.  This is also 
one of the core use cases for some kind of view controller 
registered against the input forward's path, which is one of my 
goals to implement in a Struts 1.3.x timeframe.

Joe
Joe,
I hope you don't think I'm labouring a point after the big 
discussion last week, but regarding a view controller registered 
against the input forward's path, I just don't get the paradigm.

It seems like an unnecessary complexity when you can do what Matt 
suggested and point the input attribute at a 'loader' action mapping.
As Struts is designed now, setting the "input" attribute of an action 
mapping to point to another action mapping results in two passes 
through the request processor for a single HTTP request.  This is not 
a use case for which Struts is designed or tested, and which could 
have strange side effects.  Certainly, many people use it today 
without problems, but why not move Struts towards a clearly defined 
usage pattern which doesn't involve any grey areas like this?

Having a loader action decouples it from the validation+processing 
action, which seems friendly and OO to me. Then you can use that 
loader action from anywhere - can you say the same about your view 
controller registered against the input forward path?
When I say that it's registered against the input forward path, I 
don't mean that it's connected to the validating action mapping.  I 
mean that the system is configured so that any time it is headed to 
the path defined as the input forward path, it will execute one or 
more view controllers.  Therefore, it doesn't matter whether you are 
presenting the form for the first time or on a subsequent pass; the 
view controller code would still be executed.  To me this seems "more 
OO" because it associates the processing code with the context in 
which it is used.  No one needs to remember a sequence of actions 
which must be chained; they just trust that the request context 
(including the session and application) have the right data in the 
right places, and then small adjustments necessary to rendering the 
view can be encapsulated cleanly.

Does that help at all?
Joe
--
Joe Germuska
[EMAIL PROTECTED]  
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction"  -The Ex

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: DynaValidatorForm 'forgets' request-attribute on redisplay after validation

2004-11-24 Thread Adam Hardy
On 11/23/2004 02:20 PM Joe Germuska wrote:
Your action isn't executed if validation fails.  However, the validation 
is performed on a second request, so the object placed into the scope 
before the form was presented is no longer there.

If your categories are really relatively static, consider managing them 
in Application scope rather than request.  I often have one or more 
plugins which initialize common menus like states and provinces or 
months of the year and place them into the application scope (I like to 
use the DigestingPlugIn).  Your code doesn't look like there's anything 
particularly request-sensitive about the category tree.

Some people make lists a property of the form itself.  This is also one 
of the core use cases for some kind of view controller registered 
against the input forward's path, which is one of my goals to implement 
in a Struts 1.3.x timeframe.

Joe
Joe,
I hope you don't think I'm labouring a point after the big discussion 
last week, but regarding a view controller registered against the input 
forward's path, I just don't get the paradigm.

It seems like an unnecessary complexity when you can do what Matt 
suggested and point the input attribute at a 'loader' action mapping.

Having a loader action decouples it from the validation+processing 
action, which seems friendly and OO to me. Then you can use that loader 
action from anywhere - can you say the same about your view controller 
registered against the input forward path?

You have to do the loading without validation anyway, i.e. you need that 
first action. So how do you hook up your view controller to the loading 
action, or do you have some further mechanism that allows you to have 
only one action, tweaking validation on or off somehow?

Adam
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: DynaValidatorForm 'forgets' request-attribute on redisplay after validation

2004-11-23 Thread Alexander Czernay
The problem is, that the given form actually edits the categories-tree 
and as it is presented to the user after editing it, it should be 
updated after the form is submitted.

Alexander
Joe Germuska wrote:
Your action isn't executed if validation fails.  However, the validation 
is performed on a second request, so the object placed into the scope 
before the form was presented is no longer there.

If your categories are really relatively static, consider managing them 
in Application scope rather than request.  I often have one or more 
plugins which initialize common menus like states and provinces or 
months of the year and place them into the application scope (I like to 
use the DigestingPlugIn).  Your code doesn't look like there's anything 
particularly request-sensitive about the category tree.

Some people make lists a property of the form itself.  This is also one 
of the core use cases for some kind of view controller registered 
against the input forward's path, which is one of my goals to implement 
in a Struts 1.3.x timeframe.

Joe
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: DynaValidatorForm 'forgets' request-attribute on redisplay after validation

2004-11-23 Thread Matt Bathje
Alexander Czernay wrote:
I have a simple DynaValidatorForm
 




 

that is called whtin an action
   
   

that inserts so data into the request inside its execute method
   public ActionForward execute(
   ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response) throws Exception {
 // read CategoriesTree and put it into request scope
   try {
   CategoriesModel categories = new CategoriesModel();
   request.setAttribute(Constants.CATEGORY_TREE, 
categories.getCategories());
   } catch (ApplicationException e) {
   request.setAttribute(Constants.CATEGORY_TREE, null);
   }

   return mapping.findForward("success");
   }  
This works quite well during the form's initial display. But if I enter 
wrong values so that the validation fails, the CATEGORY_TREE-attribute 
is missing and thus the JSP-view fails.

Isn't the execute-method called again when the validation fails? 
Anything else wrong here?

Thanks for any help,
Alexander
Alexander - what happens on failure is based on the "input" attribute of 
the action mapping. Right now you have it set to msys.categories-edit, 
which I would guess is a tile definition. If you go directly to the tile 
definition then no, the execute() method is not called, because you 
bypassed the action.

You would have to set the input attribute to be /categories-edit.do to 
get the execute() method to run again.

This may not work either because that action always validates the form 
data. You most likely need to setup a "loader" action that just does the 
CATEGORY-TREE loading, and forward back to that when there is an error.

If you wanted you could also setup your own ActionForm (don't use 
DynaForms) and have the validate() method of the ActionForm check 
whether it should actually validate or not. If you choose this option 
search on the archives a bit, I'm pretty sure there is info about doing 
something like that.

Matt
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: DynaValidatorForm 'forgets' request-attribute on redisplay after validation

2004-11-23 Thread Joe Germuska
Your action isn't executed if validation fails.  However, the 
validation is performed on a second request, so the object placed 
into the scope before the form was presented is no longer there.

If your categories are really relatively static, consider managing 
them in Application scope rather than request.  I often have one or 
more plugins which initialize common menus like states and provinces 
or months of the year and place them into the application scope (I 
like to use the DigestingPlugIn).  Your code doesn't look like 
there's anything particularly request-sensitive about the category 
tree.

Some people make lists a property of the form itself.  This is also 
one of the core use cases for some kind of view controller registered 
against the input forward's path, which is one of my goals to 
implement in a Struts 1.3.x timeframe.

Joe
At 3:09 PM +0100 11/23/04, Alexander Czernay wrote:
I have a simple DynaValidatorForm
 




 

that is called whtin an action
   
   

that inserts so data into the request inside its execute method
   public ActionForward execute(
   ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response) throws Exception {
 // read CategoriesTree and put it into request scope
   try {
   CategoriesModel categories = new CategoriesModel();
   request.setAttribute(Constants.CATEGORY_TREE, 
categories.getCategories());
   } catch (ApplicationException e) {
   request.setAttribute(Constants.CATEGORY_TREE, null);
   }

   return mapping.findForward("success");
   }  

This works quite well during the form's initial display. But if I 
enter wrong values so that the validation fails, the 
CATEGORY_TREE-attribute is missing and thus the JSP-view fails.

Isn't the execute-method called again when the validation fails? 
Anything else wrong here?

Thanks for any help,
Alexander
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
Joe Germuska
[EMAIL PROTECTED]  
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction"  -The Ex

DynaValidatorForm 'forgets' request-attribute on redisplay after validation

2004-11-23 Thread Alexander Czernay
I have a simple DynaValidatorForm
 




 

that is called whtin an action
   
   

that inserts so data into the request inside its execute method
   public ActionForward execute(
   ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response) throws Exception {
  
   // read CategoriesTree and put it into request scope
   try {
   CategoriesModel categories = new CategoriesModel();
   request.setAttribute(Constants.CATEGORY_TREE, 
categories.getCategories());
   } catch (ApplicationException e) {
   request.setAttribute(Constants.CATEGORY_TREE, null);
   }

   return mapping.findForward("success");
   }   

This works quite well during the form's initial display. But if I enter 
wrong values so that the validation fails, the CATEGORY_TREE-attribute 
is missing and thus the JSP-view fails.

Isn't the execute-method called again when the validation fails? 
Anything else wrong here?

Thanks for any help,
Alexander
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]