• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Same Form, More than Once

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic