MultipartRequest and form population after validation failed

2005-08-05 Thread Franz-Josef Herpers

Hi,

I've a little problem with form population after a multipart request's 
file size exceeded. What I do is testing the file size of an uploaded 
file in the validate method of a form:


  public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

String requestAttrName
= MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED;
Object o = request.getAttribute(requestAttrName);
Boolean fileLengthExceeded = (Boolean) o;

if ((fileLengthExceeded != null) && 
fileLengthExceeded.booleanValue()) {

  errors.add(ActionMessages.GLOBAL_MESSAGE,
 new ActionMessage("maxLengthExceeded"));
}

if (errors.isEmpty()) {
  errors = super.validate(mapping, request);
}

return errors;

  }

As you can see from the call to super.validate, there are some other 
fields which should be validated. When the user filled out these other 
fields correctly and uploads a file that is too big, he is forwarded too 
input page. So validation works as expected. But the problem is, that 
the values of the other fields are gone. A look in the Struts code 
reveals why: In RequestUtils#populate you can find the same test for 
file size:


Boolean maxLengthExceeded =
(Boolean) request.getAttribute(

MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
if ((maxLengthExceeded != null) && 
(maxLengthExceeded.booleanValue())) {

return;
}

And the method returns immediately, if the file size is too big. That 
means *before* the form is populated. So I populatetd the form by myself 
in the validate method by reusing code from RequestUtils, just to  find, 
that that's not the end of the story. In 
CommonsMultipartRequestHandler#handleRequest you find again this test 
and again *before* the text parameters are set.


Is there any "easy" solution for this problem and is it "stupid" to ask, 
why not populate (even if this is only for redisplaying values) the form 
or in the case of MultipartRequestHandlers, set the text parameters, 
*before* testing the file size and returning?


Thanks in advance
Franz


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Custom Validation doesn't add

2005-08-04 Thread Franz-Josef Herpers

Hi,

I ran into a strange problem with the validation of form input that 
includes an uploaded file in Struts 1.2.7. I wrote a custom validation 
method for validating the file size of an uploaded file:


 public static boolean validateFile(Object bean,
   ValidatorAction validatorAction,
   Field field,
   ActionMessages messages,
   Validator validator,
   HttpServletRequest request) {
  
   Object o = 
request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);

   Boolean fileLengthExceeded = (Boolean) o;

   if ((fileLengthExceeded != null) && fileLengthExceeded.booleanValue()) {
 messages.add(field.getKey(),
Resources.getActionMessage(request, validatorAction, 
field));

 return false;
   }

   return true;

 }

I defined a validation rule in my validator-rules.xml:

 
classname="org.uba.iuclidx.gui.web.struts.validators.FormValidator"

  method="validateFile"
  methodParams="java.lang.Object,
   org.apache.commons.validator.ValidatorAction,
   org.apache.commons.validator.Field,
   org.apache.struts.action.ActionMessages,
   org.apache.commons.validator.Validator,
   javax.servlet.http.HttpServletRequest"
  msg="errors.maxLengthFileExceeded"/>

And I added an entry for the form to be validated in validation.xml

 
 
   
 
 
   
 
 
   
   
 
   

Everything works fine, and the method is called. But if the file exceeds 
the file size defined in the controller element of struts-config.xml, I 
get the error messages of all fields for the required validation rule 
(including the file upload field!), but not the one for exceeding the 
file size. Additionally the fields contain no more values. As if the 
form has been reset after executing validateFile and then validated 
again.


Any ideas or hints?

Thanks in advance.
Franz


--
Franz-Josef Herpers

fjh consulting
Tel.: +49 30 2068 7154
Mobil: +49 173 54 23 666
VoIP: +49  948 625515
Fax: 01212 6 20687154
Puschkinallee 9A
12435 Berlin

Email: [EMAIL PROTECTED]
VoiceMail: 01212-6-20687154

http://www.fjh-consulting.de
__
http://www.openbc.com/go/invuid/FranzJosef_Herpers



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Redirect request to home if session is expired

2005-07-06 Thread Franz-Josef Herpers

Hi list members,

