aspose file tools*
The moose likes JSP and the fly likes Setters not being called on bean when navigating away from JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Setters not being called on bean when navigating away from JSP page" Watch "Setters not being called on bean when navigating away from JSP page" New topic
Author

Setters not being called on bean when navigating away from JSP page

John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 73

Hi,

I have one session level object that is referenced by several wizard jsp pages, each page updating different values on the object. The pages are linked via 'next' and 'previous' buttons. The object is correctly updated when navigating between the pages. However, the last page of the wizard has a 'submit' button. The problem is, the setters for the data on the last page of the wizard are not being called when the submit button is pressed. (but they are when navigating to 'previous')

The only difference between the 'previous'. 'next' and 'submit' buttons is that the 'submit' button goes to a servlet, and the next and previous go to jsp pages.

I fiddled the html so that the submit also went to a jsp page, but it made no difference. I just can't get the last wizard page to store its changes if I click on submit.

Any help would be appreciated.

I am developing on Apache Tomcat 6.0.20.

John.


John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 73

Ok, I see what one of my problems is. I need a <setProperty property="*"> on the submit page as well. Is it possible to do this in code in a servlet?

My other problem is this... The spec for JSPs says it will not execute the setter for any value that has been set to "" or null. Why would this be a good thing? If a user sets a form value to empty, I need to know it.

The only solution I can think of to save this is to forward each Next, Previous and Submit through a servlet which uses reflection to go through all the parameters and manually set values and then forward to the 'real' next page. very annoying. Is there a better way?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

John Farrel wrote: Is there a better way?

as you said use servlet as a controller and java class as a model(for business logic) .

coming to your last page submit problem, I will give you a clue ok ?

the clue is *how you are storing the values to session from every page(submitting) ?*
John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 73


For posterity...

Firstly, I didn't realise the <jsp:setProperty .... property="*"/> needs to go in every destination jsp file, including the submit jsps.
Secondly, the <jsp:setProperty ... property="*"> setting is garbage. It ignores any input set to empty string or null values.
Instead I replaced all the setProperty tags with some third party code do the same reflection trick, but one that does not ignore empty strings and null values.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

If you're looking for best practice advice, submitting to a JSP is a big no-no. All submissions should be performed to a servlet in a modern, best-practice JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 73
Bear Bibeault wrote:If you're looking for best practice advice, submitting to a JSP is a big no-no. All submissions should be performed to a servlet in a modern, best-practice JSP.


Actually, I was and am. The jsp was just there to test a theory and has been replaced with a servlet.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

John Farrel wrote:The jsp was just there to test a theory and has been replaced with a servlet.


cool
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setters not being called on bean when navigating away from JSP page
 
Similar Threads
navigation problem
problem with registration page
multiple forms in struts
No validation before LookupDispatchAction
Multi page form handling