Overview Install Manual Screenshots CVS Download Contribute Contact / Help

WebWork : WWPortlet Application Development QuickStart

Suppose

  • Suppose you are familiar with WebWork & Velocity, we do not explain the detail syntax of both, and just list some sample codes about how to quick start using WWPortlet framework.
  • In order to keep your attention on how to use WWPortlet, we will keep the sample as simple as possible.

The sample include

  • two view files: hello.vm & helloResult.vm
  • one xwork file: xwork.xml
  • one java action file: HelloAction.java
  • one I18N resource file: HelloAction.properties
  • one porltet description file: portlet.xml

Here is the sample list

hello.vm
<html>
<head><title>Please input your information</title></head>
<body>
<p>Welcome to Use $!now
</p>
#bodytag (Form "action='/hello.action'" "method='post'")
<input type="text" name="userName" value="" />
<INPUT name="Submit" type="submit" value="Submit"/>
#end
<br/>
</body>
</html>

helloResult.vm
<html>
<head><title>$action.getText('heading')</title></head>
<body>
<!-- h1>$action.getText('heading')</h1 -->
<p>$action.getText('greeting') $now
</p>
<p>
$userName 

</p>
#bodytag (Form "action='/hello.action'" "method='post'")
<input type="text" name="userName" value="" />
<INPUT name="Submit" type="submit" value="Submit"/>
#end
</body>
</html>

webwork-default.xml code snippet
<package name="webwork-default">
<result-types>
<result-type name="dispatcher" class="com.opensymphony.webwork.portlet.result.PortletDispatcherResult"/>
<result-type name="velocity" class="com.opensymphony.webwork.portlet.result.PortletDispatcherResult" default="true"/>
</result-types> 
....

xwork.xml code snippet
<xwork>
<include file="webwork-default.xml"/>

<package name="default" extends="webwork-default">
<interceptors>
<interceptor-stack name="standard-interceptors">
<interceptor-ref name="static-params"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
</interceptor-stack>
</interceptors>
....
<!-- Business Function Services -->
<action name="hello" class="com.test.HelloAction">
<result name="success">
<param name="location">/helloResult.vm</param>
</result>
</action>
</package>
</xwork>

HelloAction.java
package com.test;
import java.util.Date;
import com.opensymphony.xwork.ActionSupport;

public class HelloAction extends ActionSupport { 
private String _userName; 
public void setUserName(String name) { 
_userName = name; 
} 

public String getUserName() { 
return _userName; 
} 

public Date getNow() {
return new Date(System.currentTimeMillis());
}

public String execute() throws Exception { 
return SUCCESS; 
} 
}

portlet.xml
<portlet-app>
<portlet>
<portlet-name>UserManagementPortlet</portlet-name>
<display-name>UserManagementPortlet</display-name>
<portlet-class>com.opensymphony.webwork.portlet.WebWorkPortlet</portlet-class>
<name>defaultViewFile</name>
<value>/index.vm</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>UserManagementPortlet</title>
</portlet-info>
</portlet>
</portlet-app>

Conclusion

From above codes, we can see WWPortlet Framework do not change any WebWork development principle. You can test this sample codes in the standard Web Container, of course this sample based on WWPortlet will run smoothly in JSR168 Portal Container as portlet.

But there are a few key points you should know:
  • Change the webwork-default.xml (or in your xwork.xml) the result-type velocity to class "com.opensymphony.webwork.portlet.result.PortletDispatcherResult", also make result-type "velocity as the default view.
  • Now the presentation technology only support velocity. Cause I like velocity and hate JSP. Maybe the next version release, we will add the JSP presentation tech support.
  • In Velocity HTML Form only support to use #bodytag (Form "action='/hello.action'" "method='post'") .... #end, in order to run post in Portal we must follow the portal action & link name rules. We automatically change the action name at WWPortlet Framework layer.
  • If you like to use HTML link to access other resource, you should use such code <a href="$actionURL?wwLink=/index.vm">Home</a> to access index.vm, the key is "$actionURL?wwLink=".
  • If you want to use HTML link to access WebWork action resource, you must use code: <A class=nav href="$!actionXURL./login.action">Login</A>, the key is "$!actionXURL."
  • Any static resource refered in presentation page, must use code as: <IMG height=31 hspace=10 src="$req.contextPath/images/_bullet.gif" width=19 align=absMiddle>, the key is ""$req.contextPath"

WebWork Portlet Framework development guide

To be written....