Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring data binding to hyperlink

 
Meghna Bhardwaj
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!
 
Sergey Chunayev
Greenhorn
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"spyboost",
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!

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic