Re: Struts, Tiles and the Validator
Martin Ravell wrote: > So you call validate from within the Action? > Yes. > Do you then have to forward back to the original page if you have errors? > Yes. One nice thing about doing validation "manually" (see below) is that I can add further validation that would be irritating to do in validation.xml (say by writing a custom validator) or validation that requires trips to the DB, etc. I really only use validation.xml for the easy stuff, mostly just the stuff that comes with it, with an occasional custom validator. > Have you tried having validate="true" in your action? > Yes, but that can cause issues, like if your input form needs setup before display, etc. > Could I take a look at an example out of one of your Actions? > No, but I've appended some pseudo-code, although it might not help. > Thanks for showing me that the input can point to a tiles definition. I've > been trying this without luck. Perhaps I have something in my configuration > somewhere which is not setup 100% correctly. > I'm not sure where it could get messed up; it's pretty straight-forward. So, here's (very) psuedo-code for one version of an Action class hierarchy. Basically all I'd do in my subclasses is implement something in executePost. Currently I'm not even doing much there, it's just marshalling stuff from the form into a bean and calling stuff on the business and ORM side of things. There was a pretty good thread some time ago with Frank Zammetti regarding ways to never have to change your code inside of your action classes through various means that is probably worth looking up if you're interested in such things. == BASE ACTION CLASS == // Call subclass or default impls public ActionForward execute(...) { if (!prepForAction()) handleError(); return executeGet() if isGetRequest(); return getInputForward() if validationErrors(); return executePost(); } // Default impl goes to input page public executeGet() { return getInputForward(); } // Default impl calls form's validation method and does the right thing public validationErrors() { errs = form.validate(); if (haveErrs) saveErrors(); } == SUBCLASS EXAMPLE == public prepForAction() { request.setAttribute("listOfSomething", getListOfSomething()); } public executePost() { // Do stuff relating to form post } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Struts, Tiles and the Validator
> >I'm not using extension mapping so I'm not sure about this, but have you >tried input="/activate" instead of input="/activate.do"? It's certainly >possible for the input attribute to point to an action rather than a JSP >or Tiles def. > >L. Part of the problem is that my actions typically extend DispatchAction and therefore need a parameter passed as well. Regards Marty - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Struts, Tiles and the Validator
>I call validate manually, but since I'm using DynaValidatorActionForms >I'm using the validation defs from the validator XML config file. This >is quite a bit more flexible to boot. > >In any case, I use tiles and validator together all the time so I'm not >quite sure where your problem lies: > >type="com.pingsite.actions.NiceAction" >name="niceBean" >input="page.NiceAction" >scope="request" >validate="false" >roles="Role1,Role2"> > > redirect="true"/> > > > > > > > > >etc. > >Dave One of the main reasons I have for heading down this path was to use generic validation defs. This alone should cut out a heap of tedious code. So you call validate from within the Action? Do you then have to forward back to the original page if you have errors? Have you tried having validate="true" in your action? Could I take a look at an example out of one of your Actions? Thanks for showing me that the input can point to a tiles definition. I've been trying this without luck. Perhaps I have something in my configuration somewhere which is not setup 100% correctly. Regards Marty - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts, Tiles and the Validator
Martin Ravell wrote: Thanks for the post Vasumathi I don't quite follow what you are saying however. Since I use Tiles with my struts the page that contains my form is produced by an Action executing (I use an Action which extends DispatchAction). If the Validation fails (there are fields that do not meet their validations rules) I need to go back to what is in the 'input' option of the action element. As far as I can work out this needs to be a jsp. It cannot however be a jsp since it is my Action that ties me into a tiles definition which produces the form. I've tried putting thigns like '/activate.do?method=init' into the input option of the action element but this refuses to work. I'm not using extension mapping so I'm not sure about this, but have you tried input="/activate" instead of input="/activate.do"? It's certainly possible for the input attribute to point to an action rather than a JSP or Tiles def. L. Any ideas? Regards Marty -Original Message- From: Vasumathi [mailto:[EMAIL PROTECTED] Sent: Tuesday, 24 January 2006 4:44 PM To: Struts Users Mailing List Subject: Re: Struts, Tiles and the Validator Hi you try like this in struts_config.xml and tiles_sam.xml file. type="controller.admin.action.SampleAction" validate="true" input="/admin/icf/sample.jsp"> in tiles for this sample.jsp this may help u - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts, Tiles and the Validator
Martin Ravell wrote: > This basically means I am not using the Validator. Sticking everything in > the Action negates all the advantages of getting this stuff unbound. > I don' really see it that way. I call validate manually, but since I'm using DynaValidatorActionForms I'm using the validation defs from the validator XML config file. This is quite a bit more flexible to boot. In any case, I use tiles and validator together all the time so I'm not quite sure where your problem lies: etc. Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Struts, Tiles and the Validator
Great minds think alike or Fools seldom differ I've already gone down almost exactly this track and while it does work I am currently using the deprecated saveErrors() method. Will give your request.setAttribute() method a try as well. This basically means I am not using the Validator. Sticking everything in the Action negates all the advantages of getting this stuff unbound. Ohh well, maybe I can't have everything. At the moment I'll settle for something that works. Regards Marty -Original Message- From: Vasumathi [mailto:[EMAIL PROTECTED] Sent: Tuesday, 24 January 2006 9:42 PM To: Struts Users Mailing List Subject: RE: Struts, Tiles and the Validator dont change anything in struts_config.xml. write your validation in action itself instead of writing in validation.xml for your Form. like, if(id == null){ request.setAttribute("error","errors.id.notexist"); } try this, let me the result pls. with regards vasu Quoting Martin Ravell <[EMAIL PROTECTED]>: > Thanks for the post Vasumathi > > I don't quite follow what you are saying however. > > Since I use Tiles with my struts the page that contains my form is produced > by an Action executing (I use an Action which extends DispatchAction). > > If the Validation fails (there are fields that do not meet their > validations > rules) I need to go back to what is in the 'input' option of the action > element. > > As far as I can work out this needs to be a jsp. > > It cannot however be a jsp since it is my Action that ties me into a tiles > definition which produces the form. > > I've tried putting thigns like '/activate.do?method=init' into the input > option of the action element but this refuses to work. > > Any ideas? > > > Regards > Marty > > > -----Original Message----- > From: Vasumathi [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 24 January 2006 4:44 PM > To: Struts Users Mailing List > Subject: Re: Struts, Tiles and the Validator > > Hi > you try like this in struts_config.xml and tiles_sam.xml file. > > type="controller.admin.action.SampleAction" validate="true" > input="/admin/icf/sample.jsp"> > > > > in tiles for this sample.jsp > > > > > > > > > > this may help u > > > > > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Struts, Tiles and the Validator
dont change anything in struts_config.xml. write your validation in action itself instead of writing in validation.xml for your Form. like, if(id == null){ request.setAttribute("error","errors.id.notexist"); } try this, let me the result pls. with regards vasu Quoting Martin Ravell <[EMAIL PROTECTED]>: > Thanks for the post Vasumathi > > I don't quite follow what you are saying however. > > Since I use Tiles with my struts the page that contains my form is produced > by an Action executing (I use an Action which extends DispatchAction). > > If the Validation fails (there are fields that do not meet their > validations > rules) I need to go back to what is in the 'input' option of the action > element. > > As far as I can work out this needs to be a jsp. > > It cannot however be a jsp since it is my Action that ties me into a tiles > definition which produces the form. > > I've tried putting thigns like '/activate.do?method=init' into the input > option of the action element but this refuses to work. > > Any ideas? > > > Regards > Marty > > > -Original Message- > From: Vasumathi [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 24 January 2006 4:44 PM > To: Struts Users Mailing List > Subject: Re: Struts, Tiles and the Validator > > Hi > you try like this in struts_config.xml and tiles_sam.xml file. > > type="controller.admin.action.SampleAction" validate="true" > input="/admin/icf/sample.jsp"> > > > > in tiles for this sample.jsp > > > > > > > > > > this may help u > > > > > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Struts, Tiles and the Validator
Thanks for the post Vasumathi I don't quite follow what you are saying however. Since I use Tiles with my struts the page that contains my form is produced by an Action executing (I use an Action which extends DispatchAction). If the Validation fails (there are fields that do not meet their validations rules) I need to go back to what is in the 'input' option of the action element. As far as I can work out this needs to be a jsp. It cannot however be a jsp since it is my Action that ties me into a tiles definition which produces the form. I've tried putting thigns like '/activate.do?method=init' into the input option of the action element but this refuses to work. Any ideas? Regards Marty -Original Message- From: Vasumathi [mailto:[EMAIL PROTECTED] Sent: Tuesday, 24 January 2006 4:44 PM To: Struts Users Mailing List Subject: Re: Struts, Tiles and the Validator Hi you try like this in struts_config.xml and tiles_sam.xml file. in tiles for this sample.jsp this may help u - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts, Tiles and the Validator
Hi you try like this in struts_config.xml and tiles_sam.xml file. in tiles for this sample.jsp this may help u Quoting Martin Ravell <[EMAIL PROTECTED]>: > Say I have an app that uses Struts and Tiles and I am trying to get the > Validator plugin to play nicely. > > As I understand it the 'input' option of an action element in > struts-config.xml is used when a validation fails. i.e. if a validation > fails we are redirected to whatever is in the input option rather than > getting sent to the Action. > > This is what we want right? Only actually go to the Action if the fields > pass their validations. > > I've looked at various Tiles tutorials and even more Validator tutorials > but > I can't seem to work out what I need to do to get these two to work in > conjunction with each other. > > This 'input' value for the action element cannot be straight to a .jsp > since > I am using Tiles. If a validation fails we need to get Tiles to reconstruct > the page (with it's header, menu etc) and display the messages from the > failed validation. > > If I put in the name of a definition in my tiles-defs.xml into the 'input' > option and purposefully fail validation on one or more fields I just get a > blank page and a record in my log saying: > > Validation failed, returning to 'activate_init' > > (activate_init in this case was the name of my definition in > tiles-defs.xml) > > > I know that the validator is being invoked because if I enter values that > will pass the validation tests I do go through to the Action. > > > Can someone give me an idea of what the action element should look like? > More specifically what should go into the input option if I am using Tiles? > > I've tried creating an action definition specifically for use in the > 'input' > option e.g. > > > > Then putting "/act.do" into the input still gives me a blank page. > > > Damn I am confused. Have been looking so hard at this that I cannot see it. > Can someone help with an explanation of how Struts and Tiles and the > Validator can work happily together? > > > Regards > Marty > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]