You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by purpureleaf lee <pu...@hotmail.com> on 2001/11/22 09:27:51 UTC
Will writing Actions in script make sense?
Hi all
I have implemented a experimental extention to Struts.
The idea is to write some scripts in the body of <action> tag to implement
the business logics.
For example:
<action path="/saveCustomer"
type="scriptedaction.ScriptedAction"
scope="request"
validate="false">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/error.jsp"/>
<parameter name="id"/>
<parameter name="firstName"/>
<parameter name="lastName"/>
if (id.length() == 0) return "failure";
System.out.println("id=" + id);
System.out.println("His name is \"" + firstName + "." + lastName + "\"");
return "success";
</action>
This is simple action.It uses "ScriptedAction" as it type,defines three
parameters and 4 lines of scripts.Scripts are written in beanshell,a script
environment for java(for more information ,visit www.beanshell.org).
When it is invoked, the "ScriptedAction" will initialize the script
environment,get the parameters from request parameters(and attributes),set
them as predefined variables of the script environment,and invoke the
codes.Writing a new Action class is not needed.
If the script is long and complex(for example,with many "try...catch" or
many EJB lookup),this approach doesn't make sense.Sinse a java class can do
the some thing but easier to debug.On the other hand,if the business logic
is simple and can be written in ten lines,we can gain flexibility and save
time.
But in most case, business logic is hard to script.May be with well designed
business component (Sun's J2EE Patterns?),we can write script to handle
them.After all,Struts acts as a mediator bettwen GUI layer and data layer
,there could be a good place to write srcipt if data layer is ease to use.
There is a web application includes my extentions and a simple
demo(struts.jar is not included).Just drop it to tomcat "webapps" to see
what will happen(Please copy struts.jar to WEB-INF/lib).
It won't amaze you :),just a idea.
Any comments?
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
Re: Will writing Actions in script make sense?
Posted by Ted Husted <hu...@apache.org>.
purpureleaf lee wrote:
> Any comments?
I think it makes sense for a number of use-cases, and is the same
general direction that is taken by the Workflow Proposal. A declared
goal there is to enable business domain experts to program workflows
without being Java engineers, using the equivalent of a
struts-config.xml. This also doesn't have to be an all-or-nothing
approach. Scripting can be used where it makes sense, and we still have
custom Actions when it does not.
Have you looked at BSF? There's been talk of having this donated to
Jakarta.
http://www-124.ibm.com/developerworks/projects/bsf
I'm having a lot of success using a small number of "framework" actions
that are scripted from the Struts configuration, using a combination of
objects specified as the parameter and ActionForwards.
-Ted.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>