Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Spring data binding to hyperlink

Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

My question is related to data binding in Spring using a command object. I am using the SimpleFormController.

I have a command object which has a few drop down list and text input elements that are bound to it. This works fine and when the user selects an option from the list or enters text, the values are being bound to the command.

Now I want to click on a hyperlink and bind it to the command too - so that I know in my controller that this link was clicked. I have in my jsp

<a href="javascript: showAll()" name="showAllAction" value="1">Show All</a>

In the above I have a variable int showAllAction; defined in my command pojo.

The problem is that the anchor <a> element does not have the "value" attribute defined for it, so I get a warning in the jsp. My command variable "showAllAction" is null always, and I cannot identify when the hyperlink is clicked. Since both <input> and <option> elements have the value attribute I do not face any problems here.

There must be a way to bind other elements like hyperlinks etc to the command object? Does anybody know how?

If not is there any workaround for this? Any help much appreciated!
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, may be my solution will be helpful for your trouble.
Try to do the following:

Then, in your method showAll() just add at the end something like this:

May be this is not so elegant solution but I hope that it will help to set the appropriate value to the variable showAllAction of your command object.
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check your private messages.
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Ben,

I checked my private messages and I did not receive any messages from you.

However, I ahve found the answer to my question!! And it is soo simple just like the beauty of Spring. For hyperlinks - all you need is

<a href="myLink.htm?myBindingVar=99 ">

now if you have a variables in your command object pojo called myBindingVar it will be bound to the value set here once the link is clicked!!
Its as simple as.

Thanks folks for your input anyways!

    Bookmark Topic Watch Topic
  • New Topic