XWork Configuration (2)

3.WebWork - WebWork - Action configuration:
The optional "method" parameter tells WebWork which method to call based upon this action. If you leave the method parameter blank, WebWork will call the method execute() by default. If there is no execute() method and no method specified in the xml file, WebWork will throw an exception.

Also, you can tell WebWork to invoke "doSomething" method in your action by using the pattern "actionName!something" in your form. For example, "formTest!save.action" will invoke the method "save" in FormAction class. The method must be public, take no arguments and also returns a String which indicate the name of the result to be executed:
public String save() throws Exception{
...
return SUCCESS;
}


(可选属性"method"用来告诉WebWork调用action的那个方法.如果method属性为空,WebWork调用默认调用*execute*()方法.如果Action类中既没有execute()方法也没有在xml文件中指定其他方法,WebWork会抛出异常.

您也可以在您的表单中用"actionName!something"的方式告诉WebWork调用Action类中的"something"方法.例如"formTest!save.action"会调用FormAction类中的"save"方法.这个方法必须是public且没有参数).

Action Support
Action class attribute could be left out such as following :
<action name="myAction">
   ....
</action>

In this case, the class will default to com.opensymphony.xwork.ActionSupport which have an execute() method that returns SUCCESS by default.

(Action的类属性可以像下面一样省略:

在这种情况下,会缺省使用com.opensymphony.xwork.ActionSupport 类,它有一个execute()方法,缺省返回SUCCESS).

Action configuration (zh_cn) (en)

Default Action Reference

Since Webwork 2.2.1 you are also able to specify a default action to be executed when no other action is matched in the xwork.xml. This feature is provided mainly to eliminate the need to create an action class and/or element for very simple or similar results.  The default action name can be set inside the package element like below:

<package name="myPackage" ....>

...

<default-action-ref name="simpleViewResultAction">

<!-- 
An example of a default action that is just a simple class 
that has 3 fields: successUrl, errorUrl, and inputUrl.  This action 
parses the request url to set the result values.  In the normal case 
it just renders velocity results of the same name as the requested url.
-->
<action name="simpleViewResultAction" class="SimpleViewResultAction">
	<result type="velocity">${successUrl}</result>
	<result name="error" type="velocity">${errorUrl}</result>
	<result name="input" type="velocity">${inputUrl}</result>
</action>

... 

</package>


(从Webwork2.2.1开始您也可以指定一个当xwork.xml中找不到指定的action时执行的默认action.这一特性主要是用来满足为创建非常简单或相似的action类或元素的需求.默认action名可以在package元素里面这样配置).

Note
Note that the name attribute is left out for the first result, as WebWork will default to "success" if it is left out.

In this case any request to action not defined in this package will automatically trigger action with alias "simpleViewResultAction" to be executed.



(注意

注意第一个result的属性省略了,WebWork缺省会把它当作"success"

在这种情况下,如果请求到action的映射没有在这个包里定义,它会自动转向到别名为 "simpleViewResultAction" 的action来执行.).



你可能感兴趣的:(xml,velocity,Webwork)