Custom WebWork Result Type
add following to a xwork.xml config file:
<?xml version="1.0" encoding="utf-8"?> <result-types> <result-type name="mydispatch" class="com.company.portal.util.MyDispatch" default="true"/> <result-type name="my2dispatch" class="MyDispatch" default="true"/><!-- spring wire bean --> </result-types>
use this custom type in the action:
<?xml version="1.0" encoding="utf-8"?> <action name="mydispatch" class="myPackage.barAction"> <result>foo.jsp</result> </action>
Actually can simply extend a webwork predefined resulttype for some purpose and override the conditionalParse and return a final location for the action. major methods in WebWorkSupport.java
/** * Implementation of the execute method from the Result interface. This will call * the abstract method {[cite/t:@link] #doExecute(String, ActionInvocation)} after optionally evaluating the * location as an OGNL evaluation. * * [cite/t:@param] invocation the execution state of the action. * [cite/t:@throws] Exception if an error occurs while executing the result. */ public void execute(ActionInvocation invocation) throws Exception { │ doExecute(conditionalParse(location, invocation), invocation); } protected String conditionalParse(String param, ActionInvocation invocation) { if (parse && param != null && invocation != null) { return TextParseUtil.translateVariables(param, invocation.getStack(), new TextParseUtil.ParsedValueEvaluator() { public Object evaluate(Object parsedValue) { if (encode) { if (parsedValue != null) { try { // use UTF-8 as this is the recommended encoding by W3C to // avoid incompatibilities. return URLEncoder.encode(parsedValue.toString(), "UTF-8"); }catch(UnsupportedEncodingException e) { _log.warn("error while trying to encode ["+parsedValue+"]", e); } } } return parsedValue; } }); } else { return param; } } /** │* Executes the result given a final location (jsp page, action, etc) and the action invocation │* (the state in which the action was executed). │* Subclasses must implement this class to handle │* custom logic for result handling. │* │* [cite/t:@param] finalLocation the location (jsp page, action, etc) to go to. │* [cite/t:@param] invocation the execution state of the action. │* [cite/t:@throws] Exception if an error occurs while executing the result. */ protected abstract void doExecute(String finalLocation, ActionInvocation invocation) throws Exception;