• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DynaValidatorForm not redisplaying scoped variables

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using standard JSTL, I have a simple form in my app that pre-populates a couple of fields with corresponding properties of a scoped transfer object (at the request level). For example, a typical line would like this:

<tr><td>Master Class Name:</td><td><html:text readonly="true" property="mclassname" value="${mclassname}"/></td></tr>

You can see that the value of ${mclassname} pre-populates the Master Class Name field. Upon submission, if an error occurs (via the DynaValidatorForm) the ${mclassname} does not re-appear in the Master Class Name.

How do I get that value to re-appear in my form.

Thanks in advance.

Scott
 
Scott Updike
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I figured out how to display previous values in <html:text></html:text> tags, but what if the ${mclassname} (again scoped in the request) is in some text on the screen? When the error screen appears, this field is blank and hence the text is not very user friendly.

So I'd like to ask the same question more genericaly. How do I access a request scoped attribute in the resulting error screen once the DynaValidatorForm has failed validation?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Scott Updike:
How do I access a request scoped attribute in the resulting error screen once the DynaValidatorForm has failed validation?


You don't. This has nothing to do with a Struts limitation. It has to do with the way Java EE Web Containers work.

Request scope means just that: It exists for the life of one request to the server and is gone after that. Once your Action class forwarded to the JSP and the container processed the JSP and sent the plain HTML back to the browser, the request that was used during the creation of the JSP became out of scope. Even before the user re-submitted the page, the request was gone with no chance of getting it back.

There are several ways to work around this:
  • Put your variables in session scope rather than request scope
  • Use ActionForm properties rather than request scoped variables. ActionForm variables are carried forward from page to page even if the ActionForm itself is in request scope. If you have an ActionForm property for which there is no input field on the page and you want to preserve its value, put it in an <html:hidden> tag.
  • Use client-side validation with JavaScript. That way if an error is reported, the page is not refreshed, so the fact that the variables are out of scope is not an issue.
  •  
    Ranch Hand
    Posts: 948
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I am not completely sure what your question is or if Merrill has provided an answer...

    If you are saying that you have a piece of text that is shown on the page that is not in a editable field and you need to show this text when the page is refreshed after validation you have a couple options. If you put the value in an hidden field (html:hidden) the value will be submitted on the request with the rest of the form values. Another option is to populate the value on the form in the action that shows the page after the validation error. A hidden field works well for a few text fields. The second option is better if you need to reload a lot of fields or lists of data.

    - Brent
     
    reply
      Bookmark Topic Watch Topic
    • New Topic