This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

[struts 2] Use Javascript confirm() dialog  RSS feed

 
Bartender
Posts: 9511
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table of items:


The "Edit" link takes the user to the item edit page. Ideally, the Delete button would prompt the user "Do you want to delete Item 1?", the user would confirm that he does, and the list would be redisplayed without the deleted item. I can't think of a clean way to implement this functionality. I can display the Delete link thusly:



I can display the Javascript pop-up with onclick, but that will execute the action no matter what the user clicks. The only other thing I can think of is something like what Merrill posted here, but each Delete link would be a separate form. Not very clean.
 
Sheriff
Posts: 9613
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the confirm function on the onclick event of the hyperlink. You can do something like this



And this doesn't seem to be concerned with Struts to me...
 
Joe Ess
Bartender
Posts: 9511
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ankit Garg wrote:
And this doesn't seem to be concerned with Struts to me...



It's not the JavaScript that's giving me the problem. It's using Struts 2 tags with the JavaScript. The code you have given works and that's fine, but it sticks out like a sore thumb in a JSP that's entirely Struts tags. I was wondering if there's a more "Struts 2" way to accomplish the same functionality.
 
Joe Ess
Bartender
Posts: 9511
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I came up with the following. In the JSP, I just reference a property ("escape=false" writes the property as-is, without escaping HTML characters):


Then in the java bean I have a property that prints out an anchor tag with the JavaScript to do the confirmation embedded:


(sorry about the image, but JForum stripped out my JavaScript code)
It creates some ugly HTML/JavaScript, but this page will only have around 30 values, so it's Good Enough. It's not a good separation of responsibility, a data bean knowing how to display an HTML link, but it makes the JSP really clean and the bean only has one weird method. It's self-contained, which is a good thing, as opposed to having a JavaScript function elsewhere that has no connection to the tag in the JSP.

 
Ankit Garg
Sheriff
Posts: 9613
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have done something like this

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!