aspose file tools*
The moose likes Struts and the fly likes Same Form, More than Once Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Same Form, More than Once" Watch "Same Form, More than Once" New topic
Author

Same Form, More than Once

Zachary Wright
Greenhorn

Joined: Aug 04, 2008
Posts: 6
Hello, this is my first topic here, and thanks for deciding to read it.

I'm currently working on a project using Struts 1, and as a Struts newbie I'm having some trouble managing one of the pages that I'm working on. I've spent a lot of time trying to learn how struts works and how to use it effectively, but like I said, I'm still a newbie to it.

I have five jsp's created, four of these jsp's are the four possible views for when a user is navigating a 4-tabbed menu on a certain part of the website. They all use the same form, but each jsp allows the user to enter and manage different information.

The fifth jsp is a new one I'm creating, which offers a sort of "quick search" functionality, that the user can use to stay on the same screen and "view", but load up a different set of data. I already have the search functionality created. My problem is that I want this new, quick search jsp to use the same form and the same action that the other jsp's are using, since they are all closely related. I just needed to add a few form parameters to the form, and a new step to the action, and I thought I was good to go. The new quicksearch jsp is a tile, when I use to show it at the top of the other views, represented by each of the other jsps. I did this because I didn't want to replicated the exact same code four times.

However, I am having a problem. Since I have two jsp's using the same form on the same page, I think that when a user submits the "quicksearch" form, the parameters are immediately reset by the second instance of the same form on that page, and none of the parameters are getting passed to the action. Or something to that effect, I have print statements inside the action class, and they are consistently printing "null" for all the form parameters entered into the search bars. I have checked the getter and setter methods and my tags, and everything looks correct.

Now I'm just wondering if it's possible to even do this, have two jsp's using the same form on the same page. If not, is it possible to move the <html:form "/..."></form> tags into a base file that sort of wraps all the other jsp's?

Any help is greatly appreciated, I've been agonizing over this for a few days now.


Thanks,
ZW
[ August 04, 2008: Message edited by: Zachary Wright ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I have five jsp's created, four of these jsp's are the four possible views for when a user is navigating a 4-tabbed menu on a certain part of the website. They all use the same form, but each jsp allows the user to enter and manage different information.


When each JSP page displays different information and contains a HTML form, it should have its own ActionForm.

If mutliple JSP pages display the same information, they may all share a single HTML form and related ActionForm.

Once you change your design to match what I state above, things will be a bit easier and you will be able to move along with the work.

My problem is that I want this new, quick search jsp to use the same form and the same action that the other jsp's are using, since they are all closely related.


This is a "cooky" design. Your "quick search" JSP page serves a different purpose than the other pages. It should have its own Action and its own ActionForm. "closely related" and "identical" are not the same.


Good luck!
[ August 04, 2008: Message edited by: James Clark ]
Zachary Wright
Greenhorn

Joined: Aug 04, 2008
Posts: 6
Thank you for the help, I have taken your advice and created a new form and action for my quick search jsp.

I thought for sure this would solve the problem, but oddly it didn't. I'm wondering if I'm doing something else wrong.

In my jsp I have a few javascript functions, one to read in keystrokes in case a user clicks "enter", to perform the search. The other builds an "onclick" string and does a changeAction using that onclick string. The form parameter for the current "view" in the menu is passed in in the URL, something like "blah.do?step=quickSearch&submitAction=quickSearch¤tView=<view>"

The four possible search parameters are set in text boxes, like:
<html:text property="searchCustomerName" style="font: verdana; font-size: 12px;" />

However, whenever I type something into that box (or any of the other boxes), and hit the submit button, which calls the javascript function which builds the onClick and does the changeaction, they are always null. The getter and setter methods are all spelled correctly, and my IDE (Intellij IDEA 7.0.3) doesn't find any errors on my jsp page or in the form and action.

The quickSearch jsp is still a tile, being placed on each of the other four pages created by the other jsps, which use a different form.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
However, whenever I type something into that box (or any of the other boxes), and hit the submit button, which calls the javascript function which builds the onClick and does the changeaction, they are always null. The getter and setter methods are all spelled correctly, and my IDE (Intellij IDEA 7.0.3) doesn't find any errors on my jsp page or in the form and action.


The first thing I would do find out what the problem is to modify the submit button to call the Struts Action directly. Once you get the form working correctly, then you can add the JavaScript call and see if you still have an issue.

Work with the JSP page directly first before including it in the other JSP pages as a Tile.

Either your form is not configured right or the JavaScript is not making the call properly to the Struts Action. Don't expect your IDE to identify application/coding errors such as the ones you currently have.
[ August 05, 2008: Message edited by: James Clark ]
Zachary Wright
Greenhorn

Joined: Aug 04, 2008
Posts: 6
Thanks very much for the help, it did end up being a problem with the way the tiles were set up, and things seem to be working well now with my form parameters being set correctly.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Same Form, More than Once