ActionForm Nightmare.

G

gwoodhouse

Hello again all,

I'm currently trying to get a product working here and its driving me
nuts.

Ive been working all day on a stupidly complicated way of filling form
values. Ill skip the complicated part out and give you the current
part of the problem i just cannot understand.

Basically, one of my jsp's is forwarding to search.do?
searchTermLanguage="English". This uses:

<action path="/articles/search" forward="/WEB-INF/jsp/articles/
searchForm.jsp" name="AdvancedSearchForm" validate="false"
scope="session"/>

on searchForm.jsp, there is a form input element named
"searchTermLanguage". At the point this page loads, i /thought/ that
searchTermLanguage field would automatically fill with the term
"English". But it isn't.

Could someone tell me why? pretty please? If i have to come into work
again tomorrow and sit glaring at eclipse im going to go on some sort
of spree.

Graeme
 
J

Joe Attardi

Basically, one of my jsp's is forwarding to search.do?
searchTermLanguage="English". This uses:

<action path="/articles/search" forward="/WEB-INF/jsp/articles/
searchForm.jsp" name="AdvancedSearchForm" validate="false"
scope="session"/>

on searchForm.jsp, there is a form input element named
"searchTermLanguage". At the point this page loads, i /thought/ that
searchTermLanguage field would automatically fill with the term
"English". But it isn't.
Does the AdvancedSearchForm have a setter method
setSearchTermLanguage(String)?

When you request an action in Struts, it takes the parameters passed (in
this case searchTermLanguage) and looks for a corresponding setter
method (following the normal JavaBeans convention). If it finds one, it
calls it, passing in the value.
 
G

gwoodhouse

Does the AdvancedSearchForm have a setter method
setSearchTermLanguage(String)?

When you request an action in Struts, it takes the parameters passed (in
this case searchTermLanguage) and looks for a corresponding setter
method (following the normal JavaBeans convention). If it finds one, it
calls it, passing in the value.

Yes it does,

Thanks for the suggestion, ill try debugging the setter method to see
if it does in fact set.
 
G

gwoodhouse

Yes it does,

Thanks for the suggestion, ill try debugging the setter method to see
if it does in fact set.

It seems that the value is indeed set.

I also set a break point on the reset method of my form. The problem
being that by the time it gets to the reset method the value is
already null again - its been lossed between it being set and the form
being reset as the page loads.

I guess my job now is to find why the heck the form is losing its
values! Any help would be very very very appreciated.
 
O

Owen Jacobson

Hello again all,

I'm currently trying to get a product working here and its driving me
nuts.

Ive been working all day on a stupidly complicated way of filling form
values. Ill skip the complicated part out and give you the current
part of the problem i just cannot understand.

Basically, one of my jsp's is forwarding to search.do?
searchTermLanguage="English". This uses:

<action path="/articles/search" forward="/WEB-INF/jsp/articles/
searchForm.jsp" name="AdvancedSearchForm" validate="false"
scope="session"/>

on searchForm.jsp, there is a form input element named
"searchTermLanguage". At the point this page loads, i /thought/ that
searchTermLanguage field would automatically fill with the term
"English". But it isn't.

Could someone tell me why? pretty please? If i have to come into work
again tomorrow and sit glaring at eclipse im going to go on some sort
of spree.

Graeme

Assuming for the moment that your ActionForm is being populated and
preserved for the request...

Keep in mind that struts will only populate form fields for you if you
use the <html:foo> taglib elements (<html:text>, <html:select>, etc).
It can't automatically fill in <input> elements' value attributes for
you.

You can, of course, populate the value attribute yourself if you don't
want to use the HTML taglib, using f.e. value="$
{myFormName.someProperty}".
 
G

gwoodhouse

Sorry for my late response,

I found the problem with my code: I had set the scope to "session",
this was dumping and creating a whole new form for me. Setting the
form to request instead fixed my problem.

Hope this helps anyone else that searches for a similar problem.
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top