I'm trying to create a search form that, when submitted, displays the search results on the same page. Right now I am encountering an infinite loop due to my action mapping (included below). What's happening (I stepped through using remote debugging) is that my actionform validate AND my actual action which does the search is being executed even before the page is rendered. I can understand the actionform but why is the action being executed? The action returns to the success mapping which is the same page.. resulting in the infinite loop. Incase it gets asked.. I do have to have them both on the same page.
What is the "best practices" way to tell an action not to execute unless submit is clicked.. query string parameters for example?
-- exceprt from struts-config.xml <form-bean name="search" type="forms.searchFormBean"/>
Both your input and your ActionForward are mapped back to MySearchAction. Try pointing them to a jsp instead of an Action. What's happening is you are chaining the Action to itself, the result of which is as you've noticed, an infinite loop.
And.. the loop also happened when the input attribute was not there on the action mapping.
So, should I make the link *to* this search page (e.g. the link from other pages) go to the SearchPage tile (not sure how to do that).. right now I link right to Search.do which I guess is why the action is executing?
Thanks for such a quick response by the way!
Joined: Nov 09, 2000
The input parameter of the <action> element refers to the page that called the Action. So if your search form is calling the action, then your input parameter should point back to that page. If that's the case, your action mapping in the struts-config should look something like this:
Your search page view, as you've named it in your tiles-def, is SearchPage. Therefore that is the view that you need to forward to on success, as illustrated in the above code fragment.