開発メモ

開発用のメモです。

ロケーションを動的に処理するための設定

package jp.mirageworld.webapps.report.actions;

import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.CookiesAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

@Results({
        @Result(name = ActionSupport.SUCCESS, location = "${location}")
})
public class Index extends ActionSupport
        implements RequestAware, SessionAware, CookiesAware {
    @Override
    public void setCookiesMap(Map<String, String> cookies) {
        this.cookies = cookies;
    }

    @Override
    public void setRequest(Map<String, Object> request) {
        if (request instanceof RequestMap) {
            requestMap = (RequestMap) request;
        } else {
            requestMap = new RequestMap(ServletActionContext.getRequest());
        }
    }

    @Override
    public void setSession(Map<String, Object> session) {
        if (session instanceof SessionMap) {
            sessionMap = (SessionMap<String, Object>) session;
        } else {
            sessionMap = new SessionMap<>(ServletActionContext.getRequest());
        }
    }

    protected RequestMap requestMap;

    protected SessionMap<String, Object> sessionMap;

    protected Map<String, String> cookies;

    public String reportType;

    private String location;

    public String execute() {
        location = "index.jsp";
        return SUCCESS;
    }

    public String getLocation() {
        return location;
    }

}
Twitter: @asahina_alice