You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Sayre <ri...@gmail.com> on 2009/04/22 13:00:24 UTC

Reusing GUI and Actions

I have a form in my web application that can be accessd from different
places (Namespaces) in the web app.

It looks something like this

/Admin/EditSchedule.action
/MySchedules/NewSchedule.action
/Create/NewSchedule.action
/Create/EditSchedule.action

The are subtle differences in how the data is handled each time.  For
example, in Admin all data can be updated, in Create and MySchedules
the data can be added. Also in  Create there is another area where the
data can be edited with the exception of two fields that can not be
changed.


The issue I am having is I need to submit the form to different
actions depending on where the user is.  For example in Admin, the
action will do an update on all the data (this takes 3 steps), in
Create it does an add plus it uses some other functionality from the
model (5 Steps).

So far I have used the same action name that saves the data in each
name space.  So every Forms action is SaveSchedule.action and each of
the name spaces provide a mapping for this action name.  Each action
does different thigs with the data.  This has workled so far and has
allowed me to use the exact same JSP for all areas in my web
application.  Since I have added the Edit function to the Create
namespace I can not do this anymore.  Since they share the same
namespace I can not reuse the SaveSchedule Action name.  The save from
the edit on the Create side on has 2 Steps.

Does any one have any suggestions on the best way to handle this?  I
figured I can do the following:

1)  In my JSP pages, leave out the Action in the form and provide it
in a java script function.

Currently my JSPs look like:

//unique things to that area of the app

include javaScriptFile

include formCode

//more unique things

Change it to

//unique things to that area of the app

<script>
//common function called from the form code
function saveScheduleForm() { ... }

</script>

include javaScriptFile

include formCode

//more unique things

This way each area that uses the form will provide its own
saveScheduleForm method.

I don't like this apprach since it could be very confusing to other programmers.


2) Rather than reuse the form code Cut and Paste it to every area of
the application I need it and change the action of the form to reflect
what action to submitt to.

I don't like this option because I dont want to maintain multiple
copies of this GUI.


3) Hand in some flag about what page I am on and choose logic based on that.

I don't like this because it does not seem like a good practice.


Does anyone have any suggestions?

Thanks,

Rich

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


Re: Reusing GUI and Actions

Posted by mitch gorman <mg...@shadowtv.com>.
    i've explicitly passed the name of the action to take into the page,
in similar situations.  my form has
<s:form ... action="%{actionname}" ....>

    or, i've used the session, so the form tag looks like
<form ... action="<s:property value="#session.actionname" />" ....>

    YMMV.

-- 
Mitch Gorman
mgorman@shadowtv.com
(215) 764-6310
Skype: mitch.shadowtv.com


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