Solved

not able return the list in the jsp

Posted on 2014-04-13
5
399 Views
Last Modified: 2014-04-28
Hi,

I have a piece of code  in a  controller which  has a  method to display the list of item
 from the data base  i.e i could see the data in the sop but not able to display the data
in the jsp .  

 what could be the reason...

Thank you
 java code
//Display listExistingRights(/) 
	@RequestMapping(value = "tile/list")
	public ModelAndView existRights
	( Model model, HttpServletRequest request) {

		List<WebdUserRight> maintainrights = new ArrayList<WebdUserRight>();

		EntityManager em = DataAccess.emf.createEntityManager();

		try {
			maintainrights = WebdUserRight.findAll(em);
			model.addAttribute("maintainrights", maintainrights);
			for (WebdUserRight rights : maintainrights) {
				System.out.println("rights: " + rights.getCode() + ", drsc: "                                          +  rights.getDescrip());

			/
	
			}
		} finally {
			em.close();
			
			
			
		}
		return new ModelAndView( "tile/mainRights", "maintainrights", maintainrights);

Open in new window


in jsp i use

<tbody>
    <c:forEach var="rights" items="${maintainrights}" varStatus="idx">
		<tr data-right-id="${rights.code}" >
			<td style="width:30px;text-align: center;">
        	    <img class="addEditRights" style="cursor:pointer;" src="/asset/image/silk/edit.png" />
 			</td>
			<td>${rights.code}</td>
			<td>${rights.descrip}</td>
		</tr>
    </c:forEach>
  </tbody>

Open in new window



on click event when i call  the above jsp page it donot display anything

$( "#MaintainRights").click( function() {

document.location.href = "/tile/mainRights.html?maintainrights="+maintainrights;
 });

Open in new window

0
Comment
Question by:roy_sanu
  • 3
5 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
Comment Utility
you should call your controller and in turn it will redirect to the jsp page..

see this example

call the servlet like this.

http://localhost:8080/SpringMVC/registerNewMember

<code>

@Controller
@RequestMapping(value="/")
public class MemberController
{
   
      
      

    @RequestMapping(value="/registerNewMember",method=RequestMethod.GET)
    public ModelAndView registerNewMember()
    {
          List<Member> maintainrights = new ArrayList<Member>();
          
          Member m = new Member();
          m.setId(new Long(1));
          m.setName("aaaa");
          
          Member m1 = new Member();
          m1.setId(new Long(2));
          m1.setName("bbbbbbbb");
          
          maintainrights.add(m);
          maintainrights.add(m1);

          System.out.println("maintainrights....."+maintainrights.size());
            
          return new ModelAndView( "index", "maintainrights", maintainrights);
    }
}

</code>

<code>
      <c:forEach items="${maintainrights}" var="member">
                                                      <tr>
                                                            <td>${member.id}</td>
                                                            <td>${member.name}</td>
                                                            <td>${member.email}</td>
                                                            <td>${member.phoneNumber}</td>
                                                            <td><a href="<c:url value="/rest/members/${member.id}"/>">/rest/members/${member.id}</a></td>
                                                </c:forEach>
</code>
0
 
LVL 20

Expert Comment

by:chaitu chaitu
Comment Utility
apart from that you cannot send the object in the url


$( "#MaintainRights").click( function() {

document.location.href = "/tile/mainRights.html?maintainrights="+maintainrights;
 });
0
 

Author Comment

by:roy_sanu
Comment Utility
There is no problem with the controller sending to the jsp.. As with the debug i could see the  value... but  i think the issue is how am i going to pass the object to url  

"it should happen on click of the button, but this does not work even i change to below code.. It goes to the url but do not give me any data
$( "#MaintainRights").click( function() {

document.location.href = "/tile/mainRights.html"
 }); 

Open in new window

0
 
LVL 20

Expert Comment

by:chaitu chaitu
Comment Utility
where should it go?should it go to controller or jsp?first it should go to controller and then should redirect to jsp right,..

"/tile/mainRights.html"
0
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
Comment Utility
I think that
@RequestMapping(value = "tile/list")
shoud be changed to
@RequestMapping(value = "/tile/mainRights")
then your link in JS should be changed to:
document.location.href = "/tile/mainRights";
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now