本地中文化网址
http://wiki.javascud.org/display/ww2cndoc/Home
在线文档
http://www.opensymphony.com/webwork/wikidocs
与 struts 的区别有实现国级化的时候, struts 的 message 只能出现 5 个动态的值
也就像下面的信息
Your {0} ticket(s) for flight {1} have been booked.
The total cost is {2}. Your confirmation number is {3}.
Your flight leaves at {4} and arrives at {5}
需要分成两段才能完成
<bean:message key="confirmation.msg1"
arg0="count" arg1="flightNumber" arg2="cost"/>
<bean:message key="confirmation.msg2"
arg0="confirmation" arg1="departure" arg2="arrival"/>
而 webwork 是无限制的,像上面的可以写成这样子
<ww:text name="confirmation.msg">
<ww:param value="count"/>
<ww:param value="flightNumber"/>
<ww:param value="cost"/>
<ww:param value="confirmation"/>
<ww:param value="departure"/>
<ww:param value="arrival"/>
</ww:text>
还有在web.xml里同指定webwork的tld所在位置
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>
/WEB-INF/lib/webwork- 2.1.7 .jar
</taglib-location>
</taglib>
在很多书上都讲上面可行,可是我却报下面的错...换成下面那种方式就ok了
也可以指定webwork.tld所在的位置也可以,,如
/WEB-INF/webwork.tld(webwork.tld拷到这下面来).
一个简单的例子
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class>
</servlet>
<servlet-name>action</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
--------------------------------------------------------------------------------
上面的set.get其实与struts当中的ActionFrom类似..
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib prefix="ui" uri="webwork" %>
<html>
<head>
<title>First WebWork Example</title>
</head>
<body>
<form action="hello.action" method="post">
<table>
<ui:textfield label="欢迎语句" name="greeting"/>
<ui:submit value="'Submit'"/>
</table>
</form>
</body>
</html>
这里的greeting要与HelloWorldActio.java里的属性一致
如出现错误会显示在当前页,
Enter your greeting please | |
欢迎语句: | |
|
如填上内容,就会相应的调用setGreeting()方法的..
<%@ taglib prefix="ww" uri="webwork" %>
<html>
<head>
<title>First WebWork Example</title>
</head>
<body>
<p><ww:property value="greeting"/></p>
</body>
</html>
把填的内容显示出来
在xwork.xml里的<action>
也相应的变成
<action name="hello" class="helloWorld.HelloWorldAction">
<result name="success" type="dispatcher">
<param name="location">/greetings.jsp</param>
</result>
<result name="error" type="dispatcher">
<param name="location">/index.jsp</param>
</result>
</action>
------------------------------------------------------------
(1)Field-Drivern上面的例子就是
(2)ModelDriven
package helloWorld;
private long id;
private String name;
return id;
}
this.id = id;
}
return name;
}
this.name = name;
}
}
--
package helloWorld;
import com.opensymphony.xwork.*;
Pet pet = new Pet();
return pet;
}
if (pet.getId() == 0) {
addFieldError("id", "Please enter in an id number for you new Pet.");
}
}
if (hasErrors())
return ERROR;
return SUCCESS;
}
}
需实现ModelDriven这个接口,它也只有一个方法
public Object getModel();
在xwork.xml加上
<action name="addpet" class="helloWorld.AddPetAction">
<result name="success" type="dispatcher">
<param name="location">/petadded.jsp</param>
</result>
<result name="error" type="dispatcher">
<param name="location">/addpet.jsp</param>
</result>
<interceptor-ref name="debugStack" />
<interceptor-ref name="defaultStack" />
</action>
还有两个页面分别用来添加和显示用的
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="ui" uri="webwork" %>
<html>
<head>
<title>First WebWork Example</title>
</head>
<body>
<form action="addpet.action" method="post">
<table>
<ui:textfield label="Pet ID Number" name="id"/>
<ui:textfield label="Name of Pet" name="name"/>
<ui:submit value="'Submit'"/>
</table>
</form>
</body>
</html>
-------petadded.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="ww" uri="webwork" %>
<html>
<head>
<title>First WebWork Example</title>
</head>
<body>
<p>Added a pet with the following properties:</p>
<ul>
<li>ID: <ww:property value="id"/></li>
<li>Name: <ww:property value="name"/></li>
</ul>
</form>
</body>
</html>