Re: Design question about ActionForm's validate method

2002-02-08 Thread Jonathan Gibbons


Hi Ted,

I was implementing this and noticed a problem in V1.0.1

1.  Struts config is as below







2. The code for AdminSessionViewSrchAction does the following:

AdminSessionViewForm form_obj = 
sess_bean.maintainStrutSearchAdminSessionViewForm(params);
request.setAttribute("adminsessionviewForm", form_obj);
// Now want to forward to the correct jsp, including the params
return (mapping.findForward("display_row"));

3. OK, so we are seeing an action setting up the form for the following page, and that 
following page is being accessed via an ForwardAction, validate false.

Well, it doesn't work.   The prepopulated form does not display, all the fields have 
been reset to nothing.

4.  Is this a bug, or is this a problem with my config?  If display_row simlpy 
redirects to the jsp page directly then it works fine.

Jonathan




 Message History 



From: Ted Husted <[EMAIL PROTECTED]> on 06/02/2002 18:47 EST

Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED]>

To:   Struts Users Mailing List <[EMAIL PROTECTED]>
cc:
Subject:  Re: Design question about ActionForm's validate method


In 1.0.x, it is often suggested that each link at least be represented
by an ActionForward. This centralizes control over the hyperlinks in the
Struts Config, which yields a number of benefits.

In Struts 1.1, now the Nightly Build, support has been added for
multiple Struts configuration files. In order for this feature to work,
any request for a presentation page that uses elements from the
configuration file (ActionForms, forwards, mappings) must be routed
through the controller. This allows the controller to make the
appropriate configuration available for a given page.

This is becoming a common pattern, since the Velocity support, and I
believe the X2 servlet, also need you to do the same thing for the same
reason. The controller needs to touch the request to prepare it for the
presentation layer.

Many other features in advanced applications, including security,
logging, and screen definitins, are easier to implement when everything
passes through the controller.

In a strict MVC implementation, the controller is responsible for
interacting with the user. It then follows that all requests from the
user should flow through the controller. Some of us had been counting
the ActionForwards as flowing through the controller, but as the
framework expands, and more services are being plugged in, passing the
actual request through the controller becomes more and more desirable,
until it's really not worth making the occasional exception any more.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/


Alex Paransky wrote:
>
> So do you mean, all pages go through the Action?  Even those which are not
> forms and for display purposes only?  Could you shed some light as to why
> this is preferred?
>
> Thanks.
>
> -AP_
> http://www.alexparansky.com
>
> -Original Message-
> From: Ted Husted [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 05, 2002 2:02 PM
> To: Struts Users Mailing List
> Subject: Re: Design question about ActionForm's validate method
>
> The best practice now is to use ActionMappings for everything, so that
> the reqeust passes through the controller.
>
> This buys you several important capabilities that become important as
> applications grow. Not the least of which is the new support for
> multiple applications in the Nightly Build.
>
> The ActionMapping has a validate property that you can use to turn off
> validation when the mapping is used to initialize a new form. So,
> typically, you will have an ActionMapping for each circumstance.
>
>  path="/item/Add"
> type="org.apache.struts.actions.ForwardAction"
> parameter="/pages/item/Form.jsp">
> name="itemForm"
> scope="request"
> validate="false">
> 
>
> path="/item/Store"
> type="org.apache.gavel.item.http.Store"
> name="itemForm"
> scope="request"
> validate="true"
> input="/pages/item/Form.jsp"">
>  name="continue"
> path="/do/donor/Detail"/>
> 
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Java Web Development with Struts.
> -- Tel +1 585 737

RE: Design question about ActionForm's validate method

2002-02-07 Thread Alex Paransky

Well, I went ahead and changed my code, so that all .jsp pages are accessed
through actions.  I am running into a particular problem and was hoping that
someone could help me out.

I have a page called "foo.jsp", I wrap it with a ForwardAction like this:



I also have a tag, which allows me to create a bean containing the current
URL (I use it for returnTo parameter to many forms).  In this tag, I use
request.getServletPath().  The problem, is that while the user's browser
reads "foo.do", my tag returns foo.jsp.  So when I use the resulting value
later, I am returned to foo.jsp and not foo.do.

Is there a way to fix this problem?

Thanks.
-AP_
http://www.alexparansky.com

-Original Message-
From: Sean Willson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 07, 2002 11:23 AM
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method


RE: Design question about ActionForm's validate method
The process we followed is very simular to what Ted suggested but depends on
how you are approaching the construction of your actions. If you have the
ability to write a collection of objects that handle storing and retreiving
data irreguardless of the data you might map it like this:

/do/store/address
/do/load/address
/do/load/user
etc ...

If however you want to segment it out as to what you are working on and then
the action you are performing on that thing you would merely reverse it to
this:

/do/address/load
/do/address/save
/do/address/delete

No what have we done in practice is a combination of those two. For one
project we were able to encapsulate the loading, sending, and saving type of
actions into one an action for each and thus the namespace we defined for
this was simular to the top  this namespace was a bit easier to manage
but obviously the actions themselves were either larger or the beans they
used were larger, for us the actions. For another larger project we went for
breadth as we didn't have much that was reusable and therefor had many many
actions all acting on the data but in different unique ways. Therefor the
namespace we defined was more in line with suggestion two.

One standard we have imposed which I think works and looks much cleaner is
the /do/* instead of *.do. It requires less explaining to people on what is
a .do file ... hehhe ... and it has less legacy implications like.cgi and
.pl have ... a namespace is nothing more then a mapping to a resource,
therefor extension has less importance. Anyhow ... we use /do/* for all
actions.

Not sure if any of this has helped ... ;)

Sean


- Original Message -
From: Alex Paransky
To: Struts Users Mailing List
Cc: [EMAIL PROTECTED]
Sent: Wednesday, February 06, 2002 11:53 PM
Subject: RE: Design question about ActionForm's validate method


Ok, I understand how forcing all requests through the controller is a good
thing.  Now, I have various types of pages:
Forms - http://www.alexparansky.com


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-07 Thread Sean Willson

RE: Design question about ActionForm's validate method
The process we followed is very simular to what Ted suggested but depends on
how you are approaching the construction of your actions. If you have the
ability to write a collection of objects that handle storing and retreiving
data irreguardless of the data you might map it like this:

/do/store/address
/do/load/address
/do/load/user
etc ...

If however you want to segment it out as to what you are working on and then
the action you are performing on that thing you would merely reverse it to
this:

/do/address/load
/do/address/save
/do/address/delete

No what have we done in practice is a combination of those two. For one
project we were able to encapsulate the loading, sending, and saving type of
actions into one an action for each and thus the namespace we defined for
this was simular to the top  this namespace was a bit easier to manage
but obviously the actions themselves were either larger or the beans they
used were larger, for us the actions. For another larger project we went for
breadth as we didn't have much that was reusable and therefor had many many
actions all acting on the data but in different unique ways. Therefor the
namespace we defined was more in line with suggestion two.

One standard we have imposed which I think works and looks much cleaner is
the /do/* instead of *.do. It requires less explaining to people on what is
a .do file ... hehhe ... and it has less legacy implications like.cgi and
.pl have ... a namespace is nothing more then a mapping to a resource,
therefor extension has less importance. Anyhow ... we use /do/* for all
actions.

Not sure if any of this has helped ... ;)

Sean


- Original Message -
From: Alex Paransky
To: Struts Users Mailing List
Cc: [EMAIL PROTECTED]
Sent: Wednesday, February 06, 2002 11:53 PM
Subject: RE: Design question about ActionForm's validate method


Ok, I understand how forcing all requests through the controller is a good
thing.  Now, I have various types of pages:
Forms - http://www.alexparansky.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-07 Thread Ted Husted

Unfortunately, we don't have free reign on conventions, and are
restricted to the patterns that the container will match. The container
gets the request first, and then passes it along to Struts. For the best
compatibility, a single, very simple pattern is best. 

One way to think about it is that the Actions are your applications API,
its command set. They represent everything that your application knows
how to do. One thing it does is display a form for adding a new record.
Another thing might to display a page summarizing the entered data, or a
page for editing the data. 

Displaying a form is sometimes a simple process. Often times, it is not,
since dropdown boxes must be populated, security parmeters might need to
be checked, other customizations might need to be performed. In
practice, there is sometimes a lot to do even to simply display a data
entry form. 

I tend to break my applications into modules, which sometimes correspond
to the major tables in a database, or at least the major databases
views. So I would tend to represent the URIs you mentioned as 

/adddress/Form.do
/address/Store.do
/address/View.do

or 

/do/adddress/Form
/do/address/Store
/do/address/View

-Ted.


Alex Paransky wrote:
> 
> Ok, I understand how forcing all requests through the controller is a good
> thing.  Now, I have various types of pages:
> 
> Forms -  Actions - .do action of the form
> View - basic .jsp page to view and link to a form for further edit
> 
> Is there a naming convention that you found works for you?  Since, I am
> using .do extension for everything, it seems like I have URL's which look
> like this:
> 
> AddressForm.do
> AddressSaveAction.do
> AddressView.do
> 
> I think it would be nice to have:
> 
> Address.form
> AddressSave.action
> Address.view
> 
> Or something like this.  The .do extension makes me think of "action" and I
> don't see a form or a view as an action.  I could always map *.view and
> *.form to execute the servlet as well, but then Address.form and
> Address.view are ambiguous.
> 
> Any suggestion on naming conventions?
> 
> Thanks.
> -AP_
> http://www.alexparansky.com
> 
> -Original Message-
> From: Ted Husted [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 06, 2002 3:47 PM
> To: Struts Users Mailing List
> Subject: Re: Design question about ActionForm's validate method
> 
> In 1.0.x, it is often suggested that each link at least be represented
> by an ActionForward. This centralizes control over the hyperlinks in the
> Struts Config, which yields a number of benefits.
> 
> In Struts 1.1, now the Nightly Build, support has been added for
> multiple Struts configuration files. In order for this feature to work,
> any request for a presentation page that uses elements from the
> configuration file (ActionForms, forwards, mappings) must be routed
> through the controller. This allows the controller to make the
> appropriate configuration available for a given page.
> 
> This is becoming a common pattern, since the Velocity support, and I
> believe the X2 servlet, also need you to do the same thing for the same
> reason. The controller needs to touch the request to prepare it for the
> presentation layer.
> 
> Many other features in advanced applications, including security,
> logging, and screen definitins, are easier to implement when everything
> passes through the controller.
> 
> In a strict MVC implementation, the controller is responsible for
> interacting with the user. It then follows that all requests from the
> user should flow through the controller. Some of us had been counting
> the ActionForwards as flowing through the controller, but as the
> framework expands, and more services are being plugged in, passing the
> actual request through the controller becomes more and more desirable,
> until it's really not worth making the occasional exception any more.
> 
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Java Web Development with Struts.
> -- Tel +1 585 737-3463.
> -- Web http://www.husted.com/struts/
> 
> Alex Paransky wrote:
> >
> > So do you mean, all pages go through the Action?  Even those which are not
> > forms and for display purposes only?  Could you shed some light as to why
> > this is preferred?
> >
> > Thanks.
> >
> > -AP_
> > http://www.alexparansky.com
> >
> > -Original Message-
> > From: Ted Husted [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, February 05, 2002 2:02 PM
> > To: Struts Users Mailing List
> > Subject: Re: Design question about ActionForm's validate method
> >
> > The best practice now is to use ActionMappings for everything, so that
> > the reqeust 

RE: Design question about ActionForm's validate method

2002-02-06 Thread Alex Paransky

Ok, I understand how forcing all requests through the controller is a good
thing.  Now, I have various types of pages:

Forms - http://www.alexparansky.com


-Original Message-
From: Ted Husted [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 06, 2002 3:47 PM
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method


In 1.0.x, it is often suggested that each link at least be represented
by an ActionForward. This centralizes control over the hyperlinks in the
Struts Config, which yields a number of benefits.

In Struts 1.1, now the Nightly Build, support has been added for
multiple Struts configuration files. In order for this feature to work,
any request for a presentation page that uses elements from the
configuration file (ActionForms, forwards, mappings) must be routed
through the controller. This allows the controller to make the
appropriate configuration available for a given page.

This is becoming a common pattern, since the Velocity support, and I
believe the X2 servlet, also need you to do the same thing for the same
reason. The controller needs to touch the request to prepare it for the
presentation layer.

Many other features in advanced applications, including security,
logging, and screen definitins, are easier to implement when everything
passes through the controller.

In a strict MVC implementation, the controller is responsible for
interacting with the user. It then follows that all requests from the
user should flow through the controller. Some of us had been counting
the ActionForwards as flowing through the controller, but as the
framework expands, and more services are being plugged in, passing the
actual request through the controller becomes more and more desirable,
until it's really not worth making the occasional exception any more.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/


Alex Paransky wrote:
>
> So do you mean, all pages go through the Action?  Even those which are not
> forms and for display purposes only?  Could you shed some light as to why
> this is preferred?
>
> Thanks.
>
> -AP_
> http://www.alexparansky.com
>
> -Original Message-
> From: Ted Husted [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 05, 2002 2:02 PM
> To: Struts Users Mailing List
> Subject: Re: Design question about ActionForm's validate method
>
> The best practice now is to use ActionMappings for everything, so that
> the reqeust passes through the controller.
>
> This buys you several important capabilities that become important as
> applications grow. Not the least of which is the new support for
> multiple applications in the Nightly Build.
>
> The ActionMapping has a validate property that you can use to turn off
> validation when the mapping is used to initialize a new form. So,
> typically, you will have an ActionMapping for each circumstance.
>
>  path="/item/Add"
> type="org.apache.struts.actions.ForwardAction"
> parameter="/pages/item/Form.jsp">
> name="itemForm"
> scope="request"
> validate="false">
> 
>
> path="/item/Store"
> type="org.apache.gavel.item.http.Store"
> name="itemForm"
> scope="request"
> validate="true"
> input="/pages/item/Form.jsp"">
>  name="continue"
> path="/do/donor/Detail"/>
> 
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Java Web Development with Struts.
> -- Tel +1 585 737-3463.
> -- Web http://www.husted.com/struts/
>
> Sid Stuart wrote:
> >
> > Hi,
> >
> > I've stumbled across a subtle problem/design question that I don't see
> > mentioned in the documentation.
> >
> > The ActionForm's validate method can be configured to verify form data
> > from a page and generate error messages which may then be displayed on
> > the page for the user to see. This works fine when the user has accessed
> > the page by specifying a JSP file in the URL. When the user accesses the
> > page by calling the Action directly though, the validate method is
> > called before the user ever sees the page, much less inputs valid data
> > to the form. This leads to an unfortunate display of unwarranted error
> > messages.
> >
> > It would be nice if the documentation would provide a rule such as:
&

Re: Design question about ActionForm's validate method

2002-02-06 Thread Ted Husted

In 1.0.x, it is often suggested that each link at least be represented
by an ActionForward. This centralizes control over the hyperlinks in the
Struts Config, which yields a number of benefits. 

In Struts 1.1, now the Nightly Build, support has been added for
multiple Struts configuration files. In order for this feature to work,
any request for a presentation page that uses elements from the
configuration file (ActionForms, forwards, mappings) must be routed
through the controller. This allows the controller to make the
appropriate configuration available for a given page. 

This is becoming a common pattern, since the Velocity support, and I
believe the X2 servlet, also need you to do the same thing for the same
reason. The controller needs to touch the request to prepare it for the
presentation layer. 

Many other features in advanced applications, including security,
logging, and screen definitins, are easier to implement when everything
passes through the controller. 

In a strict MVC implementation, the controller is responsible for
interacting with the user. It then follows that all requests from the
user should flow through the controller. Some of us had been counting
the ActionForwards as flowing through the controller, but as the
framework expands, and more services are being plugged in, passing the
actual request through the controller becomes more and more desirable,
until it's really not worth making the occasional exception any more. 

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/


Alex Paransky wrote:
> 
> So do you mean, all pages go through the Action?  Even those which are not
> forms and for display purposes only?  Could you shed some light as to why
> this is preferred?
> 
> Thanks.
> 
> -AP_
> http://www.alexparansky.com
> 
> -Original Message-
> From: Ted Husted [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 05, 2002 2:02 PM
> To: Struts Users Mailing List
> Subject: Re: Design question about ActionForm's validate method
> 
> The best practice now is to use ActionMappings for everything, so that
> the reqeust passes through the controller.
> 
> This buys you several important capabilities that become important as
> applications grow. Not the least of which is the new support for
> multiple applications in the Nightly Build.
> 
> The ActionMapping has a validate property that you can use to turn off
> validation when the mapping is used to initialize a new form. So,
> typically, you will have an ActionMapping for each circumstance.
> 
>  path="/item/Add"
> type="org.apache.struts.actions.ForwardAction"
> parameter="/pages/item/Form.jsp">
> name="itemForm"
> scope="request"
> validate="false">
> 
> 
> path="/item/Store"
> type="org.apache.gavel.item.http.Store"
> name="itemForm"
> scope="request"
> validate="true"
> input="/pages/item/Form.jsp"">
>  name="continue"
> path="/do/donor/Detail"/>
> 
> 
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Java Web Development with Struts.
> -- Tel +1 585 737-3463.
> -- Web http://www.husted.com/struts/
> 
> Sid Stuart wrote:
> >
> > Hi,
> >
> > I've stumbled across a subtle problem/design question that I don't see
> > mentioned in the documentation.
> >
> > The ActionForm's validate method can be configured to verify form data
> > from a page and generate error messages which may then be displayed on
> > the page for the user to see. This works fine when the user has accessed
> > the page by specifying a JSP file in the URL. When the user accesses the
> > page by calling the Action directly though, the validate method is
> > called before the user ever sees the page, much less inputs valid data
> > to the form. This leads to an unfortunate display of unwarranted error
> > messages.
> >
> > It would be nice if the documentation would provide a rule such as:
> > If one plans on the user calling the Action directly in the URL  then
> > one should not use the automatic validation provided by ActionForm.
> >
> > Further, as having two different procedures to generate a page can lead
> > to subtle errors, one should decide whether a page will be accessed as a
> > JSP or as an Actio

RE: Design question about ActionForm's validate method

2002-02-06 Thread Greg Hess

I would like to see some examples, I have found my apps to be a bit bloated
since introducing struts and my Action classes are very small.

Thanks

-Original Message-
From: Sean Willson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 06, 2002 9:06 AM
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method


RE: Design question about ActionForm's validate methodFor reference I wanted
to share how we are using the action framework in our web application. Every
single call to every single view on our web site goes through Struts. There
are several reasons for this, one we are using Tiles for navigation and
since they are not as tightly integrated as I would like we had to do this.
Another is that every single view has data that needs to be prepopulated
before it can be displayed. Rather than create 2 actions for each view (one
for the loading and one for the saving) we encapsulated this logic in one
action. One of the first things it does is call a method called
isSubmission(request) ... this method interrogates the request to see if
there are any parameters that it considers "new" and not related to a load,
if it found some it would then assume it is a submission. If there are none,
it assumes it is a load and thus loads all of the data from the database and
other sources. If however it sees data on the hook that it doesn't
recognize, it then behaves as a submission and attempts to perform a save.
This has worked rather well overall.

To facilitate this we create a root action that has this method
(isSubmission) and in there we can specify parameters that we want ALL
action to handle, like a successRedirect parameter that should be used in
the event a submission is successfully saved. The same can be said for a
root level form that all of our forms subclass from to tie in those
attributes added to the check in isSubmission.

Some may argue that this is a mix between the model and the controller logic
but I don't agree. I think if you look at anyone's actions you will see a
little overlap, since Struts itself isn't a pure clean line of separation.
The key is getting it to work for you and your clients while still
maintaining some future vision and control over the architecture and not
letting it get out of hand.

I you want some code examples of this I can likely throw some together.

Sean


- Original Message -
From: Matt Read
To: Struts Users Mailing List
Sent: Tuesday, February 05, 2002 11:59 AM
Subject: RE: Design question about ActionForm's validate method


I'm fairly new to struts (well, about 24 hours actually) and this message
touches on a concept that I've having trouble grasping.
Are you saying that your site should never allow the user to navigate to a
URL that maps to an Action unless you are submitting a form?
This is my example and although it's actually working in practice it doesn't
really feel right to me and doesn't conform to above rule. I hope I've
included enough detail and would appreciate any clues on good design.
1. User goes to the home page and clicks on a "Find a client" link.
2. This link points to "/find/client.do" which is defined as an
ActionMapping as follows:



3. The code in FindClientAction ensures that the user is authenticated and
then populates some request scoped attributes that enabled
/pages/findClient.jsp to function correctly. /pagesfindClient.jsp displays a
form to allow the user to enter search criteria.
4. The submit action for the form in /pages/findClient.jsp is
"/find/getresults" which is defined as an ActionMapping as follows:



5. The code in FindClientResultsAction examines the contents of the
clientFindForm and contstructs a SQL statement to retrieve the correct data.
6. /pages/findClientResults.jsp renders the results from the database.
Matt.


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-06 Thread Sean Willson

RE: Design question about ActionForm's validate methodFor reference I wanted
to share how we are using the action framework in our web application. Every
single call to every single view on our web site goes through Struts. There
are several reasons for this, one we are using Tiles for navigation and
since they are not as tightly integrated as I would like we had to do this.
Another is that every single view has data that needs to be prepopulated
before it can be displayed. Rather than create 2 actions for each view (one
for the loading and one for the saving) we encapsulated this logic in one
action. One of the first things it does is call a method called
isSubmission(request) ... this method interrogates the request to see if
there are any parameters that it considers "new" and not related to a load,
if it found some it would then assume it is a submission. If there are none,
it assumes it is a load and thus loads all of the data from the database and
other sources. If however it sees data on the hook that it doesn't
recognize, it then behaves as a submission and attempts to perform a save.
This has worked rather well overall.

To facilitate this we create a root action that has this method
(isSubmission) and in there we can specify parameters that we want ALL
action to handle, like a successRedirect parameter that should be used in
the event a submission is successfully saved. The same can be said for a
root level form that all of our forms subclass from to tie in those
attributes added to the check in isSubmission.

Some may argue that this is a mix between the model and the controller logic
but I don't agree. I think if you look at anyone's actions you will see a
little overlap, since Struts itself isn't a pure clean line of separation.
The key is getting it to work for you and your clients while still
maintaining some future vision and control over the architecture and not
letting it get out of hand.

I you want some code examples of this I can likely throw some together.

Sean


- Original Message -
From: Matt Read
To: Struts Users Mailing List
Sent: Tuesday, February 05, 2002 11:59 AM
Subject: RE: Design question about ActionForm's validate method


I'm fairly new to struts (well, about 24 hours actually) and this message
touches on a concept that I've having trouble grasping.
Are you saying that your site should never allow the user to navigate to a
URL that maps to an Action unless you are submitting a form?
This is my example and although it's actually working in practice it doesn't
really feel right to me and doesn't conform to above rule. I hope I've
included enough detail and would appreciate any clues on good design.
1. User goes to the home page and clicks on a "Find a client" link.
2. This link points to "/find/client.do" which is defined as an
ActionMapping as follows:



3. The code in FindClientAction ensures that the user is authenticated and
then populates some request scoped attributes that enabled
/pages/findClient.jsp to function correctly. /pagesfindClient.jsp displays a
form to allow the user to enter search criteria.
4. The submit action for the form in /pages/findClient.jsp is
"/find/getresults" which is defined as an ActionMapping as follows:



5. The code in FindClientResultsAction examines the contents of the
clientFindForm and contstructs a SQL statement to retrieve the correct data.
6. /pages/findClientResults.jsp renders the results from the database.
Matt.


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




RE: Design question about ActionForm's validate method

2002-02-06 Thread Jonathan Gibbons


Hi,

live and learn eh!   I revise my recommendation, you still need two URL's, but they 
can go to defined action paths.

However, beware of users browsing directly to the JSP's and code with that in mind.   
Also to stop yourself going mad, make sure the GET path and POST path are different

eg GET
/jsp/apageGet

POST
/jsp/apagePost.do

Jonathan
ps now rewritting my code gen.


 Message History 



From: "Robert Scaduto" <[EMAIL PROTECTED]> on 05/02/2002 13:31 EST

Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED]>

To:   "Struts Users Mailing List" <[EMAIL PROTECTED]>
cc:
Subject:  RE: Design question about ActionForm's validate method


Matt,

I also disagree that you should only use actions when submitting a form.  I
also believe that in most cases you should never forward a request directly
to a jsp without first going through the Action framework.

Struts provides a utility action that will do this for you.  The
org.apache.struts.actions.ForwardAction will forward to the jsp file
specified in the parameter attribute of the action mapping. Like so..




If you are using the *.do extension in your servlet mapping you would access
the action like this...

Go to Password
Assistance

It may seem like extra work for no reason but if the requirements of your
system change and now you need to forward to an action instead of a jsp it
is much easier to replace the ForwardAction to a custom action.

It sounds to me like you are on the right track.

-Rob

-Original Message-
From: Matt Read [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 05, 2002 12:59 PM
To: Struts Users Mailing List
Subject: RE: Design question about ActionForm's validate method


I'm fairly new to struts (well, about 24 hours actually) and this message
touches on a concept that I've having trouble grasping.

Are you saying that your site should never allow the user to navigate to a
URL that maps to an Action unless you are submitting a form?

This is my example and although it's actually working in practice it doesn't
really feel right to me and doesn't conform to above rule. I hope I've
included enough detail and would appreciate any clues on good design.

1. User goes to the home page and clicks on a "Find a client" link.
2. This link points to "/find/client.do" which is defined as an
ActionMapping as follows:
 
   
 
3. The code in FindClientAction ensures that the user is authenticated and
then populates some request scoped attributes that enabled
/pages/findClient.jsp to function correctly. /pagesfindClient.jsp displays a
form to allow the user to enter search criteria.
4. The submit action for the form in /pages/findClient.jsp is
"/find/getresults" which is defined as an ActionMapping as follows:

   

5. The code in FindClientResultsAction examines the contents of the
clientFindForm and contstructs a SQL statement to retrieve the correct data.
6. /pages/findClientResults.jsp renders the results from the database.

Matt.

-Original Message-
From: Jonathan Gibbons [mailto:[EMAIL PROTECTED]]
Sent: 05 February 2002 17:44
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method



I made this same 'mistake'.

Actions MUST only be called when a form is submitted.   Never to generate
the JSP.  Thats why they are called actions.

Or two put it another way, you do need several URL's

a) URL to JSP on a GET
b) URL to action the POST

The easiert way to do it is to have all forwards going directly to the JSP,
and all actions in the pages going to .do.

At first it seems rubish, but then you hopefully buy into the model view
controller idea.  i.e NO business logic in the page and it all starts to
make perfect sence.   But you really do have to buy into it otherwise you
are fighting urge to ditch it all and go back to brilliant servlets, nice
and easy, total power etc etc.

Jonathan


 Message
History 


From: Sid Stuart <[EMAIL PROTECTED]> on 05/02/2002 09:24 PST

Please respond to "Struts Users Mailing List"
<[EMAIL PROTECTED]>

To:   Struts Users Mailing List <[EMAIL PROTECTED]>
cc:
Subject:  Design question about ActionForm's validate method


Hi,

I've stumbled across a subtle problem/design question that I don't see
mentioned in the documentation.

The ActionForm's validate method can be configured to verify form data
from a page and generate error messages which may then be displayed on
the page for the user to see. This works fine when the user has accessed
the page by specifying a JSP file in the URL. When the user accesses the
page by calling the Action directly though, the

RE: Design question about ActionForm's validate method

2002-02-05 Thread Alex Paransky

So do you mean, all pages go through the Action?  Even those which are not
forms and for display purposes only?  Could you shed some light as to why
this is preferred?

Thanks.

-AP_
http://www.alexparansky.com


-Original Message-
From: Ted Husted [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 05, 2002 2:02 PM
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method


The best practice now is to use ActionMappings for everything, so that
the reqeust passes through the controller.

This buys you several important capabilities that become important as
applications grow. Not the least of which is the new support for
multiple applications in the Nightly Build.

The ActionMapping has a validate property that you can use to turn off
validation when the mapping is used to initialize a new form. So,
typically, you will have an ActionMapping for each circumstance.


name="itemForm"
scope="request"
validate="false">


   



-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/


Sid Stuart wrote:
>
> Hi,
>
> I've stumbled across a subtle problem/design question that I don't see
> mentioned in the documentation.
>
> The ActionForm's validate method can be configured to verify form data
> from a page and generate error messages which may then be displayed on
> the page for the user to see. This works fine when the user has accessed
> the page by specifying a JSP file in the URL. When the user accesses the
> page by calling the Action directly though, the validate method is
> called before the user ever sees the page, much less inputs valid data
> to the form. This leads to an unfortunate display of unwarranted error
> messages.
>
> It would be nice if the documentation would provide a rule such as:
> If one plans on the user calling the Action directly in the URL  then
> one should not use the automatic validation provided by ActionForm.
>
> Further, as having two different procedures to generate a page can lead
> to subtle errors, one should decide whether a page will be accessed as a
> JSP or as an Action and design for the one scenario. The simplest (and
> safest) design rule will be to access all pages through either one
> mechanism or the other.
>
> Comments?
>
> Sid Stuart

--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




RE: RE: Design question about ActionForm's validate method

2002-02-05 Thread ykphuah

Hi,

I think there is some misconfiguration issue, as far as I know,
there are two kind of actions in Struts, EditAction and
SaveAction. For my implementation, all the EditAction
have validate=false in the struts-config.xml and all the
SaveAction have validate=true.

EditAction took care of 2 operations, edit and add, for
add, it just instantiate an object, for edit operation, it have
to load the values from the persistence layer (loading from JSP
is surely a very ugly thing to do.).

So for EditAction, its just plainly creating and loading,
no validation is neccessary, for SaveAction, then we need
validation.

CHeers,
Yee Keat

- Original Message -
From: "Robert Scaduto" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List"
<[EMAIL PROTECTED]>
Sent: Feb 6, 2002 2:31:19 AM GMT+08:00
Subject: RE: Design question about ActionForm's validate method

>Matt,
>
>I also disagree that you should only use actions when
submitting a form.  I
>also believe that in most cases you should never forward a
request directly
>to a jsp without first going through the Action framework.
>
>Struts provides a utility action that will do this for you. 
The
>org.apache.struts.actions.ForwardAction will forward to the
jsp file
>specified in the parameter attribute of the action mapping.
Like so..
>
>   type="org.apache.struts.actions.ForwardAction"
>   parameter="/password_assistance.jsp">
>
>
>If you are using the *.do extension in your servlet mapping
you would access
>the action like this...
>
>Go to Password
>Assistance
>
>It may seem like extra work for no reason but if the
requirements of your
>system change and now you need to forward to an action instead
of a jsp it
>is much easier to replace the ForwardAction to a custom
action.
>
>It sounds to me like you are on the right track.
>
>-Rob
>
>-Original Message-
>From: Matt Read [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, February 05, 2002 12:59 PM
>To: Struts Users Mailing List
>Subject: RE: Design question about ActionForm's validate
method
>
>
>I'm fairly new to struts (well, about 24 hours actually) and
this message
>touches on a concept that I've having trouble grasping.
>
>Are you saying that your site should never allow the user to
navigate to a
>URL that maps to an Action unless you are submitting a form?
>
>This is my example and although it's actually working in
practice it doesn't
>really feel right to me and doesn't conform to above rule. I
hope I've
>included enough detail and would appreciate any clues on good
design.
>
>1. User goes to the home page and clicks on a "Find a client"
link.
>2. This link points to "/find/client.do" which is defined as
an
>ActionMapping as follows:
>  type="mysite.actions.FindClientAction"
>   name="clientFindForm"
>   scope="request"
>   input="/pages/findclient.jsp">
>   
>   
>3. The code in FindClientAction ensures that the user is
authenticated and
>then populates some request scoped attributes that enabled
>/pages/findClient.jsp to function correctly.
/pagesfindClient.jsp displays a
>form to allow the user to enter search criteria.
>4. The submit action for the form in /pages/findClient.jsp is
>"/find/getresults" which is defined as an ActionMapping as
follows:
>   type="mysite.actions.FindClientResultsAction"
>   name="clientFindForm"
>   scope="request"
>   input="/pages/findclient.jsp">
>   
>    
>5. The code in FindClientResultsAction examines the contents
of the
>clientFindForm and contstructs a SQL statement to retrieve the
correct data.
>6. /pages/findClientResults.jsp renders the results from the
database.
>
>Matt.
>
>-Original Message-
>From: Jonathan Gibbons [mailto:[EMAIL PROTECTED]]
>Sent: 05 February 2002 17:44
>To: Struts Users Mailing List
>Subject: Re: Design question about ActionForm's validate
method
>
>
>
>I made this same 'mistake'.
>
>Actions MUST only be called when a form is submitted.   Never
to generate
>the JSP.  Thats why they are called actions.
>
>Or two put it another way, you do need several URL's
>
>a) URL to JSP on a GET
>b) URL to action the POST
>
>The easiert way to do it is to have all forwards going
directly to the JSP,
>and all actions in the pages going to .do.
>
>At first it seems rubish, but then you hopefu

Re: Design question about ActionForm's validate method

2002-02-05 Thread Ted Husted

The best practice now is to use ActionMappings for everything, so that
the reqeust passes through the controller. 

This buys you several important capabilities that become important as
applications grow. Not the least of which is the new support for
multiple applications in the Nightly Build. 

The ActionMapping has a validate property that you can use to turn off
validation when the mapping is used to initialize a new form. So,
typically, you will have an ActionMapping for each circumstance. 


name="itemForm"
scope="request"
validate="false">


   
 


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/


Sid Stuart wrote:
> 
> Hi,
> 
> I've stumbled across a subtle problem/design question that I don't see
> mentioned in the documentation.
> 
> The ActionForm's validate method can be configured to verify form data
> from a page and generate error messages which may then be displayed on
> the page for the user to see. This works fine when the user has accessed
> the page by specifying a JSP file in the URL. When the user accesses the
> page by calling the Action directly though, the validate method is
> called before the user ever sees the page, much less inputs valid data
> to the form. This leads to an unfortunate display of unwarranted error
> messages.
> 
> It would be nice if the documentation would provide a rule such as:
> If one plans on the user calling the Action directly in the URL  then
> one should not use the automatic validation provided by ActionForm.
> 
> Further, as having two different procedures to generate a page can lead
> to subtle errors, one should decide whether a page will be accessed as a
> JSP or as an Action and design for the one scenario. The simplest (and
> safest) design rule will be to access all pages through either one
> mechanism or the other.
> 
> Comments?
> 
> Sid Stuart

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: Design question about ActionForm's validate method

2002-02-05 Thread Greg Hess

Unfortunatly not all html input fields are populated in the http request by
default. Radio Buttons and Check boxes will be null if the user did not
select the option.

-Original Message-
From: Sid Stuart [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 05, 2002 2:56 PM
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method


You get a zero length string.

Sid

dderry wrote:

> What if your user then hits the Submit button without populating any of
the
> form fields?
>
> - Original Message -
> From: "Sid Stuart" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Tuesday, February 05, 2002 2:06 PM
> Subject: Re: Design question about ActionForm's validate method
>
> > Hi,
> >
> > My friend, Lee Crawford, just pointed out to me that the fields of the
> > ActionForm will be null if the validate method is called before the form
> is
> > submitted, but will be non-null afterwards. This provides a quick and
> simple
> > test that works for JSP called pages and for Action called pages,
> >
> >
> >public ActionErrors validate (ActionMapping mapping,
> >  HttpServletRequest request) {
> >  // See if the form has been submitted, if not do not
> >  validate.
> >  if (logon == null || password == null ) return null;
> >  // Validate the data
> >  final ActionErrors errors = new ActionErrors ();
> >  if (logon.length() < 1) {
> >  errors.add ("logon", new ActionError
> >  ("error.logon.logonRequired"));
> >  }
> >  if (password.length() < 1) {
> >  errors.add("password", new ActionError
> >  ("error.logon.passwordRequired"));
> >  }
> >  return errors;
> >  }
> >
> >
> > Sid
> >
> >
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-05 Thread dderry

True, so I guess the null test will work.


- Original Message -
From: "Sid Stuart" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, February 05, 2002 2:55 PM
Subject: Re: Design question about ActionForm's validate method


> You get a zero length string.
>
> Sid
>
> dderry wrote:
>
> > What if your user then hits the Submit button without populating any of
the
> > form fields?
> >
> > - Original Message -
> > From: "Sid Stuart" <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Tuesday, February 05, 2002 2:06 PM
> > Subject: Re: Design question about ActionForm's validate method
> >
> > > Hi,
> > >
> > > My friend, Lee Crawford, just pointed out to me that the fields of the
> > > ActionForm will be null if the validate method is called before the
form
> > is
> > > submitted, but will be non-null afterwards. This provides a quick and
> > simple
> > > test that works for JSP called pages and for Action called pages,
> > >
> > >
> > >public ActionErrors validate (ActionMapping mapping,
> > >  HttpServletRequest request) {
> > >  // See if the form has been submitted, if not do not
> > >  validate.
> > >  if (logon == null || password == null ) return null;
> > >  // Validate the data
> > >  final ActionErrors errors = new ActionErrors ();
> > >  if (logon.length() < 1) {
> > >  errors.add ("logon", new ActionError
> > >  ("error.logon.logonRequired"));
> > >  }
> > >  if (password.length() < 1) {
> > >  errors.add("password", new ActionError
> > >  ("error.logon.passwordRequired"));
> > >  }
> > >  return errors;
> > >  }
> > >
> > >
> > > Sid
> > >
> > >
> >
> > --
> > To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-05 Thread Sid Stuart

You get a zero length string.

Sid

dderry wrote:

> What if your user then hits the Submit button without populating any of the
> form fields?
>
> - Original Message -
> From: "Sid Stuart" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Tuesday, February 05, 2002 2:06 PM
> Subject: Re: Design question about ActionForm's validate method
>
> > Hi,
> >
> > My friend, Lee Crawford, just pointed out to me that the fields of the
> > ActionForm will be null if the validate method is called before the form
> is
> > submitted, but will be non-null afterwards. This provides a quick and
> simple
> > test that works for JSP called pages and for Action called pages,
> >
> >
> >public ActionErrors validate (ActionMapping mapping,
> >  HttpServletRequest request) {
> >  // See if the form has been submitted, if not do not
> >  validate.
> >  if (logon == null || password == null ) return null;
> >  // Validate the data
> >  final ActionErrors errors = new ActionErrors ();
> >  if (logon.length() < 1) {
> >  errors.add ("logon", new ActionError
> >  ("error.logon.logonRequired"));
> >  }
> >  if (password.length() < 1) {
> >  errors.add("password", new ActionError
> >  ("error.logon.passwordRequired"));
> >  }
> >  return errors;
> >  }
> >
> >
> > Sid
> >
> >
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-05 Thread dderry

What if your user then hits the Submit button without populating any of the
form fields?


- Original Message -
From: "Sid Stuart" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, February 05, 2002 2:06 PM
Subject: Re: Design question about ActionForm's validate method


> Hi,
>
> My friend, Lee Crawford, just pointed out to me that the fields of the
> ActionForm will be null if the validate method is called before the form
is
> submitted, but will be non-null afterwards. This provides a quick and
simple
> test that works for JSP called pages and for Action called pages,
>
>
>public ActionErrors validate (ActionMapping mapping,
>  HttpServletRequest request) {
>  // See if the form has been submitted, if not do not
>  validate.
>  if (logon == null || password == null ) return null;
>  // Validate the data
>  final ActionErrors errors = new ActionErrors ();
>  if (logon.length() < 1) {
>  errors.add ("logon", new ActionError
>  ("error.logon.logonRequired"));
>  }
>  if (password.length() < 1) {
>  errors.add("password", new ActionError
>  ("error.logon.passwordRequired"));
>  }
>  return errors;
>  }
>
>
> Sid
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-05 Thread Sid Stuart

Hi,

My friend, Lee Crawford, just pointed out to me that the fields of the
ActionForm will be null if the validate method is called before the form is
submitted, but will be non-null afterwards. This provides a quick and simple
test that works for JSP called pages and for Action called pages,


   public ActionErrors validate (ActionMapping mapping,
 HttpServletRequest request) {
 // See if the form has been submitted, if not do not
 validate.
 if (logon == null || password == null ) return null;
 // Validate the data
 final ActionErrors errors = new ActionErrors ();
 if (logon.length() < 1) {
 errors.add ("logon", new ActionError
 ("error.logon.logonRequired"));
 }
 if (password.length() < 1) {
 errors.add("password", new ActionError
 ("error.logon.passwordRequired"));
 }
 return errors;
 }


Sid

Sid Stuart wrote:

> Hi,
>
> I've stumbled across a subtle problem/design question that I don't see
> mentioned in the documentation.
>
> The ActionForm's validate method can be configured to verify form data
> from a page and generate error messages which may then be displayed on
> the page for the user to see. This works fine when the user has accessed
> the page by specifying a JSP file in the URL. When the user accesses the
> page by calling the Action directly though, the validate method is
> called before the user ever sees the page, much less inputs valid data
> to the form. This leads to an unfortunate display of unwarranted error
> messages.
>
> It would be nice if the documentation would provide a rule such as:
> If one plans on the user calling the Action directly in the URL  then
> one should not use the automatic validation provided by ActionForm.
>
> Further, as having two different procedures to generate a page can lead
> to subtle errors, one should decide whether a page will be accessed as a
> JSP or as an Action and design for the one scenario. The simplest (and
> safest) design rule will be to access all pages through either one
> mechanism or the other.
>
> Comments?
>
> Sid Stuart



RE: Design question about ActionForm's validate method

2002-02-05 Thread Robert Scaduto

Matt,

I also disagree that you should only use actions when submitting a form.  I
also believe that in most cases you should never forward a request directly
to a jsp without first going through the Action framework.

Struts provides a utility action that will do this for you.  The
org.apache.struts.actions.ForwardAction will forward to the jsp file
specified in the parameter attribute of the action mapping. Like so..




If you are using the *.do extension in your servlet mapping you would access
the action like this...

Go to Password
Assistance

It may seem like extra work for no reason but if the requirements of your
system change and now you need to forward to an action instead of a jsp it
is much easier to replace the ForwardAction to a custom action.

It sounds to me like you are on the right track.

-Rob

-Original Message-
From: Matt Read [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 05, 2002 12:59 PM
To: Struts Users Mailing List
Subject: RE: Design question about ActionForm's validate method


I'm fairly new to struts (well, about 24 hours actually) and this message
touches on a concept that I've having trouble grasping.

Are you saying that your site should never allow the user to navigate to a
URL that maps to an Action unless you are submitting a form?

This is my example and although it's actually working in practice it doesn't
really feel right to me and doesn't conform to above rule. I hope I've
included enough detail and would appreciate any clues on good design.

1. User goes to the home page and clicks on a "Find a client" link.
2. This link points to "/find/client.do" which is defined as an
ActionMapping as follows:



3. The code in FindClientAction ensures that the user is authenticated and
then populates some request scoped attributes that enabled
/pages/findClient.jsp to function correctly. /pagesfindClient.jsp displays a
form to allow the user to enter search criteria.
4. The submit action for the form in /pages/findClient.jsp is
"/find/getresults" which is defined as an ActionMapping as follows:



5. The code in FindClientResultsAction examines the contents of the
clientFindForm and contstructs a SQL statement to retrieve the correct data.
6. /pages/findClientResults.jsp renders the results from the database.

Matt.

-Original Message-
From: Jonathan Gibbons [mailto:[EMAIL PROTECTED]]
Sent: 05 February 2002 17:44
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method



I made this same 'mistake'.

Actions MUST only be called when a form is submitted.   Never to generate
the JSP.  Thats why they are called actions.

Or two put it another way, you do need several URL's

a) URL to JSP on a GET
b) URL to action the POST

The easiert way to do it is to have all forwards going directly to the JSP,
and all actions in the pages going to .do.

At first it seems rubish, but then you hopefully buy into the model view
controller idea.  i.e NO business logic in the page and it all starts to
make perfect sence.   But you really do have to buy into it otherwise you
are fighting urge to ditch it all and go back to brilliant servlets, nice
and easy, total power etc etc.

Jonathan


 Message
History 


From: Sid Stuart <[EMAIL PROTECTED]> on 05/02/2002 09:24 PST

Please respond to "Struts Users Mailing List"
<[EMAIL PROTECTED]>

To:   Struts Users Mailing List <[EMAIL PROTECTED]>
cc:
Subject:  Design question about ActionForm's validate method


Hi,

I've stumbled across a subtle problem/design question that I don't see
mentioned in the documentation.

The ActionForm's validate method can be configured to verify form data
from a page and generate error messages which may then be displayed on
the page for the user to see. This works fine when the user has accessed
the page by specifying a JSP file in the URL. When the user accesses the
page by calling the Action directly though, the validate method is
called before the user ever sees the page, much less inputs valid data
to the form. This leads to an unfortunate display of unwarranted error
messages.

It would be nice if the documentation would provide a rule such as:
If one plans on the user calling the Action directly in the URL  then
one should not use the automatic validation provided by ActionForm.

Further, as having two different procedures to generate a page can lead
to subtle errors, one should decide whether a page will be accessed as a
JSP or as an Action and design for the one scenario. The simplest (and
safest) design rule will be to access all pages through either one
mechanism or the other.

Comments?

Sid Stuart








--

This e-mail may contain confidential and/or privileged inform

RE: Design question about ActionForm's validate method

2002-02-05 Thread Matt Read

I'm fairly new to struts (well, about 24 hours actually) and this message
touches on a concept that I've having trouble grasping.

Are you saying that your site should never allow the user to navigate to a
URL that maps to an Action unless you are submitting a form?

This is my example and although it's actually working in practice it doesn't
really feel right to me and doesn't conform to above rule. I hope I've
included enough detail and would appreciate any clues on good design.

1. User goes to the home page and clicks on a "Find a client" link.
2. This link points to "/find/client.do" which is defined as an
ActionMapping as follows:



3. The code in FindClientAction ensures that the user is authenticated and
then populates some request scoped attributes that enabled
/pages/findClient.jsp to function correctly. /pagesfindClient.jsp displays a
form to allow the user to enter search criteria.
4. The submit action for the form in /pages/findClient.jsp is
"/find/getresults" which is defined as an ActionMapping as follows:



5. The code in FindClientResultsAction examines the contents of the
clientFindForm and contstructs a SQL statement to retrieve the correct data.
6. /pages/findClientResults.jsp renders the results from the database.

Matt.

-Original Message-
From: Jonathan Gibbons [mailto:[EMAIL PROTECTED]]
Sent: 05 February 2002 17:44
To: Struts Users Mailing List
Subject: Re: Design question about ActionForm's validate method



I made this same 'mistake'.

Actions MUST only be called when a form is submitted.   Never to generate
the JSP.  Thats why they are called actions.

Or two put it another way, you do need several URL's

a) URL to JSP on a GET
b) URL to action the POST

The easiert way to do it is to have all forwards going directly to the JSP,
and all actions in the pages going to .do.

At first it seems rubish, but then you hopefully buy into the model view
controller idea.  i.e NO business logic in the page and it all starts to
make perfect sence.   But you really do have to buy into it otherwise you
are fighting urge to ditch it all and go back to brilliant servlets, nice
and easy, total power etc etc.

Jonathan


 Message
History 


From: Sid Stuart <[EMAIL PROTECTED]> on 05/02/2002 09:24 PST

Please respond to "Struts Users Mailing List"
<[EMAIL PROTECTED]>

To:   Struts Users Mailing List <[EMAIL PROTECTED]>
cc:
Subject:  Design question about ActionForm's validate method


Hi,

I've stumbled across a subtle problem/design question that I don't see
mentioned in the documentation.

The ActionForm's validate method can be configured to verify form data
from a page and generate error messages which may then be displayed on
the page for the user to see. This works fine when the user has accessed
the page by specifying a JSP file in the URL. When the user accesses the
page by calling the Action directly though, the validate method is
called before the user ever sees the page, much less inputs valid data
to the form. This leads to an unfortunate display of unwarranted error
messages.

It would be nice if the documentation would provide a rule such as:
If one plans on the user calling the Action directly in the URL  then
one should not use the automatic validation provided by ActionForm.

Further, as having two different procedures to generate a page can lead
to subtle errors, one should decide whether a page will be accessed as a
JSP or as an Action and design for the one scenario. The simplest (and
safest) design rule will be to access all pages through either one
mechanism or the other.

Comments?

Sid Stuart








--

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Design question about ActionForm's validate method

2002-02-05 Thread Jonathan Gibbons


I made this same 'mistake'.

Actions MUST only be called when a form is submitted.   Never to generate the JSP.  
Thats why they are called actions.

Or two put it another way, you do need several URL's

a) URL to JSP on a GET
b) URL to action the POST

The easiert way to do it is to have all forwards going directly to the JSP, and all 
actions in the pages going to .do.

At first it seems rubish, but then you hopefully buy into the model view controller 
idea.  i.e NO business logic in the page and it all starts to make perfect sence.   
But you really do have to buy into it otherwise you are fighting urge to ditch it all 
and go back to brilliant servlets, nice and easy, total power etc etc.

Jonathan


 Message History 



From: Sid Stuart <[EMAIL PROTECTED]> on 05/02/2002 09:24 PST

Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED]>

To:   Struts Users Mailing List <[EMAIL PROTECTED]>
cc:
Subject:  Design question about ActionForm's validate method


Hi,

I've stumbled across a subtle problem/design question that I don't see
mentioned in the documentation.

The ActionForm's validate method can be configured to verify form data
from a page and generate error messages which may then be displayed on
the page for the user to see. This works fine when the user has accessed
the page by specifying a JSP file in the URL. When the user accesses the
page by calling the Action directly though, the validate method is
called before the user ever sees the page, much less inputs valid data
to the form. This leads to an unfortunate display of unwarranted error
messages.

It would be nice if the documentation would provide a rule such as:
If one plans on the user calling the Action directly in the URL  then
one should not use the automatic validation provided by ActionForm.

Further, as having two different procedures to generate a page can lead
to subtle errors, one should decide whether a page will be accessed as a
JSP or as an Action and design for the one scenario. The simplest (and
safest) design rule will be to access all pages through either one
mechanism or the other.

Comments?

Sid Stuart








--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorized copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




RE: Design question about ActionForm's validate method

2002-02-05 Thread Robert Nocera


Direct the user to an action that isn't the action associated with the
page in question, even if all that action does is forward to the JSP
page.  Generally the action's associated with a JSP page get called from
that JSP page.

ActionA forwards to B.JSP, B.JSP submits to ActionB and so on...

Alternately provide a hidden form variable in your page, in your
validation method, check for it, if it's not there, don't continue
validating as the user did not just submit the page.

Robert Nocera
New England Open Solutions
www.neosllc.com
"You supply the vision, we'll do the rest."
 

-Original Message-
From: Sid Stuart [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, February 05, 2002 12:25 PM
To: Struts Users Mailing List
Subject: Design question about ActionForm's validate method

Hi,

I've stumbled across a subtle problem/design question that I don't see
mentioned in the documentation.

The ActionForm's validate method can be configured to verify form data
from a page and generate error messages which may then be displayed on
the page for the user to see. This works fine when the user has accessed
the page by specifying a JSP file in the URL. When the user accesses the
page by calling the Action directly though, the validate method is
called before the user ever sees the page, much less inputs valid data
to the form. This leads to an unfortunate display of unwarranted error
messages.

It would be nice if the documentation would provide a rule such as:
If one plans on the user calling the Action directly in the URL  then
one should not use the automatic validation provided by ActionForm.

Further, as having two different procedures to generate a page can lead
to subtle errors, one should decide whether a page will be accessed as a
JSP or as an Action and design for the one scenario. The simplest (and
safest) design rule will be to access all pages through either one
mechanism or the other.

Comments?

Sid Stuart




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Design question about ActionForm's validate method

2002-02-05 Thread Sid Stuart

Hi,

I've stumbled across a subtle problem/design question that I don't see
mentioned in the documentation.

The ActionForm's validate method can be configured to verify form data
from a page and generate error messages which may then be displayed on
the page for the user to see. This works fine when the user has accessed
the page by specifying a JSP file in the URL. When the user accesses the
page by calling the Action directly though, the validate method is
called before the user ever sees the page, much less inputs valid data
to the form. This leads to an unfortunate display of unwarranted error
messages.

It would be nice if the documentation would provide a rule such as:
If one plans on the user calling the Action directly in the URL  then
one should not use the automatic validation provided by ActionForm.

Further, as having two different procedures to generate a page can lead
to subtle errors, one should decide whether a page will be accessed as a
JSP or as an Action and design for the one scenario. The simplest (and
safest) design rule will be to access all pages through either one
mechanism or the other.

Comments?

Sid Stuart