File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts2 workflow question

 
Billy Vandory
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • 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?

Thanks,

Billy

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic