[Opensource] Réf. : Re: [Opensource] ActionForms and Validation
Mike Traum
mtraum at jgroup.net
Fri Jan 16 12:24:36 PST 2004
Sorry - I guess I wasn't very clear when it came to perform(). It's only
available when you use external states, which are states defined in
their own class. See the Expresso Developers Guide -
(http://www.jcorporate.com/expresso/doc/edg/edg_controllers.html#N10AFF). But, instead of using run() as the EDG says, use perform(StateForm stateForm, ControllerRequest request, ControllerResponse response)
hth,
mike
On Fri, 2004-01-16 at 04:51, Raul DAVIDOVICH wrote:
> I sent ths email one hour too early... ;-)
>
> I found the struts-config.xml part, but I extended DefaultForm instead of
> ControllerForm, otherwise I get a class cast exception
>
> Just by doing this it fills the bean correctly and I can use my get and set
> methods...
>
> what it's tricky (almost a hack) is the way to retrieve the ActionForm
> inside the controller.. here's my code:
>
>
> public class MyForm extends DefaultForm {
> private String myVar;
>
> public void setMyVar(String myVar) {
> this.myVar= myVar;
> }
>
> public String getMyVar() {
> return myVar;
> }
> ...
> }
>
> MyForm myForm = (MyForm) params.getSession
> ().getAttribute(params.getFormAttribute());
> if (myForm == null) {
> myForm = (MyForm) params.getSession
> ().getPersistentAttribute(params.getFormAttribute());
> }
>
>
> there is a getDefautForm() method in ControllerResponse which does exactly
> this, but it is protected and I didn't want to mess up with the interfaces
> (I preffer to leave that to those who know what they do ;-)
> but there is no ControllerRequest.getDefaultForm() method, which might do
> some sense. is there a cleaner way to retrieve the form inside the
> controller?
>
>
> Anyway, this is not the interesting part, since request.getParameter
> ("name") is much easier and straightforward... where this is interesting is
> to extend ValidatorForm, which uses commons-validator and then you can have
> your validation in an xml file with all the benefits that pluggable
> validators give.
>
>
>
>
> I didn't fully get what you mean by State.perform() and State.run() If I
> understand right, we could say that a State's perform method is equivalent
> to a Struts' Action's perform() method, and then from my controller I call
> MyState.perform() from inside runDoSomethingState()? or is this method
> called automatically? I'm a bit confused here :-(
>
> this is what I do usually:
>
> public class MyController
> extends DBController {
>
> public MyController() {
> super();
> State doSomething = new State("doSomething ", "MyState");
> addState(doSomething );
> ...
> }
>
> protected ControllerResponse runDoSomethingState(ControllerRequest params,
> ControllerResponse
> response) throws
> ControllerException {
> //do something
> ...
> //go to next state, usually a list or prompt state
> try {
> transition("doSomethingElse", params, response);
> }
> catch (NonHandleableException nhe) {
> errors.addError("problem after transition");
> }
> }
> ...
> }
>
>
> according to what you say, should I do:
>
>
> public class DoSomething extends State(){
> ...
> public void perform(StateForm stateForm, ControllerRequest newRequest,
> ControllerResponse newResponse)
> throws NonHandleableException, ControllerException {
> //do something
> }
> }
>
>
>
>
> import com.mycompany.myapp.states.DoSomething;
>
> public class MyController
> extends DBController {
>
> public MyController() {
> super();
>
> addState(new DoSomething() );
> ...
> }
>
> protected ControllerResponse runDoSomethingState(ControllerRequest params,
> ControllerResponse
> response) throws
> ControllerException {
>
> //and here???
>
> }
> ...
> }
>
>
>
>
> Also, what is the difference between transition("name", request, response)
> and MyState.perform(stateForm, request, response)?
>
>
>
> I'm really sorry to ask you all this on friday ;-)
>
>
> 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
>
>
> |---------+------------------------------->
> | | Mike Traum |
> | | <mtraum at jgroup.net> |
> | | Envoyé par : |
> | | opensource-admin at jco|
> | | rporate.com |
> | | |
> | | |
> | | 15/01/2004 19:22 |
> | | Veuillez répondre à |
> | | opensource |
> | | |
> |---------+------------------------------->
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
> | |
> | Pour : opensource at jcorporate.com |
> | cc : |
> | Objet : Re: [Opensource] ActionForms and Validation |
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
>
>
>
>
> 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
>
>
> 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/
> --
>
> Mike Traum
> --
> JGroup Expert
> Expresso Core Developer
> Providing support and development services - Available Now!
>
> _______________________________________________
> Opensource mailing list
> Opensource at jcorporate.com
> http://mail.jcorporate.com/mailman/listinfo/opensource
> Archives: http://mail.jcorporate.com/pipermail/opensource/
>
>
>
>
>
> _______________________________________________
> Opensource mailing list
> Opensource at jcorporate.com
> http://mail.jcorporate.com/mailman/listinfo/opensource
> Archives: http://mail.jcorporate.com/pipermail/opensource/
--
Mike Traum
--
JGroup Expert
Expresso Core Developer
Providing support and development services - Available Now!
More information about the Opensource
mailing list