struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sandeep Takhar <sandeep_tak...@yahoo.com>
Subject Re: Help-Loading 2nd FormBean in same action???Is there an easy way??
Date Mon, 03 Dec 2001 16:31:18 GMT
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 <greg_callaghan@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" <andy.noble@data-workshop.com>
> Reply-To: "Struts Users Mailing List"
> <struts-user@jakarta.apache.org>
> To: "Struts Users Mailing List"
> <struts-user@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 <greg_callaghan@hotmail.com>
> To: <struts-user@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:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
>  > For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
>  >
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> 
=== message truncated ===


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

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


Mime
View raw message