Hi,
Currently there are two minor usage problems with
CommandDriven factory. I will summarize them briefly
below. A patch is attached along in this email.
1. Command Name:
Right now the name of the command is fetched from the
value of the submit button:
i.e.: for <input type="submit" name="command"
value="Add"/>, the command would be "Add".
Now that's fine for name in English or in one locale.
However, it won't work if the value is changing
depending on the current locale. I propose to add the
following feature:
If the user specifies:
<input type="submit" name="command{MyCommand}"
value="Add"/>
(note the additional '{MyCommand}')
then ww will use "MyCommand" as the command name
instead of using the value of the submit button.
2. Recursive CommandDriven invocation:
This happens when there is a "command" parameter in
the request's parameter list. This command is supposed
to be used by the action handling the form only. Now,
if within that action, you dynamically execute another
CommandDriven action, or within the view of that
action you use <webwork:action> or #action (velocity),
ww will set and invoke the same command. This is not
an expected behavior. Of course you can use
MyAction!myCommand to get around that, but right now
it doesn't seem to work with action alias. The quick
fix is to check if the action name ends with '!'; if
it does then we need not to set the command.
Regards,
======================= Diff =========================
F:\external_projects\webwork\src\main\webwork\action\factory>cvs
diff CommandAct
ionFactoryProxy.java
Index: CommandActionFactoryProxy.java
===================================================================
RCS file:
/cvsroot/webwork/webwork/src/main/webwork/action/factory/CommandAction
FactoryProxy.java,v
retrieving revision 1.10
diff -r1.10 CommandActionFactoryProxy.java
12a13,15
> import java.util.Set;
> import java.util.Iterator;
>
49,50c52,55
< if (idx != -1)
< {
---
>
> if ( idx == aName.length() - 1 ){
> return
getNextFactory().getActionImpl(aName.substring(0,
idx));
> }else if (idx != -1) {
69a75,87
> }else{
> Set keys =
ActionContext.getContext().getParameters().keySet();
> String keyName;
>
> for ( Iterator iter = keys.iterator();
iter.hasNext(); ){
> keyName = (String) iter.next();
>
> if ( keyName.startsWith("command{")
&& keyName.endsWith("}") )
{
> ((CommandDriven)
action).setCommand(
> keyName.substring(8,
keyName.length() - 1));
> break;
> }
> }
=====
---------------------------------------------
Hai Pham Quang
---------------------------------------------
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
/*
* WebWork, Web Application Framework
*
* Distributable under Apache license.
* See terms of license at opensource.org
*/
package webwork.action.factory;
import webwork.action.Action;
import webwork.action.CommandDriven;
import webwork.action.ActionContext;
import java.util.Set;
import java.util.Iterator;
/**
* Executes a "command" within an action specified either as part of the
* action name or as a parameter value.
*
* @author Rickard �berg ([EMAIL PROTECTED])
* @version $Revision: 1.10 $
*/
public class CommandActionFactoryProxy
extends ActionFactoryProxy
{
// Attributes ----------------------------------------------------
// Constructors --------------------------------------------------
public CommandActionFactoryProxy(ActionFactory aFactory)
{
super(aFactory);
}
// ActionFactory overrides ---------------------------------------
/**
* Locates the matching action object from the action factory proxy chain
* and then executes a command on it if the {@link CommandDriven} interface
* is implemented. The command is determined either by using the text
* after the <code>"!"</code> in the action name or from the value of the
* first parameter named
* <code>"command."</code>
*
* @param aName
* @return action from the next action factory proxy
* @exception Exception
*/
public Action getActionImpl(String aName)
throws Exception
{
// Set command that was used as part of action name
int idx = aName.lastIndexOf("!");
if ( idx == aName.length() - 1 ){
return getNextFactory().getActionImpl(aName.substring(0, idx));
}else if (idx != -1) {
String command = aName.substring(idx+1);
String actionName = aName.substring(0, idx);
Action action = getNextFactory().getActionImpl(actionName);
if (action instanceof CommandDriven)
{
((CommandDriven)action).setCommand(command);
}
return action;
}
Action action = getNextFactory().getActionImpl(aName);
if (action instanceof CommandDriven)
{
// Set command that was sent in as a parameter
String[] commandParam =
((String[])ActionContext.getContext().getParameters().get("command"));
if (commandParam != null)
{
((CommandDriven)action).setCommand(commandParam[0]);
}else{
Set keys = ActionContext.getContext().getParameters().keySet();
String keyName;
for ( Iterator iter = keys.iterator(); iter.hasNext(); ){
keyName = (String) iter.next();
if ( keyName.startsWith("command{") && keyName.endsWith("}") ){
((CommandDriven) action).setCommand(
keyName.substring(8, keyName.length() - 1));
break;
}
}
}
}
return action;
}
}