0

My page.jsp has some html div tags inside, switching div's display to block or none as the user clicks on a corresponding anchor tag buttons.

Let's say user clicks 2nd anchor button link, approriate div having html form loads in.. There I have a file upload browse button, using interceptor below, restricting upload limit maxsize and content type:

<interceptor-ref name="fileUpload">
<param name="maximumSize">15728640</param>
<param name="allowedTypes">application/pdf</param>
</interceptor-ref>  

Then in java class extending ActionSupport, getting return type as input if in case of violation of maxsize and content type.

SO In struts.xml I defined

   <result name="input">  page.jsp </result>

But this causes page.jsp to reload, not maintaining the same html div state, i.e 2nd form of div tag,which again one has to go and click on 2nd anchor tag button, thus loading file browse form.

Rather than Keeping

<s:fielderror> </s:fielderror> 

inside of file browse form of second div tag, I can keep it at start of a body tag to display returned error message.

But I want user inputs like 'file browse path' to stay in the input fields, and error messages shows above the fields. If I can convince myself to display error messages on another jsp page, there wouldn't be so much trouble. But just to speculate, is it possible to achieve what I desired?

Ashish Kataria
  • 520
  • 3
  • 11
  • 31

1 Answers1

0
<s:if test="hasActionErrors()">
        <s:actionerror/>
</s:if>

You can put this code wherever you want to show the errors Also, if you want to show corresponding div which containes the form to show up on page load you can use the same strategy in your javascript code

<script>
 <s:if test="hasActionErrors()">
         document.getElementById("div2").display="block";//or trigger click on the corresponding link
 </s:if>
</script>

From this post

Replace with hasFieldErrors() if you are using that

Community
  • 1
  • 1
Anupam
  • 7,966
  • 3
  • 41
  • 63
  • thx anu.. but would it preserve the value of user input textbox? that is 'file browse path' to stay in the input fields.. – Ashish Kataria Jul 26 '12 at 12:37
  • 1
    page.jsp is there any way, not to define jsp page while result name, return type is input, so as to restricting it to stay on the same page! – Ashish Kataria Jul 26 '12 at 12:40
  • 1
    No,you cannot set the file tag's value,because of the security reasons.However,you can pass the filename as parameter to show it somewhere else on the page. As for your second question, in my knowledge it is also not possible. Why you dont want to give the jsp page name there? – Anupam Jul 26 '12 at 12:56
  • See http://stackoverflow.com/questions/4684013/is-it-possible-to-re-populate-a-file-select-form-field-with-what-the-user-previo – nmc Jul 27 '12 at 02:26
  • thx anu and nmc..As I will get Field errors in all of the divs, thus showing up the respective div which has ended with an error on page load would be difficult by only using because it comprises of all errors of all divs.. How to use s:param with hasFieldErrors() to filter it out..? do we have something like hasFieldErrors().fieldname ?? – Ashish Kataria Jul 27 '12 at 10:59
  • check out [this tutprial](http://thinkstruts.blogspot.in/2008/06/custom-validation-example-in-struts2.html). look at the code of header.jsp, how to iterate over field errors – Anupam Jul 27 '12 at 22:04