I thought there used to be a way in the struts-config to say "use this form name even though we are using the same class"
name="" property=""?? It would still require a different mapping...if it is true sandeep -----Original Message----- From: Paul Barry [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 11:29 AM To: Struts Users Mailing List Subject: Re: validator and dispatch action I get this exception: javax.servlet.ServletException: Configuration is frozen Adam Hardy wrote: > I mean, try changing it in the code in your action when you want to > validate, & change it back afterwards to its previous value when done. > Is that what you tried? > > String oldName = mapping.getName(); > mapping.setName("widget-edit"); > form.validate(mapping, request); > mapping.setName(oldName); > > > > On 03/31/2004 05:52 PM Paul Barry wrote: > >> The name of the action-mapping has to correspond to the name of the >> form-bean. >> >> Adam Hardy wrote: >> >>> If I really wanted to stick with your set-up, I see a way it might be >>> possible, although I have not done this myself. >>> >>> Try changing the 'name' attribute of the mapping to the validation >>> that you defined in the validation.xml, e.g. 'widget-update' or >>> 'widget-edit' and then call the validate() method. >>> >>> My main worry is that ActionMapping may not like being changed, but >>> if so, you could instantiate a new one. >>> >>> Adam >>> >>> On 03/31/2004 05:18 PM Paul Barry wrote: >>> >>>> Hello Everyone, >>>> >>>> I am using the validator and dispatch actions and I am wonder what >>>> the best way to do this is. Consider that I have the following >>>> method in a dispatch action: >>>> >>>> add - populates collections for drop-down lists, forwards to jsp >>>> page >>>> create - needs to do validation and store in database >>>> edit - needs to populate form with the data to edit, forward to >>>> jsp page >>>> update - needs to do validation and update database >>>> delete - needs to delete a record from the database >>>> >>>> You can see how the validation would be different for these actions. >>>> Let's say this is a dispatch action related to administrating >>>> users. So for add, there would be no validation, it just gets the >>>> data need to build the form. For create, there might be a password >>>> and verify password field that need to be validated, but update >>>> wouldn't have those fields. Edit and delete would have to have a >>>> parameter for the primary key of the record to edit or delete. >>>> >>>> Now I found something related at this link: >>>> >>>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction >>>> >>>> Which says to set validate to false in the struts-config.xml and >>>> then call validate method within each method of the dispatch action, >>>> like this: >>>> >>>> ActionErrors errors = new ActionErrors(); >>>> errors = form.validate(mapping, request); >>>> >>>> // Report any errors we have discovered back to the original form >>>> if (!errors.isEmpty()) { >>>> saveErrors(request, errors); >>>> return new ActionForward(mapping.getInput()); >>>> } >>>> >>>> This seems like a really good solution to me, but there is one >>>> problem. How do you call a different set of validation rules, based >>>> on which method you are in? Doesn't this need to be something like >>>> this: >>>> >>>> edit() { >>>> ActionErrors errors = new ActionErrors(); >>>> errors = form.validateEdit(mapping, request); >>>> } >>>> >>>> update() { >>>> ActionErrors errors = new ActionErrors(); >>>> errors = form.validateUpdate(mapping, request); >>>> } >>>> >>>> Because the rules for validating edit and update are different. You >>>> could define different action-mappings in your struts config for >>>> each dispatch method, and then a form in your validation.xml for >>>> each action-mapping, where the form name is the same as the path >>>> property of the action-mapping, but doesn't this defeat the purpose >>>> of the dispatch action? Why not just have separate actions at that >>>> point? I think the answer is to just not use the dispatch action >>>> with the validator, but I wanted to know if others had found a way >>>> to do it. >>>> >>>> --------------------------------------------------------------------- >>>> 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]