[Opensource] Réf. : Re: [Opensource] ActionForms and Validation
Raul DAVIDOVICH
R.DAVIDOVICH at caconcology.com
Tue Jan 20 00:56:53 PST 2004
Peter,
When I look in the controller's perform() method signature, it takes three
parameters: a StateForm, the ControllerRequest and the ControllerResponse.
Since StateForm is an interface, I can extend ValidatorActionForm or
ValidatorForm and implement the StateForm interface (which is empty).
ControllerForm does this by extending ActionForm
To keep it clean I created a superclass doing this and then extend this
one, which will avoid me some trouble if ever the StateForm interface
changes.
As for DefaultForm, I believe it's a way to use Struts inside Expresso
without the need to deal with ActionForms. Since it has a HashTable to hold
form data and methods to access it, it's like a dynamic form with a flavor
slightly different than Struts' DynaActionForm, which is defined in an XML
file...
By the way, since we already have Struts 1.1 incorporated in Expresso this
might be interesting.. If ever I have the time I'm going to search a bit
further here, since there is also a DynaValidatorActionForm...
I guess that having both, form definitions and validator rules pluggable in
XML files could make some people happy out there (specially lazy
programmers like me :-D )
Regards,
---------------------------------------------------
Raul Davidovich
Responsable Informatique
Cvitkovic & Associés Consultants
(33) 1 45 15 40 68
(33) 1 45 15 40 41 Fax
-------------------------------------------------------
http://www.caconcology.com
|---------+------------------------------->
| | "Peter A. Pilgrim" |
| | <peterp at xenonsoft.de|
| | mon.co.uk> |
| | Envoyé par : |
| | opensource-admin at jco|
| | rporate.com |
| | |
| | |
| | 19/01/2004 18:44 |
| | Veuillez répondre à |
| | opensource |
| | |
|---------+------------------------------->
>--------------------------------------------------------------------------------------------------------------------------------------------------|
| |
| Pour : opensource at jcorporate.com |
| cc : |
| Objet : Re: [Opensource] ActionForms and Validation |
>--------------------------------------------------------------------------------------------------------------------------------------------------|
Mike Traum wrote:
> ControllerForm extends ActionForm, so you can extend that. Then you
> define that in struts-config.xml <form-beans/> and in the 'name'
> parameter of the action mapping. To validate, I believe you override the
> validate(ActionMapping mapping, HttpServletRequest request) method of
> ActionForm. Also, I believe you should use State.perform instead of
> State.run so that you'll have access to that form bean from the state.
>
> You can also use Expresso methods, such as State.addParameter(String
> newParam, boolean required, String mask, String maskError). See
> SimpleLoginController.java for an example of this.
>
> Or, there's State.setMask() & State.checkParamMasks(). Or,
> State.autoValidate() to validate data based on a DBObject definition.
>
> request.getParameter("name") is generally how you get a parameter in
> expresso. It's getting it from the ControllerRequest. If you use a
> custom ControllerForm, you'll want to use the form bean.
>
> hth,
> mike
>
David
Oh I am not sure because ValidatorForm extends ActionForm also. All three
(including ValidationForm) are concrete classes. If you want to use the
Struts Validator possibly a new class has to be created that inherits the
abilities of ActionForm, ValidatorForm and ConcreteForm. The so called
multiple inheritance DIAMOND in C++ in Java this time, unfortunately
it does not work in Java.
You can get access to the ActionForm associated with the Action
(Expresso Controller) it s in the Controller / ControllerRequest API.
ActionForm findControllerForm( ControllerRequest request )
Once you have a reference to the ActionForm, downcast it to the
ValidatorForm type and use the form bean.
In your controller you may have to explicitly call validate() method
on the form bean inside the Expresso controller.
Expresso does not do anything special with ActionForm really.
The `DefaultForm' is just a special form bean that adds abilities
to save and load Servlet properties across Http request. (I think)
>
> On Thu, 2004-01-15 at 09:14, Raul DAVIDOVICH wrote:
>
>>Hi all,
>>
>>I'm trying to implement form validation in expresso.
>>
>>In struts, one just needs to extend ValidatorForm instead of ActionForm
and
>>the job is done.. but in expresso I'm having a real hard time to find out
>>how and where action forms are implemented so I can add this.
>>
>>Up to now I've been using request.getParameter("paramName") for
retrieving
>>the fields from the page, and now that I look further I cannott find them
>>beeing mapped to an actionform anywhere.
>>
>>I did see that there are some methods in the controller for retrieving
the
>>form from the request, but it's empty.
>>
>>
>>
>>if anyone can point me to where I can start looking it would be very
>>helpful.
>>
>>
>>Thanks in advance
>>
>>Best regards,
>>
>>---------------------------------------------------
>>Raul Davidovich
>>Responsable Informatique
>>Cvitkovic & Associés Consultants
>>
>>(33) 1 45 15 40 68
>>(33) 1 45 15 40 41 Fax
>>-------------------------------------------------------
>>http://www.caconcology.com
>>
>>
>>_______________________________________________
>>Opensource mailing list
>>Opensource at jcorporate.com
>>http://mail.jcorporate.com/mailman/listinfo/opensource
>>Archives: http://mail.jcorporate.com/pipermail/opensource/
--
Peter Pilgrim
__ _____ _____ _____
/ //__ // ___// ___/ + Serverside Java
/ /___/ // /__ / /__ + Struts
/ // ___// ___// ___/ + Expresso Committer
__/ // /__ / /__ / /__ + Independent Contractor
/___//____//____//____/ + Intrinsic Motivation
On Line Resume
||
\\===> `` http://www.xenonsoft.demon.co.uk/no-it-striker.html ''
_______________________________________________
Opensource mailing list
Opensource at jcorporate.com
http://mail.jcorporate.com/mailman/listinfo/opensource
Archives: http://mail.jcorporate.com/pipermail/opensource/
More information about the Opensource
mailing list