aspose file tools*
The moose likes Other Application Frameworks and the fly likes Spring data binding to hyperlink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring data binding to hyperlink" Watch "Spring data binding to hyperlink" New topic
Author

Spring data binding to hyperlink

Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
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

Joined: Jan 24, 2008
Posts: 6
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

Joined: Dec 11, 2004
Posts: 13410

"spyboost",
Please check your private messages.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
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.
 
Consider Paul's rocket mass heater.
 
subject: Spring data binding to hyperlink