天天看點

webWork全局result執行個體應用

為了應付目前已開發大量的一些action的現有情況,同時也要解決以前工作不要去改動,又實作一些新功能, 查閱了一下資料。

基礎思路如下:

在現有已方平台基礎上的最基礎的baseAction中加入基礎方法,同時在全局繼承的基礎package,加入基礎result

類型為“重定向”。傳回值由基礎action的變量動态生成。然後基于這些,就可以實作很靈活的操作,又不需要去重構舊代碼

<package name="mydefault" extends="webwork-default">
		<interceptors>
			<interceptor-stack name="coralStack">
				<interceptor-ref name="exception"/>
                <interceptor-ref name="alias"/>
                <interceptor-ref name="servlet-config"/>
                <interceptor-ref name="prepare"/>
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="chain"/>
                <interceptor-ref name="debugging"/>
                <interceptor-ref name="model-driven"/>
                <interceptor-ref name="fileUpload"/>
                <interceptor-ref name="static-params"/>
                <interceptor-ref name="params"/>
                <interceptor-ref name="conversionError"/>
                <interceptor-ref name="validation">
                    <param name="excludeMethods">delete,edit,execute,list,selectlist</param>
                </interceptor-ref>
                <interceptor-ref name="workflow">
                    <param name="excludeMethods">delete,edit,execute,list,selectlist</param>
                </interceptor-ref>
        	</interceptor-stack>
        </interceptors>
		<default-interceptor-ref name="coralStack" />
		<global-results>
            <result name="error">/errors/error.jsp</result>
            <!-- 全局傳回的 -->
            <result name="_toPage" type="redirect-action">${_toPageUrl}</result>

        </global-results>
        <global-exception-mappings>
            <exception-mapping result="error" exception="java.lang.Throwable"/>
        </global-exception-mappings>
        
</package>      
/**
 * 最基礎的一個Controller,供繼承
 * 
 */

abstract public class BaseAction extends ActionSupport{
	
	/**
	 * 傳回名
	 */
	protected static final String RESULT_TOPAGE = "_toPage";
	
	private String _toPageUrl;
	
	public String get_toPageUrl() {
		return _toPageUrl;
	}

	public void set_toPageUrl(String pageUrl) {
		_toPageUrl = pageUrl;
	}

	/**
	 * 跳轉的基礎方法,在公共配置上也對應的配置上了公共傳回名
	 * @return
	 */
	public String toPageUrl(){
		//測試 ../這個操作非常有用,因為webwork result中是相對路徑,通過..可以調整路徑,實作通路另一個子產品
		//this._toPageUrl = "../admin/resourceIndex.do?flag=1.00";
		
		return RESULT_TOPAGE;
	}