This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes Using form:select data on same page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Using form:select data on same page" Watch "Using form:select data on same page" New topic
Author

Using form:select data on same page

Michael Jammy
Greenhorn

Joined: Sep 21, 2011
Posts: 11

Hello all,

I have a question with regards to using the form:select data on the same page it has been selected. Let's say I have this in my form:

"<form:input path="cartProductPrice" value="${cart.cartProductPrice}" />" already has a value that it will display (from a database). I want to multiply the value that has been selected in the form:select on the same page... so the cartProductQuantity.value * the ${cart.cartProductPrice} and c:out it.

Anyone have any idea how I would go about doing that?


Oracle Certified Java Programmer 6
rinku agarwal
Greenhorn

Joined: Feb 10, 2010
Posts: 6
You can try by writing javascript method which will be called on the onChange event of select element.
Michael Jammy
Greenhorn

Joined: Sep 21, 2011
Posts: 11

rinku agarwal wrote:You can try by writing javascript method which will be called on the onChange event of select element.

Thank you for your response. However, I would rather not use any javascript in my pages. I would prefer using taglib.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

Michael Jammy wrote: I would rather not use any javascript in my pages. I would prefer using taglib.

Well that's just not going to happen.

The JSP executes on the server to send a complete HTML page to the browser where the user can interact with it. If you want something to happen at that point you're going to need to use JavaScript. The only other choice is to post the entire page back and recompute it as it if were 1998.

Please read this article to understand what JSP is and how it operates.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael Jammy
Greenhorn

Joined: Sep 21, 2011
Posts: 11

Bear Bibeault wrote:
Michael Jammy wrote: I would rather not use any javascript in my pages. I would prefer using taglib.

Well that's just not going to happen.

The JSP executes on the server to send a complete HTML page to the browser where the user can interact with it. If you want something to happen at that point you're going to need to use JavaScript. The only other choice is to post the entire page back and recompute it as it if were 1998.

Please read this article to understand what JSP is and how it operates.


Maybe there is another way doing what I want to do then. Basically I have a shopping cart page, this shopping cart page contains products. I've created this selection form so that I can select the number of products I want. What I want to achieve is that when the number of products are changed in the selection form, that it automatically changes the total value. It doesn't matter if the page is refreshed, as long as the new quantity number is there and it's multiplied by the price single product price.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

As already stated you have two choices:

  • Employ a modern technique, using JavaScript to simply add the values and update the display in-place.
  • Party like it's 1998 and submit the whole page and use server-side mechanisms to repaint the whole page with new values.

  • The former is far easier and faster. Both involve JavaScript. So using the latter mechanisms doesn't seem to make much sense as it has to use JavaScript and a whole lot of needless server-side goop.

    If you are a web developer and you are trying to avoid learning JavaScript.... well, lets just say that you are heading towards a very hard brick wall.
    Michael Jammy
    Greenhorn

    Joined: Sep 21, 2011
    Posts: 11

    I'll take your word for it. I've tried the following to see if I can access the value. However, it gives me an error.
    in <head>


    in <body> (code has been simplified for readability)


    When I change the selection value, I encounter the following error:


    I've tried it with a plain html form and it works. I've also tried it by removing the taglib prefixes and that also works. However, I want to access that value in the above form.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60739
        
      65

    So you are saying it all works when you use vanilla HTML, but not when you use Spring tags? Correct?
    Miku Ranjan
    Ranch Hand

    Joined: Oct 11, 2011
    Posts: 98
    Hi,
    Can you explain which tag library you are using for this tag.
    Michael Jammy
    Greenhorn

    Joined: Sep 21, 2011
    Posts: 11

    Yes, it works in vanila html, but not like this. The tags I use:
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60739
        
      65

    OK, then you need to compare what the tags are generating to the vanilla HTML and see what's different.

    I've moved this too the Spring forum.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Using form:select data on same page
     
    Similar Threads
    Spring MVC Request Mapping
    AbstractWizardFormController: teasing command object
    Populate MultiSelect Dojo box onLoad from XML data file
    Getting the below error when doing formvalidation in spring
    problem while loading the welcome page