Struts"
Line 4: | Line 4: | ||
=Use ZUL instead of JSP= | =Use ZUL instead of JSP= | ||
+ | |||
+ | First, let us take [http://struts.apache.org/2.x/hello-world-using-struts-2.html the Hello World example in Struts tutorial] as an example. We could provide a ZUL page called <tt>HelloWorld.zul</tt> to replace <tt>HelloWorld.jsp</tt> as follows. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <?page title="Hello World!"?> | ||
+ | |||
+ | <h:h2 xmlns:h="xhtml"> | ||
+ | ${messageStore.message} | ||
+ | </h:h2> | ||
+ | </source> | ||
+ | |||
+ | As shown, you could use the same EL expression to access the data provided by Struts and your action handler. | ||
+ | |||
+ | Then, you map the <tt>hello</tt> action to <tt>HelloWorld.zul</tt> by modifying <tt>WEB-INF/classes/struts.xml</tt> as follows. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute"> | ||
+ | <result name="success">/HelloWorld.zul</result> | ||
+ | </action> | ||
+ | </source> | ||
+ | |||
+ | Then, you could visit <nowiki>http://localhost:8080/Hello_World_Struts2_Ant/hello.action</nowiki> as you are used to and have the same result. | ||
+ | |||
+ | Of course, it is a ZUL document. You could have any Ajax behavior you'd like. | ||
=Submit Form= | =Submit Form= |
Revision as of 06:41, 11 February 2011
The use of Struts with ZK is straightforward: just replace JSP pages with ZUL pages. You don't need to modify action handlers, data models and others. All you need to do is to map the result view to a ZUL page instead of JSP. In additions, EL expressions will work the same way in the ZUL page.
Use ZUL instead of JSP
First, let us take the Hello World example in Struts tutorial as an example. We could provide a ZUL page called HelloWorld.zul to replace HelloWorld.jsp as follows.
<?page title="Hello World!"?>
<h:h2 xmlns:h="xhtml">
${messageStore.message}
</h:h2>
As shown, you could use the same EL expression to access the data provided by Struts and your action handler.
Then, you map the hello action to HelloWorld.zul by modifying WEB-INF/classes/struts.xml as follows.
<action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
<result name="success">/HelloWorld.zul</result>
</action>
Then, you could visit http://localhost:8080/Hello_World_Struts2_Ant/hello.action as you are used to and have the same result.
Of course, it is a ZUL document. You could have any Ajax behavior you'd like.
Submit Form
Version History
Version | Date | Content |
---|---|---|