You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Greg Murray <GM...@edgewater.com> on 2003/01/23 05:16:09 UTC

Use of DynaActionFormClass

Hello,

Currently I'm working on an Struts application that has a tree control for navigation on the left side of the page, and the rest of the page is taken up by the actual body content - no frames are used for the layout, just CSS, so it is actually one single page.  My plan was to have a JavaScript function run each time the user clicked on a link in the tree which would set the values of an HTML form (lets call it navigationForm), then submit the form.  One of the fields of the HTML form would contain the Struts action mapping (lets call the field actionMapping) which was to be invoked for the tree link.  All tree links would use the same form, and all pages would contain this form.  The action that is invoked by this form submission (call it navigationAction) would be responsible for looking up actionMapping, and forwarding on the request to the action denoted by actionMapping.  I should also note that I'm using dynamic form beans.

My problem is that many of the actions to which I want to forward are expecting their own form bean, not the one that was submitted for navigationForm.  As far as I can tell, I have two options:

1.  Have all forms in my application use the same form bean, so I can just pass it around without having to worry about different actions using different form beans.  The problem here is that for some fields, I may want to do validation sometimes, but not all the time, but using the same form bean for all actions would require that if validation is set for a field, then it's always validated.  Also, for some reason, this solution just doesn't "feel" right to me.
2.  Create a DynaActionForm in navigationAction for the form related to the action to which I want to forward, and fill it with any matching properties from navigationForm.  The problem here is that I'd need to instantiate the new DynaActionForm using the DynaActionFormClass, which the documentation expressly says is really only an internal class, implying that it might change without warning.

So, my questions to the list are:
1.  Is solution #2 workable, and is it kosher to base my implementation on the use of DynaActionFormClass?
2.  Is there a better way to get around this form problem that I'm just not seeing?

Sorry for the wordiness, but that was as concise as I could explain the problem.

Thanks very much for any insight anyone can offer.

Greg Murray

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Use of DynaActionFormClass

Posted by Ted Husted <hu...@apache.org>.
This is really a Struts USER question.

Like Christopher, I tend to have a minimum number of ActionForms with 
properties and then subclass that to add validations. This avoids having 
to replicate the same property over several classes. The validation 
portion specifies which property goes with which use case.

If you are using the validator, you don't even have to create 
subclasses, just keep specifying the same class under a different 
form-bean name. You can then create a validator form to match the 
form-bean name. (It goes by name rather than class.)

The validator ActionForm also have a built in action property which you 
could use with your lookups.

HTH, Ted.


Greg Murray wrote:
> Hello,
> 
> Currently I'm working on an Struts application that has a tree control for navigation on the left side of the page, and the rest of the page is taken up by the actual body content - no frames are used for the layout, just CSS, so it is actually one single page.  My plan was to have a JavaScript function run each time the user clicked on a link in the tree which would set the values of an HTML form (lets call it navigationForm), then submit the form.  One of the fields of the HTML form would contain the Struts action mapping (lets call the field actionMapping) which was to be invoked for the tree link.  All tree links would use the same form, and all pages would contain this form.  The action that is invoked by this form submission (call it navigationAction) would be responsible for looking up actionMapping, and forwarding on the request to the action denoted by actionMapping.  I should also note that I'm using dynamic form beans.
> 
> My problem is that many of the actions to which I want to forward are expecting their own form bean, not the one that was submitted for navigationForm.  As far as I can tell, I have two options:
> 
> 1.  Have all forms in my application use the same form bean, so I can just pass it around without having to worry about different actions using different form beans.  The problem here is that for some fields, I may want to do validation sometimes, but not all the time, but using the same form bean for all actions would require that if validation is set for a field, then it's always validated.  Also, for some reason, this solution just doesn't "feel" right to me.
> 2.  Create a DynaActionForm in navigationAction for the form related to the action to which I want to forward, and fill it with any matching properties from navigationForm.  The problem here is that I'd need to instantiate the new DynaActionForm using the DynaActionFormClass, which the documentation expressly says is really only an internal class, implying that it might change without warning.
> 
> So, my questions to the list are:
> 1.  Is solution #2 workable, and is it kosher to base my implementation on the use of DynaActionFormClass?
> 2.  Is there a better way to get around this form problem that I'm just not seeing?
> 
> Sorry for the wordiness, but that was as concise as I could explain the problem.
> 
> Thanks very much for any insight anyone can offer.
> 
> Greg Murray
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


-- 
Ted Husted,
Struts in Action <http://husted.com/struts/book.html>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Use of DynaActionFormClass

Posted by Christopher Willingham <cw...@maine.rr.com>.
You could use one non-dyna form and then define different form-beans off it
each with their validations.