in my Struts-based application I want to test, if the session of the 
user is expired. If so, I want to forward/redirect the user back to the 
starting page. But this seems to be a problem, if I call an Action that 
is associated with an ActionForm in session scope. When I tried to test 
for an expired session with request.getSession(false) the session is 
never null, even if I monitor session destruction with a SessionListener 
and can be sure the session is destroyed. As the source code of 
RequestProcessor suggests, this is because a new session is created, if 
the old is expired to put the ActionForm in this session. To get around 
this situation I associated the ActionServlet with a filter and did the 
testing for expired sessions there. This works. My remaining question 
is: Is this in any way a bad design or exists other best practices for 
this scenario? I'm surely not the only one who ran into this


Thanks in advance for any hints.

Regards
Franz


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



String as Parameterwith html:link

2005-06-27 Thread Franz-Josef Herpers

Hi,

I have a question concerning the Struts-HTML-Tag . I want to 
generate a link to an action with one parameter which is a hardcoded 
String (not a value of a bean property which is present in a scope). And 
I don't want to use the url-Attribut but the action-Attribut to generate 
the link to the action. One example link could be: 
http://mydomain/setLocale.do?lang="de";.


What I'm doing now is: create a HashMap with one entry and use the 
name-Attribut:





  lang


That works fine, but just out of curiosity: Is there really no 
possibility to just provide a string via an attribute of html:link which 
then is appended literally to the generated URL as a parameter. And if 
not is there a special reason for it?


Regards
Franz


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Strut Faces and Struts 1.2

2005-06-21 Thread Franz-Josef Herpers

Hi,

just a short question: Does the latest nightly build of Struts Faces 
support Struts 1.2?


Regards
Franz


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Replace logic:messagesPresent with JSTL tags

2005-06-15 Thread Franz-Josef Herpers

Hi John,

> I think you should be able to use:


${!empty requestScope['org.apache.struts.action.ERROR']} 


as your test, since requestScope is a Map object.


Thank you. That's what I forgot: The escaping because of the periods in 
the request attribute name.


Regards
Franz


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Replace logic:messagesPresent with JSTL tags

2005-06-15 Thread Franz-Josef Herpers

Hi,

I'm using the the  tag to print out validation error 
messages. Now I want to replace the Struts logic tags with JSTL tags. 
Hence I wrote:



 
   
 
   
 
   
 
   
 


But error messages are not shown even if there is definitely an request 
attribute with the name org.apache.struts.action.ERROR.
And even more strange for me is the fact that it works if i use 
scriptlets and do it this way:


<% if (request.getAttribute("org.apache.struts.action.ERROR") != null) {%>
 
   
 
   
 
   
 
   
 
<%}%>

Thanks in advance for any hints to solve this little problem.

Regards
Franz


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Versions of commons-libs in Struts versions

2004-11-14 Thread Franz-Josef Herpers
Hi,
is there any way to find out which versions of the commons-libs are 
included in a particular version of Struts. I'm especially interested in 
versions Struts 1.1 and 1.2.4?
Thank you in advance for any hints.

Regards
Franz
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: contrib/struts-shale-mailreader

2004-11-14 Thread Franz-Josef Herpers
Hi,
is there any way to find out which versions of the commons-libs are 
included in a particular version of Struts. I'm especially interested in 
versions Struts 1.1 and 1.2.4?
Thank you in advance for any hints.

Regards
Franz
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: struts 1.1 and session handling

2004-04-15 Thread Franz-Josef Herpers
Dean A. Hoover wrote:

I am using struts 1.1 and tomcat 5 for
an application. I am also using DynaValidatorForm
for validation of form data. Here is my problem:
I want to test for (tomcat) session timeout and
output a message on the users brower stating that
their session timed out. I want to catch and process
this situation wherever it may occur. 
We use a BaseAction class for this purpose. The class extends Action and 
checks in its execute method that the session is still valid.
At the and it calls another method of this class (we called that method 
executeAction()). Of course every action then has to extend this 
BaseAction class and override the executeAction() method.

Regards
Franz
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


toUpperCase() with format attribute of tag

2004-04-13 Thread Franz-Josef Herpers
Hi *,

is it possible to use the format attribute of the  tag to do 
something like the Java method String#toUpperCase() does with strings? 
If yes, i would appreciate any hints how to force this behaviour.

Thanks in advance.

Regards
Franz
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


toUpperCase() with tag

2004-04-13 Thread Franz-Josef Herpers
Hi *,

is it possible to force the behaviour of the method String#toUpperCase() 
(i.e: "ics" => "ICS") with the format attribute of the  tag? 
If yes, i would appreciate any hints how to do it?

Thanks in advance
Franz
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]