Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using form:select data on same page

 
Michael Jammy
Greenhorn
Posts: 11
Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
rinku agarwal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try by writing javascript method which will be called on the onChange event of select element.
 
Michael Jammy
Greenhorn
Posts: 11
Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Jammy
Greenhorn
Posts: 11
Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 11
    Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 65115
    89
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So you are saying it all works when you use vanilla HTML, but not when you use Spring tags? Correct?
     
    Miku Ranjan
    Ranch Hand
    Posts: 98
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,
    Can you explain which tag library you are using for this tag.
     
    Michael Jammy
    Greenhorn
    Posts: 11
    Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes, it works in vanila html, but not like this. The tags I use:
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65115
    89
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic