You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Callaghan <gr...@hotmail.com> on 2001/12/04 03:00:06 UTC

RE: Help-Loading 2nd FormBean in same action???Is there an easy w ay??

Thanks David,

I assume you're talking about sub-classing the FormBean to split out the 2 
different validation paths(?).  Would you mind if I ask you to 
confirm/explain?

Even with using different actions / struts.xml entries etc it still seems to 
me that that fundamental indication to the form bean validate method is 
required, and therefore an approach like the one you mentioned in your 1st 
para.  Maybe the penny hasn't dropped for me yet!

[Again this is trying to solve a problem associated with maintaining a 
common formbean for an object normal parameters PLUS search parameters, to 
allow the search parameters to be trickled through the Add/Edit/Delete 
process prior to going back to the narrowed list of objects page (narrowed 
based on the trickled through search parameters)]

Regards
Greg
----Original Message Follows----
From: "Sills, David" <Da...@commerceone.com>
Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
To: 'Struts Users Mailing List' <st...@jakarta.apache.org>
Subject: RE: Help-Loading 2nd FormBean in same action???Is there an easy w 
ay??
Date: Mon, 3 Dec 2001 16:02:04 -0800

As I understand it, you cannot alter parameters in any way within a
forwarded request. However, you could add an attribute that is also checked:

	// if attribute = SEARCH or parameter = SEARCH
	// else if parameter = EDIT/DELETE/ADD

Better yet, rethink your logic and consider refactoring to let polymorphism
do all this work for you. (2 subclasses with common logic in a parent class,
and two actions to use to trigger their application.)

Hope this helps.

David Sills


-----Original Message-----
From: Greg Callaghan [mailto:greg_callaghan@hotmail.com]
Sent: Monday, December 03, 2001 6:57 PM
To: struts-user@jakarta.apache.org
Subject: Re: Help-Loading 2nd FormBean in same action???Is there an easy
way??


Thanks Sandeep,

I don't think this actually helps in my situation (I think).

To distill down the problem to barebones as best I can -:
* I have a common formbean which has two possible validate paths depending
on whether the ACTION parameter is SEARCH or EDIT/DELETE/ADD.
* In the case the user say requests an ADD then -:
   - ACTION parameter is set to "ADD"
   - Formbean validation occurs, it references ACTION and does
     the correct validation (ie validate object parameters, not
     the object search parameters, search_xxx)
   - ADD action is then entered
* Now the issue is then if there is a problem an within the ADD action I
want to throw back to the previous page (via its associated *.do action to
pickup appropriate object setup code) I need a way to indicate to the common

formbean to do its SEARCH validation path, not ADD/EDIT/DELETE validation.
The problem then being how do you change/reset the ACTION request parameter?

So in summary, is there a way to, via code within an action (about to
redirect to another action), to indicate to the formbean about to be loaded
up which validation path it should follow.  I'm trying to find a way within
the struts framework, and hence thought use of the form beans parameters
would be correct.

Hope this makes sense.

Regards
Greg

PS. One solution would be perhaps to set a request attribute in the action
and have the formbean validation code reference this to determine the
correct validation path, however this seems to go a little against the grain

of the struts concept no?  That is would be nice that the form bean
validation is based on its own attributes.

----Original Message Follows----
From: Sandeep Takhar <sa...@yahoo.com>
Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
To: Struts Users Mailing List <st...@jakarta.apache.org>
Subject: Re: Help-Loading 2nd FormBean in same action???Is there an easy
way??
Date: Mon, 3 Dec 2001 08:31:18 -0800 (PST)

I think that you can use different actions mappings
for each.

>From Ted-Husted's site:

<!-- start of cut & paste -->

Use multifunction Actions to service related
ActionMappings
Here's an example:

In an Insert / Update workflow, there are usually
three ActionMappings, one for "add", to return an
empty ActionForm, one for "edit", to return a
populated ActionForm, and one for "store" to either
insert or update
the ActionForm properties into the model. Usually, all
three of these are mapped to the same Action.A good
way to tell them apart is to use the parameter
property with your mapping.

<!-- Input Article (admin) -->
<action
path="/admin/article/Add"
type="org.apache.struts.artimus.http.Client"
name="articleForm"
scope="request"
validate="false"
parameter="add">
<forward
name="continue"
path="/WEB-INF/pages/Entry.jsp"/>
</action>

<!-- Article Edit action mapping (admin) -->
<action
path="/admin/article/Edit"
type="org.apache.struts.artimus.http.Client"
name="articleForm"
scope="request"
validate="false"
parameter="select">
<forward
name="continue"
path="/WEB-INF/pages/Entry.jsp"/>
</action>

<!-- Article Save action mapping (admin) -->
<action
path="/admin/article/Save"
type="org.apache.struts.artimus.http.Client"
name="articleForm"
scope="request"
validate="true"
input="/WEB-INF/pages/Entry.jsp"
parameter="save">
<forward
name="continue"
path="/WEB-INF/pages/Article.jsp"/>
</action>

The Action can the call mapping.getParameter() and
switch to the appropriate "sub-Action". When "add" is
called, the Action checks the parameter, and returns a
blank form. When the parameter is "edit", the Action
uses other properties on the form to retrieve a record
and populate the form.

When the parameter is "save", the Action examines
properties on the form to determine whether it needs
to add or update the records. Usually, a record needs
a primary key, which is null on an add and not null on
update, and this is an easy way to tell which kind of
save is needed.



<!--- end of cut & paste -->

Sandeep
--- Greg Callaghan <gr...@hotmail.com> wrote:
  > Hi Andy,
  >
  > Here goes with the background.  Feel free anyone to
  > shoot me down if there's
  > a better approach :-)
  >
  > The high level overview is as follows, then I'll
  > follow with detail -:
  > [1] Formulating a good non-session-scope based way
  > to handle concept within
  > an application of
  > SearchObject/DisplayObjects/EditObjects where search
  >
  > criteria is remembered throughout this chain.
  > [2] Issue I have current with single form bean
  > approach in terms of how to
  > reset a request-parameter (eg ACTION) when forwarded
  > in an action to another
  > action.
  >
  > Some detail follows, however in summary in order to
  > work around issue [2]
  > above I'm having I thought that breaking out the
  > current form bean I have
  > into 2 form beans, would assist. See below
  >
  > === DETAILS ===
  > I want to have a design which caters for through out
  > the application, for
  > each application object -:
  > - Search Object X
  >    - Display Object Xs (could come in via other
  > pages too)
  >       - Edit/Add/Delete Object X
  >
  > Once the edit/add/delete operations are completed
  > then go back to the
  > "display object Xs" page, BUT remembering the
  > original search criteria.
  > Without this (or a paging approach) useability
  > becomes an issues when there
  > are many objects (ie search is used to narrow
  > scope). Of course if you add a
  > new object with fields which didn't match the search
  > criteria then after you
  > return to the "display object Xs" page the new item
  > wouldn't be in the list,
  > but thats expected.
  >
  > I currently have this working fine by incorporating
  > in the objects FormBean
  > separate search fields.  For example FormBeanX
  >    --------
  >    search_title
  >    search_description
  >    action
  >    ...
  >    title
  >    description
  >    -------
  > This way the FormBean is passed each time through
  > the chain of pages and the
  > search_xxx fields are automatically picked up from
  > request parameters via
  > the struts infra-structure.  In the "Display Object
  > Xs" and "Edit/Add/Delete
  > Object X" JSP pages I just include them as hidden
  > elements.
  >
  > I did however have to use the ACTION field in the
  > formbean to check whether
  > we were in a "search" OR "add"/"edit"/"delete"
  > action state, and then only
  > validate as appropriate.
  >
  > My only setback to this seemingly nice design is
  > that if you (a) hit an
  > exception on the "display Object X's" page after you
  > clicked on edit/add or
  > delete, OR (b) if the user hits cancel on this
  > screen, THEN I need to go
  > back to the "display Object X's" to display the
  > error.  As there is setup of
  > the object list for this page I want to forward back
  > to the action
  > associated with setting up this page (ie not recode
  > same thing in a
  > different action class).  However what I need to do
  > is reset the ACTION
  > field from EDIT say to DISPLAY (noting the
  > validation comment above), and
  > this is the problem.
  >
  > It seems this may not be possible?
  > - setting the ACTION field in the formbean from
  > within the action prior to
  > the forward doesn't work as the pseudo code in a
  > previous post from TedH
  > indicated that "If a form bean is in play, the
  > ActionServlet resets and
  > populates it from the HTTP request"
  > - I still haven't found a way to override a request
  > parameters value from an
  > action yet??? (it seems possible using a JSP tag, ie
  > the forward tag, so
  > maybe I just haven't worked it out yet)
  > =====
  >
  > Hope that make sense.  In summary therefore struts
  > questions I have are -:
  > [1] How to override a request parameters value in an
  > action &
  > [2] How to load a 2nd form bean in an action (see
  > email below)
  >
  > [PS.  Another thought I just had is to have a
  > separate action field for the
  > seach case.  ie within the form bean have ACTION and
  > SEARCH_ACTION.]
  >
  >
  > Regards
  > Greg
  >
  > ----Original Message Follows----
  > From: "Andy Noble" <an...@data-workshop.com>
  > Reply-To: "Struts Users Mailing List"
  > <st...@jakarta.apache.org>
  > To: "Struts Users Mailing List"
  > <st...@jakarta.apache.org>
  > Subject: Re: Help-Loading 2nd FormBean in same
  > action???Is there an easy
  > way??
  > Date: Mon, 3 Dec 2001 00:04:28 -0000
  >
  > As far as I'm aware, 1 JSP form gets mapped to 1
  > formbean.
  >
  > Why would you not have the attributes in the first
  > formbean?
  >
  > If really necessary,  you could maybe consider have
  > the 1st formbean have
  > getters and setters which delegate to a second
  > formbean. But would help if
  > you could explain reason for 2nd formbean.
  >
  > Andy
  >
  >
  > ----- Original Message -----
  > From: Greg Callaghan <gr...@hotmail.com>
  > To: <st...@jakarta.apache.org>
  > Sent: Sunday, December 02, 2001 11:22 PM
  > Subject: Help-Loading 2nd FormBean in same
  > action???Is there an easy way??
  >
  >
  >  > Hi,
  >  >
  >  > Does anyone know an easy way to load a 2nd form
  > bean in an action?
  >  >
  >  > That is, the main formbean has already been
  > specified in struts.xml for
  > that
  >  > action and will load automatically per usual.  If
  > however I have other
  >  > separate hidden form elements in my JSP form
  > which I would like to
  > auto-load
  >  > into their associated formbean (ie the 2nd form
  > bean) is there a way to
  >  > easily do this in the action in struts.
  >  >
  >  > Eg.  Within Action Class -:
  >  >    FormBean2 formbean2 = LOAD (request,
  > <formbean2 class ref>)
  >  >    (or something like this)
  >  >
  >  >
  >  > Cheers
  >  > Greg
  >  >
  >  >
  >
_________________________________________________________________
  >  > Get your FREE download of MSN Explorer at
  > http://explorer.msn.com/intl.asp
  >  >
  >  >
  >  > --
  >  > To unsubscribe, e-mail:
  > <ma...@jakarta.apache.org>
  >  > For additional commands, e-mail:
  > <ma...@jakarta.apache.org>
  >  >
  >
  >
  > --
  > To unsubscribe, e-mail:
  > <ma...@jakarta.apache.org>
  >
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   
<ma...@jakarta.apache.org>
For additional commands, e-mail: 
<ma...@jakarta.apache.org>



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>