2

I am displaying a list of Java objects of type documentation as follows

<c:forEach var="document" items="${documentationList}">
  <tr>
    <td valign="top" >${document.documentation}</td> <!-- c:out is not used here because, it is escaping HTML characters -->
    <td width="75" valign="top"><a href="" ><c:out value="${document.stateCode}" /></a></td>
    </c:when>
    <td width="75" valign="top"><c:out value="${document.type}" /></td>
  </tr>
</c:forEach>

State code is displayed as hyperlink. what i am trying to do is, when the link is clicked i want to pass that particular java object('document') to java controller and then display more detailed information on the new page. is there a way to this in spring ?( i am using spring MVC).

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
rohith
  • 733
  • 4
  • 10
  • 24

3 Answers3

2

You are just using regular HTTP between a browser and server.

For a GET request, you can pass information in the URL, and that's about it.

You should pass an identifier for the document (like ?docid=N) to the server as part of the URL, and then load that document on the server in the new request.

If there's no unique identifier for the document, then you would probably have to store the document in session.

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • Thank you neil, but in my case there is no unique identifier of the object in the view i am pulling data from. – rohith Dec 13 '14 at 20:07
0

You'll probably want to use sessions if you're planning on passing state around.

Couple of other posts that might help - How to use Session attributes in Spring-mvc

just a quick example - http://www.javacodegeeks.com/2013/04/spring-mvc-session-tutorial.html

Note the @SessionAttributes in the Spring controller.

//For example inside a jsp you can use -
session.setAttribute("paramName","value");

//and in a controller
@SessionAttributes("paramName")

There's lots of examples for these if you look around.

Community
  • 1
  • 1
Justin Maat
  • 1,965
  • 3
  • 23
  • 33
0

if you want to use GET method it will not so look good
The link need to be like:

 <a href="yourURL?document.documentation="+${document.documentation}+"&document.stateCode="+${document.stateCode}+
 "&document.type="+${document.type}></a>

and in your Controller something like.

@RequestMapping(value="/yourURL",method= RequestMethod.GET )
public ModelAndView doMyWork(@ModelAttribute("document" ) Document document)
{
}

OR,

to use POST you will need a form and submit it using javascript when the link is clicked

something like:

<form id="hidenForm" style="display: none;" method="POST" action="yourURL">
    <input type="text" name="document.documentation"  value="${document.documentation}"/>
    <input type="text" name="document.stateCode" value="${document.stateCode}"/>
    <input type="text" name="document.type" value="${document.type}"/>
</form>

and in javascript using jquery

fucntion submitHidden()
{
    $("#hidenForm").submit();
}

change in Controller .

@RequestMapping(value="/yourURL",method= RequestMethod.POST)
Saif
  • 6,804
  • 8
  • 40
  • 61