You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mulligan, Scott H" <sc...@eds.com> on 2006/05/04 15:40:32 UTC

Conditional validation

I just started playing with the commons-validator and came across a
problem with how I have my Struts application structured. I am using
dispatch actions that have "load" and "save" methods. In the "load" I
retrieve the reference data needed to build the page and then forward to
the jsp page. In the "save" method I process the form data.

My problem is that the validation is defined at the action level in the
struts-config file. Therefore, my validation fails before I even have a
chance to render the page. Do I need to separate the "load" and "save"
methods into different actions or is there a better way to handle this?

Thanks in advance for any advice you can provide.


Scott Mulligan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Conditional validation

Posted by Michael Jouravlev <jm...@gmail.com>.
> On May 4, 2006, at 11:27 AM, Adam Hardy wrote:
>
> > In the last couple of days someone said that they separated the two
> > flows using GET and POST - or at least I thought so.
> >
> > It sounded interesting but on looking at the struts-config DTD,
> > there seems no way to do this.
> >
> > I can't find the thread in the archive now. Did I misread that
> > previous posting?

I am doing this in Struts Dialogs 1.x [1]. Here is, for example, the
snippet from the config file of one of the active users of Struts
Dialogs (he uses Tiles as well):

<component path = "/userCenter"
           type = "com.acme.action.UserCenterAction"
           form = "userCenterForm"
           view = "page.userCenter">
  <event name = "DIALOG-EVENT-CHANGE" handler = "onUpdate"/>
  <event name = "DIALOG-EVENT-DELETE" handler = "onDelete"/>
  <event name = "DIALOG-EVENT-SHOW-ORDERS" handler = "onShowOrders"/>
  <event name = "DIALOG-EVENT-SHOW-PRICE-LIST" handler = "onShowPriceList"/>
  <event name = "DIALOG-EVENT-SHOW-ORDER-DETAILS" handler =
"onShowOrderDetails"/>

  <transfer name = "SHOW-ORDERS" path = "/showOrders.do"/>
  <transfer name = "SHOW-PRICE-LIST" path = "/showPriceList.do"/>
  <transfer name = "SHOW-ORDER-DETAILS" path = "/showOrderDetails.do"/>

  <render name = "ON-CC-DIALOG" path = "page.CCDialog"/>
  <render name = "ON-GET-DELIVERY-CONFIRMATION" path =
"/jsp/deliveryConfirmation.jsp"/>
</component>

If event is found, method handler is called. If POST and event is not
found, execute() is called. If GET and event is not found, the
location in the "view" attribute is called.

<event> element selects method handler for an event.
<transfer> is basically <forward ... redirect="true">, used to
transfer control to another webresource.
<render> is basically <forward ... redirect="false">, used to render a page.

At present point, I am not sure that differentiating by POST/GET is
the best, because it does not allow to sent event via link.
EventActionDispatcher in Struts 1.2.9 does not differentiate by
POST/GET.

On 5/4/06, James Mitchell <jm...@apache.org> wrote:
> I don't think that would be the best solution (but that's just my 2c)
> -- I would opt for the declarative approach, with wildcards for
> "verbosely declarative simplicity" -- now there's an oxymoron for ya :)

Is the mapping above decrarative enough for ya? ;-)

[1] http://struts.sourceforge.net/strutsdialogs/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Conditional validation

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Could be easily overlooked, I agree - but is it even possible? I don't 
think it is possible to configure on the action mapping level.

