Web Work
Web Work
December, 2006
What is WebWork?
• WebWork is a Model-View-Controlled type of framework.
• It separates logic from view.
• Simplifies Web development by using a powerful "action" concept on the server side.
Se rv le t
• XWork is a generic command Dis p a tc h e r
pattern implementation
XWo rk
Commercial in Confidence 2
What does XWork provide?
Commercial in Confidence 3
What does WebWork add?
• Results for servlet redirect & dispatch, Velocity, Freemarker, JasperReports, XSLT, etc.
Commercial in Confidence 4
Results: The “View” in MVC
Commercial in Confidence 5
ActionSupport
Commercial in Confidence 6
A “Car Rental Service” example
• Simple requirements.
– Take the Car rental Details, save the details and display result page.
– If the user enters a rentalID, display the rental details.
• Shows.
– Implementing an action.
– Configuring WebWork.
– Using the taglib.
– Type conversion.
– Error messages.
Commercial in Confidence 7
RentalAction.java
public class RentalAction extends ActionSupport {
private RentalService rentalService;
private RentalDetailsVO rentalVO;
public RentalDetailsVO getRentalVO() {
return rentalVO;
}
public void setRentalVO(RentalDetailsVO rentalDetailsVO) {
this.rentalVO = rentalDetailsVO;
}
Commercial in Confidence 8
RentalDetailsVO.java
public class RentalDetailsVO {
private String rentalID;
private String vehicalType;
private String vehicleNo;
private Date fromDate;
private Date toDate;
private CustomerDetailsVO customer;
Commercial in Confidence 9
InsertRentalDetails.ftl
Commercial in Confidence 10
Success_apex.ftl
<html>
<body>
<#if message?exists>
<@ww.property value='message'/>
<#else>
${action.getText('DataSaved')}
</#if>
</body>
</html>
Commercial in Confidence 11
Xwork.xml for Car Rental
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN“
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<include file="webwork-default.xml"/>
<package name="Rental" extends="webwork-default">
<action name="inputScreen" class="com.opensymphony.xwork.ActionSupport">
<interceptor-ref name="defaultStack"/>
<result name="success" type="dispatcher">/WEB-INF/ftl/InputScreen.ftl</result>
</action>
<action name="insertRentalDetails" class="com.sc.RentalActions" method="insertRentalDetails">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name=“validation"/>
<result name="success" type="dispatcher">/WEB-INF/ftl/Success_apex.ftl</result>
<result name="input" type="dispatcher">/WEB-INF/ftl/InputScreen.ftl</result>
</action>
<action name="filterScreen" class="com.opensymphony.xwork.ActionSupport" >
<interceptor-ref name="defaultStack"/>
<result name="success" type="dispatcher">/WEB-INF/ftl/filterScreen.ftl</result>
</action>
<action name="getRentalDetails" class="com.sc.RentalActions" method="getRentalDetails">
<interceptor-ref name="defaultStack"/>
<result name="success" type="dispatcher">/WEB-INF/ftl/getDetailsScreen.ftl</result>
<result name="error" type="dispatcher">/WEB-INF/ftl/Error_apex.ftl</result>
</action>
</package>
</xwork>
Commercial in Confidence 12
web.xml for Car Rental
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>/WEB-INF/lib/webwork.jar</taglib-location>
</taglib>
</web-app>
Commercial in Confidence 13
Interceptors
Re s ult
Commercial in Confidence 14
Interceptor Stacks
Commercial in Confidence 15
Model-Driven vs. Field-Driven
Commercial in Confidence 16
ModelDriven Interface
Commercial in Confidence 17
Making Rental ModelDriven
Commercial in Confidence 18
ModelDriven: Changes to the insert.ftl
Commercial in Confidence 19
Applying the ModelDrivenInterceptor
• In xwork.xml
Commercial in Confidence 20
What is the ValueStack?
OGNL Ex p re s s io n
• The ValueStack builds a stack of
objects
• Objects are used to find property
values Valu e Stack
• The ValueStack allows the
Commercial in Confidence 21
How is the ValueStack used?
Commercial in Confidence 22
The OGNL expression language
Commercial in Confidence 23
OGNL samples
OGNL Result
user.name getUser().getName()
user.toString() getUser().toString()
Commercial in Confidence 24
The XWork Validation Framework
Commercial in Confidence 25
RentalAction-insertRentalDetails-validation.xml
Commercial in Confidence 26
Bundled Validators
Validator Result
<validators>
<validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
<validator name="requiredstring" class="com.opensymphony.xwork.validator.validators.RequiredStringValidator"/>
<validator name="int" class="com.opensymphony.xwork.validator.validators.IntRangeFieldValidator"/>
<validator name="double" class="com.opensymphony.xwork.validator.validators.DoubleRangeFieldValidator"/>
<validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength" class="com.opensymphony.xwork.validator.validators.StringLengthFieldValidator"/>
<validator name="requireddouble" class="com.firstapex.fic.auxmaster.validators.DoubleMandatoryValidator"/>
<validator name="requireddate" class="com.firstapex.fic.auxmaster.validators.DateValidator"/>
<validator name="illegal" class="com.firstapex.fic.claims.validators.MiscTypeValidator"/>
<validator name="AuxCodeValidator" class="com.firstapex.fic.auxmaster.validators.AuxCodeValidator"/>
<validator name="AuxDataTypeValidator" class="com.firstapex.fic.claims.validators.AuxDataTypeValidator"/>
<validator name="PartyDataTypeValidator" class="com.firstapex.fic.claims.validators.PartyDataTypeValidator"/>
<validator name="ClaimNumberValidator" class="com.firstapex.fic.claims.validators.ClaimNumberValidator"/>
</validators>
Commercial in Confidence 27
Execution
Commercial in Confidence 28
Web works Architecture
Commercial in Confidence 29
Resources
• http://www.opensymphony.com
– Documentation
– Forums
Q & A ??
Commercial in Confidence 30