You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by st...@gmail.com on 2010/11/30 19:02:38 UTC

Incorporating action interceptor configuration parameters into a message

Before I wrap myself around my own axle, does anyone know a straightforward
technique for substituting the maximumSize into a message property text
according to the following scenario.

        <action name="singleUpload" class="FileUploadAction"
            method="upload">
            <interceptor-ref name="fileUpload">
                <param name="maximumSize">100123</param>
                <param name="allowedTypes">
                    image/png,image/x-png
                </param>
            </interceptor-ref>
            <interceptor-ref name="basicStack" />
            <result name="input">/jsp/SingleUpload.jsp</result>
            <result>/jsp/Confirm.jsp</result>
        </action>

struts.messages.error.file.too.large=File {1} is {3} bytes which exceeds the
maximum DDDDDD

I see the value 100123 in the FileUploadInterceptor inside the
ActionInvocation, but before I write stupid code, I'd like to see if there
might be a straightforward approach.

Peace,
Scott

Re: Incorporating action interceptor configuration parameters into a message

Posted by Dave Newton <da...@gmail.com>.
Nothing up my sleeve this time.

It seems like a global property/constant would be usable, but I've never
tried to @Inject a value into both interceptors and actions, so I have no
idea if it'd work. Could be useful for a few usecases, though.

Dave

On Wed, Dec 1, 2010 at 11:38 AM, <st...@gmail.com> wrote:

> Thanks Li --
>
> This is what I was afraid of, but wanted to make sure I wasn't overlooking
> something a little more straightforward.  Before duplicating the max size
> someplace else, I'll likely get into the Container build which reads the
> xml
> files.  Somewhere in the back of my mind, it feels like I should be able to
> solve this with an @Inject.  Perhaps Dandy Dave has a solution in his back
> pocket that he would sell to the highest bidder. LOL
>
> Peace,
> Scott
>
> On Wed, Dec 1, 2010 at 9:25 AM, Li Ying <li...@gmail.com> wrote:
>
> > I have read the source code of FileUploadInterceptor.
> >
> > I think it do the message getting in it's private method, and dose not
> > use the maximumSize as a message format param.
> >
> > So I believe there is no simple way to "extract interceptor interceptor
> > param".
> >
> > The simplest way I known is, hard coding the value in your message
> > properties file, like:
> > struts.messages.error.file.too.large=File {1} is {3} bytes which
> > exceeds the maximum 100123.
> >
> > It is a little ugly, but looks like the only way.
> >
> >
> > The other way is, create a new class extend from
> > FileUploadInterceptor, and override the error message building part,
> > add the maximumSize as a message format param.
> > But it need many code, I don't think this issue is worth doing so may
> work.
> >
> >
> >
> > 2010/12/1  <st...@gmail.com>:
> > > Thanks Li --
> > >
> > > I saw what the interceptor was doing and decided that was not going to
> > > work.  Would you mind posting the "simple" technique to extract the
> > > parameter from the interceptor configuration.  I'll admit I'm not a
> Guice
> > > pro and studying the container build sent me straight to the bar last
> > night.
> > >
> > > Scott
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: Incorporating action interceptor configuration parameters into a message

Posted by st...@gmail.com.
Thanks Li --

This is what I was afraid of, but wanted to make sure I wasn't overlooking
something a little more straightforward.  Before duplicating the max size
someplace else, I'll likely get into the Container build which reads the xml
files.  Somewhere in the back of my mind, it feels like I should be able to
solve this with an @Inject.  Perhaps Dandy Dave has a solution in his back
pocket that he would sell to the highest bidder. LOL

Peace,
Scott

On Wed, Dec 1, 2010 at 9:25 AM, Li Ying <li...@gmail.com> wrote:

> I have read the source code of FileUploadInterceptor.
>
> I think it do the message getting in it's private method, and dose not
> use the maximumSize as a message format param.
>
> So I believe there is no simple way to "extract interceptor interceptor
> param".
>
> The simplest way I known is, hard coding the value in your message
> properties file, like:
> struts.messages.error.file.too.large=File {1} is {3} bytes which
> exceeds the maximum 100123.
>
> It is a little ugly, but looks like the only way.
>
>
> The other way is, create a new class extend from
> FileUploadInterceptor, and override the error message building part,
> add the maximumSize as a message format param.
> But it need many code, I don't think this issue is worth doing so may work.
>
>
>
> 2010/12/1  <st...@gmail.com>:
> > Thanks Li --
> >
> > I saw what the interceptor was doing and decided that was not going to
> > work.  Would you mind posting the "simple" technique to extract the
> > parameter from the interceptor configuration.  I'll admit I'm not a Guice
> > pro and studying the container build sent me straight to the bar last
> night.
> >
> > Scott
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Incorporating action interceptor configuration parameters into a message

Posted by Li Ying <li...@gmail.com>.
I have read the source code of FileUploadInterceptor.

I think it do the message getting in it's private method, and dose not
use the maximumSize as a message format param.

So I believe there is no simple way to "extract interceptor interceptor param".

The simplest way I known is, hard coding the value in your message
properties file, like:
struts.messages.error.file.too.large=File {1} is {3} bytes which
exceeds the maximum 100123.

It is a little ugly, but looks like the only way.


The other way is, create a new class extend from
FileUploadInterceptor, and override the error message building part,
add the maximumSize as a message format param.
But it need many code, I don't think this issue is worth doing so may work.



2010/12/1  <st...@gmail.com>:
> Thanks Li --
>
> I saw what the interceptor was doing and decided that was not going to
> work.  Would you mind posting the "simple" technique to extract the
> parameter from the interceptor configuration.  I'll admit I'm not a Guice
> pro and studying the container build sent me straight to the bar last night.
>
> Scott
>

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


Re: Incorporating action interceptor configuration parameters into a message

Posted by st...@gmail.com.
Thanks Li --

I saw what the interceptor was doing and decided that was not going to
work.  Would you mind posting the "simple" technique to extract the
parameter from the interceptor configuration.  I'll admit I'm not a Guice
pro and studying the container build sent me straight to the bar last night.

Scott

On Tue, Nov 30, 2010 at 6:48 PM, Li Ying <li...@gmail.com> wrote:

> The source code of FileUploadInterceptor is:
>
>
> http://svn.apache.org/repos/asf/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
>
> ========================================================
> ......
> if (maximumSize != null && maximumSize < file.length()) {
>            String errMsg = getTextMessage(action,
> "struts.messages.error.file.too.large", new Object[]{inputName,
> filename, file.getName(), "" + file.length()}, locale);
>
> ......
> }
> ......
> ========================================================
>
> It dose not pass the maximumSize to the message text as a param.
>
>
> So I think you have to hard code it in your message text.
> But I believe it is simple, and not extra coding need.
>
>
>
>
> 2010/12/1  <st...@gmail.com>:
> > Before I wrap myself around my own axle, does anyone know a
> straightforward
> > technique for substituting the maximumSize into a message property text
> > according to the following scenario.
> >
> >        <action name="singleUpload" class="FileUploadAction"
> >            method="upload">
> >            <interceptor-ref name="fileUpload">
> >                <param name="maximumSize">100123</param>
> >                <param name="allowedTypes">
> >                    image/png,image/x-png
> >                </param>
> >            </interceptor-ref>
> >            <interceptor-ref name="basicStack" />
> >            <result name="input">/jsp/SingleUpload.jsp</result>
> >            <result>/jsp/Confirm.jsp</result>
> >        </action>
> >
> > struts.messages.error.file.too.large=File {1} is {3} bytes which exceeds
> the
> > maximum DDDDDD
> >
> > I see the value 100123 in the FileUploadInterceptor inside the
> > ActionInvocation, but before I write stupid code, I'd like to see if
> there
> > might be a straightforward approach.
> >
> > Peace,
> > Scott
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Incorporating action interceptor configuration parameters into a message

Posted by Li Ying <li...@gmail.com>.
The source code of FileUploadInterceptor is:

http://svn.apache.org/repos/asf/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java

========================================================
......
if (maximumSize != null && maximumSize < file.length()) {
            String errMsg = getTextMessage(action,
"struts.messages.error.file.too.large", new Object[]{inputName,
filename, file.getName(), "" + file.length()}, locale);

......
}
......
========================================================

It dose not pass the maximumSize to the message text as a param.


So I think you have to hard code it in your message text.
But I believe it is simple, and not extra coding need.




2010/12/1  <st...@gmail.com>:
> Before I wrap myself around my own axle, does anyone know a straightforward
> technique for substituting the maximumSize into a message property text
> according to the following scenario.
>
>        <action name="singleUpload" class="FileUploadAction"
>            method="upload">
>            <interceptor-ref name="fileUpload">
>                <param name="maximumSize">100123</param>
>                <param name="allowedTypes">
>                    image/png,image/x-png
>                </param>
>            </interceptor-ref>
>            <interceptor-ref name="basicStack" />
>            <result name="input">/jsp/SingleUpload.jsp</result>
>            <result>/jsp/Confirm.jsp</result>
>        </action>
>
> struts.messages.error.file.too.large=File {1} is {3} bytes which exceeds the
> maximum DDDDDD
>
> I see the value 100123 in the FileUploadInterceptor inside the
> ActionInvocation, but before I write stupid code, I'd like to see if there
> might be a straightforward approach.
>
> Peace,
> Scott
>

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