Configuration"

From Documentation
m (correct highlight (via JWB))
 
Line 8: Line 8:
 
= Configure WEB-INF/web.xml =
 
= Configure WEB-INF/web.xml =
  
First, you have to map <javadoc directory="zest">org.zkoss.zest.sys.ZestFilter</javadoc> to the URL that you'd like ZEST to handle. For example, you could configure <tt>WEB-INF/web.xml</tt> to map it to all URLs as follows.
+
First, you have to map <javadoc directory="zest">org.zkoss.zest.sys.ZestFilter</javadoc> to the URL that you'd like ZEST to handle. For example, you could configure <code>WEB-INF/web.xml</code> to map it to all URLs as follows.
  
 
<source lang="xml">
 
<source lang="xml">
Line 25: Line 25:
 
= Configure WEB-INF/zest.xml =
 
= Configure WEB-INF/zest.xml =
  
To map a request URI to an action, you have to provide a configuration file called <tt>WEB-INF/zest.xml</tt>. For example, assume we have an action called <tt>foo.HelloAction</tt> and you'd like to map it to <tt>/hello</tt>, such that it will be invoked when the user visits <nowiki>http://yourwebsite.com/app-context/hello</nowiki>, then you could configure it as follows.
+
To map a request URI to an action, you have to provide a configuration file called <code>WEB-INF/zest.xml</code>. For example, assume we have an action called <code>foo.HelloAction</code> and you'd like to map it to <code>/hello</code>, such that it will be invoked when the user visits <nowiki>http://yourwebsite.com/app-context/hello</nowiki>, then you could configure it as follows.
  
 
<source lang="xml">
 
<source lang="xml">
Line 35: Line 35:
 
</source>
 
</source>
  
where the <tt>path</tt> attribute specifies the URI of request that this action matches. It could be a regular expression. The <tt>method</tt> attribute specifies the name of the method to call when the action is matched. If omitted, <code>execute</code> is assumed.
+
where the <code>path</code> attribute specifies the URI of request that this action matches. It could be a regular expression. The <code>method</code> attribute specifies the name of the method to call when the action is matched. If omitted, <code>execute</code> is assumed.
  
In additions, the <tt>result</tt> element specifies the URI of the view to render and send to the user. As shown, it specifies <tt>/WEB-INF/foo/Hello.jsp</tt> shall be used if the action returns <code>"success"</code> after invoked. You could add any number of <tt>result</tt> elements you want. If the <tt>name</tt> attribute is not specified, it is the default result, i.e., it matches any result.
+
In additions, the <code>result</code> element specifies the URI of the view to render and send to the user. As shown, it specifies <code>/WEB-INF/foo/Hello.jsp</code> shall be used if the action returns <code>"success"</code> after invoked. You could add any number of <code>result</code> elements you want. If the <code>name</code> attribute is not specified, it is the default result, i.e., it matches any result.
  
Then, when a user visits <nowiki>http://yourwebsite.com/app-context/hello</nowiki> (assume the application's context path is <tt>app-context</tt>), an instance of <code>foo.HelloAction</code> will be instantiated, and then <code>foo.HelloAction.execute()</code> will be invoked. Finally, if <code>execute()</code> returns <code>"success"</code>, ZEST will forward to <code>/WEB-INF/foo/Hello.jsp</code>.
+
Then, when a user visits <nowiki>http://yourwebsite.com/app-context/hello</nowiki> (assume the application's context path is <code>app-context</code>), an instance of <code>foo.HelloAction</code> will be instantiated, and then <code>foo.HelloAction.execute()</code> will be invoked. Finally, if <code>execute()</code> returns <code>"success"</code>, ZEST will forward to <code>/WEB-INF/foo/Hello.jsp</code>.
  
 
In general, an action is implemented and mapped for a particular feature, and you could have as many as actions you'd like.
 
In general, an action is implemented and mapped for a particular feature, and you could have as many as actions you'd like.
  
The <tt>class</tt> and <tt>method</tt> attribute and the view's URI could be an EL expression. For example, you could have ZEST to invoke different method based the request's status, such as <code>${request.method}</code>.
+
The <code>class</code> and <code>method</code> attribute and the view's URI could be an EL expression. For example, you could have ZEST to invoke different method based the request's status, such as <code>${request.method}</code>.
  
 
=Version History=
 
=Version History=

Latest revision as of 02:57, 18 January 2022

Configuration



There are two steps to configure ZEST for a Web application

  1. Configure WEB-INF/web.xml to specify ZEST as a filter
  2. Configure WEB-INF/zest.xml to specify the definitions of actions

Configure WEB-INF/web.xml

First, you have to map ZestFilter to the URL that you'd like ZEST to handle. For example, you could configure WEB-INF/web.xml to map it to all URLs as follows.

<web-app>
    <filter>
        <filter-name>zest</filter-name>
        <filter-class>org.zkoss.zest.sys.ZestFilter</filter-class>
    </filter>
	<filter-mapping>
        <filter-name>zest</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

Configure WEB-INF/zest.xml

To map a request URI to an action, you have to provide a configuration file called WEB-INF/zest.xml. For example, assume we have an action called foo.HelloAction and you'd like to map it to /hello, such that it will be invoked when the user visits http://yourwebsite.com/app-context/hello, then you could configure it as follows.

<zest>
	<action path="/hello" class="foo.HelloAction" method="execute">
		<result name="success">/WEB-INF/foo/Hello.jsp</result>
	</action>
</zest>

where the path attribute specifies the URI of request that this action matches. It could be a regular expression. The method attribute specifies the name of the method to call when the action is matched. If omitted, execute is assumed.

In additions, the result element specifies the URI of the view to render and send to the user. As shown, it specifies /WEB-INF/foo/Hello.jsp shall be used if the action returns "success" after invoked. You could add any number of result elements you want. If the name attribute is not specified, it is the default result, i.e., it matches any result.

Then, when a user visits http://yourwebsite.com/app-context/hello (assume the application's context path is app-context), an instance of foo.HelloAction will be instantiated, and then foo.HelloAction.execute() will be invoked. Finally, if execute() returns "success", ZEST will forward to /WEB-INF/foo/Hello.jsp.

In general, an action is implemented and mapped for a particular feature, and you could have as many as actions you'd like.

The class and method attribute and the view's URI could be an EL expression. For example, you could have ZEST to invoke different method based the request's status, such as ${request.method}.

Version History

Last Update : 2022/01/18


Version Date Content
     



Last Update : 2022/01/18

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.