James Mitchell on 04/05/06 17:43, wrote:
> I don't think that would be the best solution (but that's just my 2c) -- 
> I would opt for the declarative approach, with wildcards for "verbosely 
> declarative simplicity" -- now there's an oxymoron for ya :)
> 
> -- 
> James Mitchell
> 
> 
> 
> 
> On May 4, 2006, at 11:27 AM, Adam Hardy wrote:
> 
>> In the last couple of days someone said that they separated the two 
>> flows using GET and POST - or at least I thought so.
>>
>> It sounded interesting but on looking at the struts-config DTD, there 
>> seems no way to do this.
>>
>> I can't find the thread in the archive now. Did I misread that 
>> previous posting?
>>
>>
>> Adam
>>
>>
>> James Mitchell on 04/05/06 15:38, wrote:
>>> The newest version of the Struts mailreader sample app shows a best 
>>> practices approach to just what you describe.
>>> Take a look at that and see if you might be able to do the same.  
>>> (Specifically, look at the paths for Edit* and Save*)
>>> HTH
>>> --James Mitchell
>>> On May 4, 2006, at 9:40 AM, Mulligan, Scott H wrote:
>>>> I just started playing with the commons-validator and came across a
>>>> problem with how I have my Struts application structured. I am using
>>>> dispatch actions that have "load" and "save" methods. In the "load" I
>>>> retrieve the reference data needed to build the page and then 
>>>> forward to
>>>> the jsp page. In the "save" method I process the form data.
>>>>
>>>> My problem is that the validation is defined at the action level in the
>>>> struts-config file. Therefore, my validation fails before I even have a
>>>> chance to render the page. Do I need to separate the "load" and "save"
>>>> methods into different actions or is there a better way to handle this?



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Conditional validation

Posted by James Mitchell <jm...@apache.org>.
I don't think that would be the best solution (but that's just my 2c)  
-- I would opt for the declarative approach, with wildcards for  
"verbosely declarative simplicity" -- now there's an oxymoron for ya :)

--
James Mitchell




On May 4, 2006, at 11:27 AM, Adam Hardy wrote:

> In the last couple of days someone said that they separated the two  
> flows using GET and POST - or at least I thought so.
>
> It sounded interesting but on looking at the struts-config DTD,  
> there seems no way to do this.
>
> I can't find the thread in the archive now. Did I misread that  
> previous posting?
>
>
> Adam
>
>
> James Mitchell on 04/05/06 15:38, wrote:
>> The newest version of the Struts mailreader sample app shows a  
>> best practices approach to just what you describe.
>> Take a look at that and see if you might be able to do the same.   
>> (Specifically, look at the paths for Edit* and Save*)
>> HTH
>> -- 
>> James Mitchell
>> On May 4, 2006, at 9:40 AM, Mulligan, Scott H wrote:
>>> I just started playing with the commons-validator and came across a
>>> problem with how I have my Struts application structured. I am using
>>> dispatch actions that have "load" and "save" methods. In the  
>>> "load" I
>>> retrieve the reference data needed to build the page and then  
>>> forward to
>>> the jsp page. In the "save" method I process the form data.
>>>
>>> My problem is that the validation is defined at the action level  
>>> in the
>>> struts-config file. Therefore, my validation fails before I even  
>>> have a
>>> chance to render the page. Do I need to separate the "load" and  
>>> "save"
>>> methods into different actions or is there a better way to handle  
>>> this?
>>>
>>> Thanks in advance for any advice you can provide.
>>>
>>>
>>> Scott Mulligan
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Conditional validation

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Dave Newton on 04/05/06 19:13, wrote:
> Adam Hardy wrote:
>> In the last couple of days someone said that they separated the two
>> flows using GET and POST - or at least I thought so.
>>
>> It sounded interesting but on looking at the struts-config DTD, there
>> seems no way to do this.
>>
>> I can't find the thread in the archive now. Did I misread that
>> previous posting?
> 
> Nope, but you might have misunderstood: it's about as far from magic as
> one can get.
> 
> Everything was handled with a base Action pseudocoded (very) roughly as
> follows. Mind you, this isn't how I would do things now, but it served
> its purpose for a pretty darn long time (just like Struts! :)
> 
> execute
>     if isError(handleSetup(request_, event_))
>         return setupError
>     if isPost(request)
>         return executeGet
>     if isError(validateForm)
>         return validationError
>     return executePost
> 
> There were various over-ridables for setting up the form differently (if
> necessary) for GET/POST, blah blah blah.

OK, I see, you coded it yourself.

I wish that sort of mechanism had gone into the Struts ActionServlet.

In your case you had to recode something from the servlet container 
level that struts had smothered - not a good situation.

I can see though that some might disagree if they are seeking to 
encapsulate and hide the HTTP layer. However I think that web 
programmers should be intimately aware of the HTTP layer if they intend 
to create a robust webapp.


rgds
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Conditional validation

