You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joachim Rohde <ma...@joachimrohde.com> on 2008/07/20 20:42:10 UTC

Re: Struts2 Fileupload user defined messages

Hi Dirk,

I had the same problem and after spending the whole day trying things 
out, I found something that works.

In WEB-INF/classes I created a class struts-messages.properties with 
following content:

struts.messages.error.uploading=Fehler beim hochladen der Datei
struts.messages.error.file.too.large=Die Datei ist zu groß!
struts.messages.error.content.type.not.allowed = Der Dateityp wird 
leider nicht unterstützt.


In my strus.properties I added:

struts.multipart.parser=org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest 

struts.multipart.maxSize=100000000
struts.custom.i18n.resources=struts-messages

My action-definition looks like:

         <action name="SaveSettings" class="saveSettings">
             <interceptor-ref name="fileUpload">
                 <param name="allowedTypes">
                     image/x-png,image/png,image/gif,image/jpeg,image/pjpeg
                 </param>
                 <param name="maximumSize">120000
                 </param>
             </interceptor-ref>
             [...]
          </action>

It seems like that the value in struts.multipart.maxSize is passed to 
commons-fileupload. If the uploaded file exceeds this value, the message 
you mentioned is displayed. BUT: if we set this value quite high (so 
that commons-fileupload is not complaining about it), the Struts 
FileUploadInterceptor checks again for the parameter maximumSize, which 
is passed in the action-definition. (In my case I don't want to have 
files bigger than 120000 bytes.) If the file-size exceeds this value, 
the message declared in struts.messages.error.file.too.large is loaded.

This behaviour is really annoying and it took an eternity to find it 
out. So let me know if this is working for you.

Greetings from Flensburg,

Joachim

Dirk Schumacher schrieb:
> Hello,
> 
> I am troubleling with the Fileupload in S2.
> 
> I want to have printed my own messages on failure of the file upload 
> which takes place in the interceptor.
> I am uploading files exceeding the set maximum size
> The documentation talks about the struts-message-properties, where is 
> declared:
> 
> struts.messages.error.uploading=Error uploading: {0}
> struts.messages.error.file.too.large=File too large: {0} "{1}" {2}
> struts.messages.error.content.type.not.allowed=Content-Type not allowed: 
> {0} "{1}" {2}
> 
> The message printed via the ActionError is complete different text I 
> cannot find in any file:
> 
> "the request was rejected because its size (2352563) exceeds the 
> configured maximum (2097152)"
> 
> Where is this Text declared?
> 
> A colleague talked about the commons-fileupload which is declaring the 
> printed text....
> The Jakarta File... seems to me the right instance of takiong care of 
> the ActionError
> 
> When looking at the sources I figured that not the FileUploadInterceptor 
> instantiates the ActionError. It is done by the
> parse()-Method of the MultipartRequestWrapper, or somewhere deeper.
> 
> So figure that the struts-message.properties is never applied and the 
> ActionError is setup in-code instead of the usage of an external 
> property file.
> 
> Is there any documentation out there on this issue? - I just want to set 
> my own (localed) messages for the different errors that may occure, just 
> like intended by the S2 FileUploadInterceptor, which seems somewhat not 
> fully useful to me right now.
> 
> I appreciate your help in advance,
> 
> best greetings from cologne,
> Dirk
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ------------------------------------------------------------------------
> 
> 
> No virus found in this incoming message.
> Checked by AVG. 
> Version: 8.0.100 / Virus Database: 270.4.0/1506 - Release Date: 17.06.2008 16:30

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


Re: [S2] Unable to access passed parameters in an included file

Posted by Paweł Wielgus <po...@gmail.com>.
Hi ,
maybe try to use tiles for this kind of job.
Did work for me.

Best greetings,
Paweł Wielgus.



On 22/07/2008, Dave Newton <ne...@yahoo.com> wrote:
> --- On Mon, 7/21/08, <Be...@mhn.com> wrote:
>  > Feels like I missed something obvious....
>
>
> The note on [1] where it says that params aren't available on the stack, I think.
>
>  I don't recall the reason at the moment, though.
>
>  Dave
>
>  [1] http://struts.apache.org/2.x/docs/include.html
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>  For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Unable to access passed parameters in an included file

Posted by Be...@mhn.com.
Thanks for the catch Dave.

Isn't it funny that they provide two examples of parameter passing in [1]?
Don't expect to be able to access those using struts tags within the
included file, ha!

I (hacked | worked around | fixed) it by using JSTL <c:set> to place those
params into the page context (and therefore the value stack):

<c:set var="nav1" value="${param.nav1}"/>

<p>
Nav 1a: <s:property value="#attr.nav1"/><br />
Nav 1b: <s:property value="%{#attr.nav1}"/><br />
Nav 1c: <s:property value="#attr['nav1']"/><br />
Nav 1d: <s:property value="%{#attr['nav1']}"/>
</p>

Nav 1a: portalAdmin
Nav 1b: portalAdmin
Nav 1c: portalAdmin
Nav 1d: portalAdmin

Thanks,
-B




                                                                           
             Dave Newton                                                   
             <newton.dave@yaho                                             
             o.com>                                                     To 
                                       Struts Users Mailing List           
             07/21/2008 05:56          <us...@struts.apache.org>            
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: [S2] Unable to access passed    
               "Struts Users           parameters in an included file      
               Mailing List"                                               
             <user@struts.apac                                             
                  he.org>                                                  
                                                                           
                                                                           
                                                                           




--- On Mon, 7/21/08, <Be...@mhn.com> wrote:
> Feels like I missed something obvious....

The note on [1] where it says that params aren't available on the stack, I
think.

I don't recall the reason at the moment, though.

Dave

[1] http://struts.apache.org/2.x/docs/include.html


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





---------------------------------------------------------------------
This message, together with any attachments, is
intended only for the use of the individual or entity
to which it is addressed. It may contain information
that is confidential and prohibited from disclosure.
If you are not the intended recipient, you are hereby
notified that any dissemination or copying of this
message or any attachment is strictly prohibited. If
you have received this message in error, please notify
the original sender immediately by telephone or by
return e-mail and delete this message, along with any
attachments, from your computer. Thank you.

---------------------------------------------------------------------

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


Re: [S2] Unable to access passed parameters in an included file

Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 7/21/08, <Be...@mhn.com> wrote:
> Feels like I missed something obvious....

The note on [1] where it says that params aren't available on the stack, I think.

I don't recall the reason at the moment, though.

Dave

[1] http://struts.apache.org/2.x/docs/include.html


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


[S2] Unable to access passed parameters in an included file

Posted by Be...@mhn.com.
Hi everyone,

I'm using <s:include> to include a page fragment in Struts 2.1.2.
(also tried with <jsp:include> and the result did not change)

Ensuring the values are passed as Strings using OGNL syntax:

<s:include value="/support/templates/header.jsp">
      <s:param name="pageTitle" value="%{'Portal Administration'}" />
      <s:param name="nav1" value="%{'portalAdmin'}" />
      <s:param name="nav2" value="%{''}" />
</s:include>


I know nav1 makes it into header.jsp as a request parameter because this
snippet yields "nav1 = portalAdmin"  (among other things)
<%
      java.util.Enumeration e = request.getParameterNames();
      while (e.hasMoreElements())
      {
            String name = (String) e.nextElement();
            out.write(" " + name + " = " + request.getParameter(name) +
"<br />");
      }
%>

(BTW, I tried removing %{''} from the <s:param> tag and nav1 was null)


In header.jsp I tried getting the value of nav1 using several different
OGNL mechanisms:

Nav 1a: <s:property value="#attr.nav1"/><br />
Nav 1b: <s:property value="%{#attr.nav1}"/><br />
Nav 1c: <s:property value="#attr['nav1']"/><br />
Nav 1d: <s:property value="%{#attr['nav1']}"/><br />


Nav 2a: <s:property value="#parameters.nav1"/><br />
Nav 2b: <s:property value="%{#parameters.nav1}"/><br />
Nav 2c: <s:property value="#parameters['nav1']"/><br />
Nav 2d: <s:property value="%{#parameters['nav1']}"/><br />


In theory all of the above should work because nav1 is a request parameter
and attr looks to request scope after page scope.

However, none of the above tags display the value of nav1.
Of course if I can't even get the value of that parameter my <s:if> logic
won't work.

Feels like I missed something obvious....



---------------------------------------------------------------------
This message, together with any attachments, is
intended only for the use of the individual or entity
to which it is addressed. It may contain information
that is confidential and prohibited from disclosure.
If you are not the intended recipient, you are hereby
notified that any dissemination or copying of this
message or any attachment is strictly prohibited. If
you have received this message in error, please notify
the original sender immediately by telephone or by
return e-mail and delete this message, along with any
attachments, from your computer. Thank you.

---------------------------------------------------------------------

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