• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

struts2 workflow question

Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my index.jsp I have a link that goes to a registration.jsp page. The book I am reading (Struts 2 in Action) says best practice is to route simple requests through actions. Ok, so in my index.jsp I have a link:

And in my struts-config.xml I have a simple action to act as a passthrough

In Register.jsp I display a form:

The action is Register and I define that in struts-config.xml

So far so good. In my Register action (RegisterAction.class), I do some validation:

If there are validation errors, the error gets printed - great.

If there are no validation errors, the page is *redirected* to the homePage action.

If the user ends up on the Register.jsp page and bookmarks it, when he returns to that page via the bookmark, an NPE is generated because emailAddress is null. But in all examples I've seen with validation, I do not see any checks for null when validating a field.

How does one prevent bookmarking this page, (because that kind of breaks the workflow of the pages anyway) or is there a way not to validate if the page is being rendered for the first time?



Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For clarity, a user doesn't "end up on Register.jsp page", they end up on an action that forwards to that page: it's an important distinction.

It's your code that's assuming the presence of the variable rather than checking for null or empty (like with StringUtils.isBlank()). You don't prevent the bookmarking of a page--even if you could, it'd be irrelevant, since the user could just type in the URL manually. If a user goes directly to Register, bypassing the input method, you have to take it into account. There are a number of ways to do that, including just checking for nulls, or deciding to handle GET and POST requests differently, just showing the validation messages, and so on.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic