aspose file tools*
The moose likes JSP and the fly likes How do I resolve this? Adding loop item to a list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How do I resolve this? Adding loop item to a list" Watch "How do I resolve this? Adding loop item to a list" New topic
Author

How do I resolve this? Adding loop item to a list

Pojahn Moradi
Greenhorn

Joined: Apr 26, 2013
Posts: 2


When I click on the submit button, the specified item shoud be added to the item-list/cart. However, I am not getting the result I am expecting.
What is happening is that when the page have loaded, the "onclick" function have executed on all the items in the loop.

How do I resolve this?
What options do I have besides "onclick", which seems buggy?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Pojahn Moradi wrote:What options do I have besides "onclick", which seems buggy?

onclick is not buggy; your code is.

You are mixing server-side code with client-side code; and the two cannot be mixed. Please read this article to understand how JSP operates and why what you are trying to do makes no sense.

You need to deal with client-side actions such as button clicks with JavaScript on the client; not JSP on the server.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pojahn Moradi
Greenhorn

Joined: Apr 26, 2013
Posts: 2
You are right. It makes more sense now. Sill clueless on how to resolve this issue.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

First item of advice: ditch the Java scriptlets. They've been obsolete for over 12 years and should no longer be used on JSP pages. Learn to use the JSTL and EL instead. See this JspFaq entry.

Advice #2: with your new knowledge of how JSP works, you'll need to sit back and rethink your approach. Your original approach assumed that you'd be able to add to the list in real time as buttons are clicked. Not so. To make any changes to the server, you need to go back with a new request -- either a link, a form or an Ajax request.

All of that requires a major refactor from the start. So don't try to band-aid what you've got; it's just going to lead to frustration. Sit back and think about how you can approach this knowing that once the JSP executes and sends the HTML to ther browser that you've got to wait for a new request to come back to do anything else.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I resolve this? Adding loop item to a list