• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bind JSP values to controller

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!!
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic