struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Canny Duck <duckmai...@googlemail.com>
Subject model conversation scope doesn' t work as property in a base action class
Date Thu, 22 May 2008 13:35:53 GMT

Hi,

I want to implement a process with more than one step and a model in a
conversation scope.
To realize that I used the Struts 2 scope plugin.

To implement the post-redirect-get pattern I have a result type of
"redirect-action". This behave is required.

The attached demo implementation worked fine, if the model property and the
getter setter method
is part of the called action. But if the model is declared in a BaseAction,
the model will not be set on the Value Stack
and the property model.page ist no set. It's think it's not a bug in the
scope plugin, because a
tried this 
http://www.vitarara.org/cms/struts_2_cookbook/using_a_conversation_scope
ConversationInterceptor  and have the same problems.

Here are the main classes of my demo process. You can test the attached demo
project to see the problem:

Action:

public class TestAction extends BaseAction<Model> {
    
// Working version without a BaseAction
//public class TestAction extends ActionSupport {
//	
//    @In(scope = ScopeType.CONVERSATION)
//    @Out(scope = ScopeType.CONVERSATION)
//    protected Model model;
//
//    public Model getModel() {
//        return model;
//    }
//
//    public void setModel(Model model) {
//        this.model = model;
//    }
    
	@Begin
	public String start() {
		model = new Model();
		model.setPage(1);
		return SUCCESS;
	}
	
	@End
	public String end() {
	    return "success";
	}
}

BaseAction:

public class BaseAction<TYPE> extends ActionSupport
{
    @In(scope = ScopeType.CONVERSATION)
    @Out(scope = ScopeType.CONVERSATION)
    protected TYPE model;

    public TYPE getModel() {
        return model;
    }

    public void setModel(TYPE model) {
        this.model = model;
    }
}

Model:

public class Model
{
    private int page;

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }
}

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <constant name="struts.devMode" value="true" />

    <package name="test" namespace="/" extends="struts-default">

        <interceptors>
            <interceptor name="bean-scope"
class="com.googlecode.scopeplugin.ScopeInterceptor" />
        </interceptors>

        <action name="start" class="example.ui.TestAction" method="start">
            <interceptor-ref name="bean-scope" />
            <interceptor-ref name="defaultStack" />
            <result name="success" type="redirect-action">/success</result>
        </action>
        
        <action name="success" class="example.ui.TestAction">
            <interceptor-ref name="bean-scope" />
            <interceptor-ref name="defaultStack" />
            <result name="success">/test/start.jsp</result>
        </action>
        
         <action name="end" class="example.ui.TestAction" method="end">
            <interceptor-ref name="bean-scope" />
            <interceptor-ref name="defaultStack" />
            <result name="success">/test/end.jsp</result>
        </action>
        

    </package>
</struts>

start.jsp:

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
<title>Start</title>
</head>

<body>
<s:form action="end">
        <!-- page is only set if no base action is used-->
	Page: <s:property value="model.page" />
	<s:submit value="End" />
</s:form>
</body>
</html>

http://www.nabble.com/file/p17404381/testapp.zip testapp.zip 
-- 
View this message in context: http://www.nabble.com/model-conversation-scope-doesn%27-t-work-as-property-in-a-base-action-class-tp17404381p17404381.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message