Posted by Dave Newton <ne...@pingsite.com>.
Adam Hardy wrote:
> In the last couple of days someone said that they separated the two
> flows using GET and POST - or at least I thought so.
>
> It sounded interesting but on looking at the struts-config DTD, there
> seems no way to do this.
>
> I can't find the thread in the archive now. Did I misread that
> previous posting?

Nope, but you might have misunderstood: it's about as far from magic as
one can get.

Everything was handled with a base Action pseudocoded (very) roughly as
follows. Mind you, this isn't how I would do things now, but it served
its purpose for a pretty darn long time (just like Struts! :)

execute
    if isError(handleSetup(request_, event_))
        return setupError
    if isPost(request)
        return executeGet
    if isError(validateForm)
        return validationError
    return executePost

There were various over-ridables for setting up the form differently (if
necessary) for GET/POST, blah blah blah.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Conditional validation

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
In the last couple of days someone said that they separated the two 
flows using GET and POST - or at least I thought so.

It sounded interesting but on looking at the struts-config DTD, there 
seems no way to do this.

I can't find the thread in the archive now. Did I misread that previous 
posting?


Adam


James Mitchell on 04/05/06 15:38, wrote:
> The newest version of the Struts mailreader sample app shows a best 
> practices approach to just what you describe.
> 
> Take a look at that and see if you might be able to do the same.  
> (Specifically, look at the paths for Edit* and Save*)
> 
> HTH
> 
> -- 
> James Mitchell
> 
> 
> 
> 
> On May 4, 2006, at 9:40 AM, Mulligan, Scott H wrote:
> 
>> I just started playing with the commons-validator and came across a
>> problem with how I have my Struts application structured. I am using
>> dispatch actions that have "load" and "save" methods. In the "load" I
>> retrieve the reference data needed to build the page and then forward to
>> the jsp page. In the "save" method I process the form data.
>>
>> My problem is that the validation is defined at the action level in the
>> struts-config file. Therefore, my validation fails before I even have a
>> chance to render the page. Do I need to separate the "load" and "save"
>> methods into different actions or is there a better way to handle this?
>>
>> Thanks in advance for any advice you can provide.
>>
>>
>> Scott Mulligan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Conditional validation

Posted by Jakub Milkiewicz <jm...@gmail.com>.
Hi
Can you point it where i can find it
Thanks

2006/5/4, James Mitchell <jm...@apache.org>:
>
> The newest version of the Struts mailreader sample app shows a best
> practices approach to just what you describe.
>
> Take a look at that and see if you might be able to do the same.
> (Specifically, look at the paths for Edit* and Save*)
>
> HTH
>
> --
> James Mitchell
>
>
>
>
> On May 4, 2006, at 9:40 AM, Mulligan, Scott H wrote:
>
> > I just started playing with the commons-validator and came across a
> > problem with how I have my Struts application structured. I am using
> > dispatch actions that have "load" and "save" methods. In the "load" I
> > retrieve the reference data needed to build the page and then
> > forward to
> > the jsp page. In the "save" method I process the form data.
> >
> > My problem is that the validation is defined at the action level in
> > the
> > struts-config file. Therefore, my validation fails before I even
> > have a
> > chance to render the page. Do I need to separate the "load" and "save"
> > methods into different actions or is there a better way to handle
> > this?
> >
> > Thanks in advance for any advice you can provide.
> >
> >
> > Scott Mulligan
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Conditional validation

Posted by James Mitchell <jm...@apache.org>.
The newest version of the Struts mailreader sample app shows a best  
practices approach to just what you describe.

Take a look at that and see if you might be able to do the same.   
(Specifically, look at the paths for Edit* and Save*)

HTH

--
James Mitchell




On May 4, 2006, at 9:40 AM, Mulligan, Scott H wrote:

> I just started playing with the commons-validator and came across a
> problem with how I have my Struts application structured. I am using
> dispatch actions that have "load" and "save" methods. In the "load" I
> retrieve the reference data needed to build the page and then  
> forward to
> the jsp page. In the "save" method I process the form data.
>
> My problem is that the validation is defined at the action level in  
> the
> struts-config file. Therefore, my validation fails before I even  
> have a
> chance to render the page. Do I need to separate the "load" and "save"
> methods into different actions or is there a better way to handle  
> this?
>
> Thanks in advance for any advice you can provide.
>
>
> Scott Mulligan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org