----- Original Message -----
From: "Greg Murray" <GM...@edgewater.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, January 22, 2003 11:16 PM
Subject: Use of DynaActionFormClass


Hello,

Currently I'm working on an Struts application that has a tree control for
navigation on the left side of the page, and the rest of the page is taken
up by the actual body content - no frames are used for the layout, just CSS,
so it is actually one single page.  My plan was to have a JavaScript
function run each time the user clicked on a link in the tree which would
set the values of an HTML form (lets call it navigationForm), then submit
the form.  One of the fields of the HTML form would contain the Struts
action mapping (lets call the field actionMapping) which was to be invoked
for the tree link.  All tree links would use the same form, and all pages
would contain this form.  The action that is invoked by this form submission
(call it navigationAction) would be responsible for looking up
actionMapping, and forwarding on the request to the action denoted by
actionMapping.  I should also note that I'm using dynamic form beans.

My problem is that many of the actions to which I want to forward are
expecting their own form bean, not the one that was submitted for
navigationForm.  As far as I can tell, I have two options:

1.  Have all forms in my application use the same form bean, so I can just
pass it around without having to worry about different actions using
different form beans.  The problem here is that for some fields, I may want
to do validation sometimes, but not all the time, but using the same form
bean for all actions would require that if validation is set for a field,
then it's always validated.  Also, for some reason, this solution just
doesn't "feel" right to me.
2.  Create a DynaActionForm in navigationAction for the form related to the
action to which I want to forward, and fill it with any matching properties
from navigationForm.  The problem here is that I'd need to instantiate the
new DynaActionForm using the DynaActionFormClass, which the documentation
expressly says is really only an internal class, implying that it might
change without warning.

So, my questions to the list are:
1.  Is solution #2 workable, and is it kosher to base my implementation on
the use of DynaActionFormClass?
2.  Is there a better way to get around this form problem that I'm just not
seeing?

Sorry for the wordiness, but that was as concise as I could explain the
problem.

Thanks very much for any insight anyone can offer.

Greg Murray

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Use of DynaActionFormClass

Posted by Ted Husted <hu...@apache.org>.
This is really a Struts USER question.

Like Christopher, I tend to have a minimum number of ActionForms with 
properties and then subclass that to add validations. This avoids having 
to replicate the same property over several classes. The validation 
portion specifies which property goes with which use case.

If you are using the validator, you don't even have to create 
subclasses, just keep specifying the same class under a different 
form-bean name. You can then create a validator form to match the 
form-bean name. (It goes by name rather than class.)

The validator ActionForm also have a built in action property which you 
could use with your lookups.

HTH, Ted.


Greg Murray wrote:
> Hello,
> 
> Currently I'm working on an Struts application that has a tree control for navigation on the left side of the page, and the rest of the page is taken up by the actual body content - no frames are used for the layout, just CSS, so it is actually one single page.  My plan was to have a JavaScript function run each time the user clicked on a link in the tree which would set the values of an HTML form (lets call it navigationForm), then submit the form.  One of the fields of the HTML form would contain the Struts action mapping (lets call the field actionMapping) which was to be invoked for the tree link.  All tree links would use the same form, and all pages would contain this form.  The action that is invoked by this form submission (call it navigationAction) would be responsible for looking up actionMapping, and forwarding on the request to the action denoted by actionMapping.  I should also note that I'm using dynamic form beans.
> 
> My problem is that many of the actions to which I want to forward are expecting their own form bean, not the one that was submitted for navigationForm.  As far as I can tell, I have two options:
> 
> 1.  Have all forms in my application use the same form bean, so I can just pass it around without having to worry about different actions using different form beans.  The problem here is that for some fields, I may want to do validation sometimes, but not all the time, but using the same form bean for all actions would require that if validation is set for a field, then it's always validated.  Also, for some reason, this solution just doesn't "feel" right to me.
> 2.  Create a DynaActionForm in navigationAction for the form related to the action to which I want to forward, and fill it with any matching properties from navigationForm.  The problem here is that I'd need to instantiate the new DynaActionForm using the DynaActionFormClass, which the documentation expressly says is really only an internal class, implying that it might change without warning.
> 
> So, my questions to the list are:
> 1.  Is solution #2 workable, and is it kosher to base my implementation on the use of DynaActionFormClass?
> 2.  Is there a better way to get around this form problem that I'm just not seeing?
> 
> Sorry for the wordiness, but that was as concise as I could explain the problem.
> 
> Thanks very much for any insight anyone can offer.
> 
> Greg Murray
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


-- 
Ted Husted,
Struts in Action <http://husted.com/struts/book.html>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>