File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Bind JSP values to controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Bind JSP values to controller" Watch "Bind JSP values to controller" New topic
Author

Bind JSP values to controller

Su nan
Greenhorn

Joined: Jun 19, 2012
Posts: 4
I am working on a spring 3.1 app. I have a jsp where I display a list of projects (displayed as links) - Project name is displayed which is one of the fields in Project entity.
On click of any of these projects, I need to fetch that project name in the controller(If possible the whole Project entity) and display fruther details of same project.

Problem is, I am not able to retrieve the Project name that is clicked on by the user:
Below is the snippet from my JSP and controller where I am trying to fetch:

JSP:
<form action="viewDashboard" class="simple_form" id="tProject" name="tProject" method="post">
<c:forEach items="${projList}" var="tProject" >
<tr> <td>
<a href="./viewDashboard" id="tProject.prjName" name="tProject.prjName" value="${tProject.prjName}"> ${tProject.prjName} </a>
</td> </tr>
</c:forEach>

CONTROLLER:
@Controller
@RequestMapping("/login/viewDashboard")
public class DashBoardController {

@Autowired
DashBoardService dashBoardService;

@RequestMapping(method = RequestMethod.GET)
// @ModelAttribute("projList")
public String displayDashboardTProject tProject, BindingResult bindingResult) {
System.out.println("Proj Name:" + tProject.getPrjName()); //This displayes null now
return "Dashboard";
}

}

Can someone please point what is wrong here or if Iam completly not making any sense !!!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

You could just add it to the end of the URL as a request parameter

so

${tProject.prjName}

becomes

${tProject.prjName}

In your controller method that takes that request have a parameter for the projectName like

public blah myMethod(@RequestParam(projectName) String projectName) {


Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Su nan
Greenhorn

Joined: Jun 19, 2012
Posts: 4
Thanks Mark. But If I use @requestParam in my controller as mentioned, it throws "The request sent by the client was syntactically incorrect ()" error.
This is how I am doing:

public String displayDashboard(@RequestParam("prjName")String prjName, BindingResult bindingResult) {

Also is there any other way since we are trying not to pass it in the url.. Can the annotation @modelAttribute be used.
If Yes, how do I make use of it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bind JSP values to controller