This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes struts2 workflow question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 workflow question" Watch "struts2 workflow question" New topic
Author

struts2 workflow question

Billy Vandory
Ranch Hand

Joined: Mar 23, 2010
Posts: 57
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

Joined: Sep 29, 2008
Posts: 12617

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
 
subject: struts2 workflow question
 
Similar Threads
Error while validating the input
struts-html.tld not found help me please
Form Data not being populated in Struts 2
Error setting the expression with value [Ljava.lang.String;@1d05b0a
global properties file