handling exceptions in struts form bean reset()

W

willirl

What method should I use to report exceptions that occur in a struts
form bean reset() method. Since the reset doesn't throw any exceptions
I can't just rethrow it. I would prefer some method that reports the
error to the client somehow.

Any ideas would be appreciated.

Will
 
S

Sudsy

What method should I use to report exceptions that occur in a struts
form bean reset() method. Since the reset doesn't throw any exceptions
I can't just rethrow it. I would prefer some method that reports the
error to the client somehow.

I'd like to know how on earth you're generating exceptions in reset!
According to the javadocs for the method:
"Reset bean properties to their default state, as needed. This method
is called before the properties are repopulated by the controller.

The default implementation does nothing. In practice, the only properties
that need to be reset are those which represent checkboxes on a session-
scoped form. Otherwise, properties can be given initial values where the
field is declared."

So where could an exception be raised?
 
W

willirl

Perhaps I should have said this is my first foray into Struts.

What I'm trying to do is on the first display of a JSP I have 3 combo
boxes that I want the selected value to be 3 values from some cookies.
I got it working by sticking the code into the reset() which does the
job but I felt wasn't the "correct" place for it.

Let's say you have a form element you need to initialize with the value
from a cookie. Where do you put that?
 
S

Sudsy

Perhaps I should have said this is my first foray into Struts.

What I'm trying to do is on the first display of a JSP I have 3 combo
boxes that I want the selected value to be 3 values from some cookies.
I got it working by sticking the code into the reset() which does the
job but I felt wasn't the "correct" place for it.

Let's say you have a form element you need to initialize with the value
from a cookie. Where do you put that?

Now we're getting somewhere! Use the html:select tag with the value
attribute set to the element which should be selected. Populate with
either the html:eek:ption or html:eek:ptions tag.
I've written a couple of articles you might wish to peruse; they even
include sample code!
<http://www.sudsy.net/technology/struts-advanced.html>
<http://www.sudsy.net/technology/struts-more.html>
 
W

willirl

I read the articles and my code basically follows the Struts best
practices. Except for the cookie part. I understand that the form
will be initialized by calling the get...() methods for the form
elements. What I had a hard time with was how to set the initial value
in the form bean from a cookie. Do you know of any best practices for
this situation? Should all the logic be in the form bean reset() as I
have it? Other alternatives?
 
S

Sudsy

I read the articles and my code basically follows the Struts best
practices. Except for the cookie part. I understand that the form
will be initialized by calling the get...() methods for the form
elements. What I had a hard time with was how to set the initial value
in the form bean from a cookie. Do you know of any best practices for
this situation? Should all the logic be in the form bean reset() as I
have it? Other alternatives?

Have you looked at bean:cookie tag?
And no, no logic should ever exist in the reset method.
 
W

willirl

Yes, at one point I had a logic:present "cookies" tag in my JSP and
loaded the initial value that way. However this just didn't feel right
so I moved it. There is the add'l problem of how do I populate the
form element from the cookie only on the first run of the JSP?
Wouldn't the formBean value override any "local" JSP value that I set
from the cookie?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Throwing exceptions from entity bean lifecycle methods 4
Struts Reset 0
Exception Handling 33
struts <bean help 0
struts form bean 1
Handling *unchecked* exceptions. 2
Registration form 13
Error Handling 27

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top