You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Darren Hill <dh...@724.com> on 2002/10/01 15:18:47 UTC

RE: ValidatorForm

Hey Charles,

Thanks for the input ... what I ended up doing is creating 2 actions-mapping
for one LookupDispatchAction.  One mapping validates and the other doesn't.
So my logic remians intect within one LookupDispatchAction class, while I
can enter the flow with/without validation.  Makes sense?  My concern is
that I will now have 2 instances of one action.  Is that true?

Darren.

-----Original Message-----
From: Charles McClain [mailto:CMcClain01@ATTBI.Com]
Sent: September 27, 2002 6:31 PM
To: 'Struts Users Mailing List'
Subject: RE: ValidatorForm


Darren:

Bear in mind that I'm relatively new to Struts and don't have all the
answers, nevertheless, I'll try to point you in the right direction.  I
had exactly the same problem, with the exception that I used a simple
DispatchAction rather than a LookupDispatchAction.

I found  Struts Tip #5 on Jguru, written by Ted Husted and titled, "Use
coarse-grained ActionForms ", which emphasized the distinction between
<form-bean>s and ActionForms -- and by extension, ValidatorForms.

The essence of it was that you can create multiple <form-bean>s in your
struts-config.xml which refer to the same ValidatorForm, and that your
validation.xml <form name="xxx"> goes by the <form-bean> name.

Thus, by creating one <form-bean> for your "view" and/or "create", and
another for your "update", and by creating corresponding <form
name="xxx"> entries in validation.xml (each with its own validation
rules), you can have different validations (including a null rule set,
meaning no validation) for the same ValidatorForm.

This does, however, cause you to make some decisions about your JSPs.
Unless you want to create separate JSPs to represent the two
ValidatorForms, you have to jump through some hoops to have your JSP
figure out which formBean its being passed to it (various tags require
the formBean name).  And if you want to vary the messages, button
captions, etc., on your JSP, you then have to use a bunch of logic:equal
tags to interrogate the formBean name.

Anyway, if you do decide to go this route, Chris Bartley sent me some
code which successfully retrieves the formBean name in your JSP.  Here
it is:

<bean:define id="actionMappingForThisScreen"
name="org.apache.struts.action.mapping.instance"
type="org.apache.struts.action.ActionMapping"/>
<bean:define id="formName" name="actionMappingForThisScreen"
property="name" type="java.lang.String" /> <bean:define id="formBean"
name="<%= formName %>" type="org.apache.struts.action.ActionForm"/>

Good luck, and if you figure out how to more easily re-use the same JSP
for all your actions, please post it.


-----Original Message-----
From: Darren Hill [mailto:dhill@724.com] 
Sent: Friday, September 27, 2002 10:42 Am
To: 'Struts Users Mailing List'
Subject: ValidatorForm

ur
Question.

I have a ValidatorForm form that works with a LookupDispatchAction.

One of the the actions is 'view'.  But this populates the form after
validation.  

The question is ... how can I selectively validate a ValiatorForm ( ie.
Don't validate for 'view', 'create', but validate for 'update', etc )

Darren

--
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>

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


RE: ValidatorForm

Posted by Charles McClain <CM...@ATTBI.Com>.
Darren:

Sorry for the delay in replying -- I didn't see your message until just
now.

If I understand what you're saying, you're doing ALMOST exactly what I
did.  I would add that the reason you can do it this simply is because
your choice is binary:  validate/don't validate.

Mine was a little more complex, because in my "select" action, I wanted
the user to be able to select based on a date field, and I wanted the
date to be validated as a proper date.  Therefore, my choice wasn't
yes/no, but validate with one set of validation criteria or validate
with another set of validation criteria.  That's where defining multiple
<form-bean>s in my struts-config.xml came in; I needed to be able to
direct the action to one or the other <form-name> and its validation
rules in my validation.xml, and the <form-bean> name is the key to doing
that.

You might want to keep that part of the solution in your pocket for
future reference; even with selection criteria, although the fields
aren't required, you may want to validate them if present.

Finally:  As I said before, I am certainly no Struts expert, but
everything I've read says that Struts loads only one instance of your
Action, and I'm reasonably sure that this is based on the classname; in
other words, if two mappings reference the same canonical Action class,
only one instance is created.

Others who know more than I do are free to comment.

-----Original Message-----
From: Darren Hill [mailto:dhill@724.com] 
Sent: Tuesday, October 01, 2002 9:19 AM
To: 'Struts Users Mailing List'
Subject: RE: ValidatorForm


Hey Charles,

Thanks for the input ... what I ended up doing is creating 2
actions-mapping for one LookupDispatchAction.  One mapping validates and
the other doesn't. So my logic remians intect within one
LookupDispatchAction class, while I can enter the flow with/without
validation.  Makes sense?  My concern is that I will now have 2
instances of one action.  Is that true?

Darren.

-----Original Message-----
From: Charles McClain [mailto:CMcClain01@ATTBI.Com]
Sent: September 27, 2002 6:31 PM
To: 'Struts Users Mailing List'
Subject: RE: ValidatorForm


Darren:

Bear in mind that I'm relatively new to Struts and don't have all the
answers, nevertheless, I'll try to point you in the right direction.  I
had exactly the same problem, with the exception that I used a simple
DispatchAction rather than a LookupDispatchAction.

I found  Struts Tip #5 on Jguru, written by Ted Husted and titled, "Use
coarse-grained ActionForms ", which emphasized the distinction between
<form-bean>s and ActionForms -- and by extension, ValidatorForms.

The essence of it was that you can create multiple <form-bean>s in your
struts-config.xml which refer to the same ValidatorForm, and that your
validation.xml <form name="xxx"> goes by the <form-bean> name.

Thus, by creating one <form-bean> for your "view" and/or "create", and
another for your "update", and by creating corresponding <form
name="xxx"> entries in validation.xml (each with its own validation
rules), you can have different validations (including a null rule set,
meaning no validation) for the same ValidatorForm.

This does, however, cause you to make some decisions about your JSPs.
Unless you want to create separate JSPs to represent the two
ValidatorForms, you have to jump through some hoops to have your JSP
figure out which formBean its being passed to it (various tags require
the formBean name).  And if you want to vary the messages, button
captions, etc., on your JSP, you then have to use a bunch of logic:equal
tags to interrogate the formBean name.

Anyway, if you do decide to go this route, Chris Bartley sent me some
code which successfully retrieves the formBean name in your JSP.  Here
it is:

<bean:define id="actionMappingForThisScreen"
name="org.apache.struts.action.mapping.instance"
type="org.apache.struts.action.ActionMapping"/>
<bean:define id="formName" name="actionMappingForThisScreen"
property="name" type="java.lang.String" /> <bean:define id="formBean"
name="<%= formName %>" type="org.apache.struts.action.ActionForm"/>

Good luck, and if you figure out how to more easily re-use the same JSP
for all your actions, please post it.


-----Original Message-----
From: Darren Hill [mailto:dhill@724.com] 
Sent: Friday, September 27, 2002 10:42 Am
To: 'Struts Users Mailing List'
Subject: ValidatorForm

ur
Question.

I have a ValidatorForm form that works with a LookupDispatchAction.

One of the the actions is 'view'.  But this populates the form after
validation.  

The question is ... how can I selectively validate a ValiatorForm ( ie.
Don't validate for 'view', 'create', but validate for 'update', etc )

Darren

--
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>

--
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>