struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Cook" <James.C...@wecomm.com>
Subject RE: Some Spring/Struts questions
Date Wed, 12 May 2010 14:36:20 GMT
Cool, cheers Wes

-----Original Message-----
From: Wes Wannemacher [mailto:wesw@wantii.com] 
Sent: 12 May 2010 15:29
To: Struts Users Mailing List
Subject: Re: Some Spring/Struts questions

Yep... Here's a quick example struts.xml -

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
        "http://struts.apache.org/dtds/struts-2.1.7.dtd">

<struts>

    <constant name="struts.convention.default.parent.package" value="/view"/>

    <package name="/view" namespace="/view" extends="app-base">

        <result-types>
            <result-type name="json"
class="org.apache.struts2.json.JSONResult"/>
        </result-types>

        <interceptors>
            <interceptor name="json"
class="org.apache.struts2.json.JSONInterceptor"/>
            <interceptor name="securityInterceptor"
class="securityInterceptor"/>

            <!-- what follows is a mod of the stock
paramsPrepareParams, but jsonValidation is added -->
            <interceptor-stack name="paramsPrepareParamsJsonStack">
                <interceptor-ref name="exception"/>
                <interceptor-ref name="servletConfig"/>
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="params">
                    <param name="excludeParams">dojo\..*,^struts\..*</param>
                </interceptor-ref>
                <interceptor-ref name="prepare"/>
                <interceptor-ref name="actionMappingParams"/>
                <interceptor-ref name="params">
                    <param name="excludeParams">dojo\..*,^struts\..*</param>
                </interceptor-ref>
                <interceptor-ref name="conversionError"/>
                <interceptor-ref name="validation">
                    <param name="excludeMethods">input,back,cancel</param>
                </interceptor-ref>
                <interceptor-ref name="jsonValidation"/>
                <interceptor-ref name="workflow">
                    <param name="excludeMethods">input,back,cancel</param>
                </interceptor-ref>
            </interceptor-stack>

            <interceptor-stack name="appStack">
                <interceptor-ref name="securityInterceptor"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="appStack"/>

        <global-results>
            <result name="loginRequired" type="redirect">
                <param name="location">/login.jsp</param>
                <param name="parse">false</param>
            </result>
        </global-results>

    </package>

</struts>

On Wed, May 12, 2010 at 10:03 AM, James Cook <James.Cook@wecomm.com> wrote:
> Ah, awesome. Thank you for clearing that one up and your package is defined in the struts.xml
in the root of the source?
>
> -----Original Message-----
> From: Wes Wannemacher [mailto:wesw@wantii.com]
> Sent: 12 May 2010 14:51
> To: Struts Users Mailing List
> Subject: Re: Some Spring/Struts questions
>
> James,
>
> What I normally do is create a "package" and set the defaults that I
> want stuff to use (interceptors / interceptor stack / etc.). Then, I
> just tell the convention plugin to use the package I configured....
>
> The list of properties that the plugin uses is here -
> http://struts.apache.org/2.x/docs/convention-plugin.html#ConventionPlugin-Configurationreference
>
> I think the setting is -
>
> struts.convention.default.parent.package
>
> -Wes
>
> On Wed, May 12, 2010 at 9:39 AM, James Cook <James.Cook@wecomm.com> wrote:
>> That would be my favoured route.
>>
>> Wes, side question. Using the convention plugin can you modify the stack
>> in the xml file so you don't have to annotate the action itself? Or do
>> you still have to add the annotation with the interceptor put in?
>>
>> James
>>
>> -----Original Message-----
>> From: Wes Wannemacher [mailto:wesw@wantii.com]
>> Sent: 12 May 2010 14:33
>> To: Struts Users Mailing List
>> Subject: Re: Some Spring/Struts questions
>>
>> I've seen a few responses, but I think the best way would be to write
>> an interceptor that places the bean into the session. Give it a known
>> name in the session, then you can use OGNL to access it... Here is a
>> quick example of the interceptor -
>>
>> public class CustomInterceptor extends AbstractInterceptor {
>>
>>    private SomeBeanGeneratingService someBeanGeneratingService;
>>
>>    public String intercept(ActionInvocation invocation) throws
>> Exception {
>>       invocation.getSession().put("knownBeanName",
>> someBeanGeneratingService.getBean());
>>       return invocation.invoke();
>>    }
>>
>>    public void setSomeBeanGeneratingService(SomeBeanGeneratingService
>> someBeanGeneratingService) {
>>        this.someBeanGeneratingService = someBeanGeneratingService;
>>    }
>> }
>>
>> The benefit is using an interceptor is two-fold... One is that it's
>> pretty easy to unit test (compared to a Servlet Filter). Two is that
>> it can be spring-configured and spring-injected.
>>
>> With this interceptor putting the bean into the session, you can
>> access the bean's values through OGNL. Here is an example s:property
>> tag retrieving some property -
>>
>> <s:property value="%{#session.knownBeanName.someProperty}" />
>>
>> Then, configure the interceptor and dependencies and put this
>> interceptor in your stack.
>>
>> -Wes
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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


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


Mime
View raw message