Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bind JSP values to controller

 
Su nan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Su nan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic