0

I am trying to create a custom list from Spring MVC.

The main issue is I can't find any great sources on how to create a custom list... But here is the design I want and some code I have already.

Design enter image description here

Code

JSP frontpage.jsp

<div id="result-panel">
            <ul>
            <c:forEach var="listValue" items="${offenderlists}">
                <li>OffenderId: <c:out value="${listValue.offenderId}"/> <li>
                </c:forEach>
            </ul>
        </div>

Java controller

@RequestMapping(value = "/", method = RequestMethod.POST)
    public String someMethod(@RequestParam("intelvalue") String valueOne) {
        ApplicationContext context = 
                new ClassPathXmlApplicationContext("Spring-Module.xml");
            OffenderDAO offenderDAO = (OffenderDAO) context.getBean("offenderDAO");
            Offender[] offenders = null;

            try {
                offenders = offenderDAO.requestOffenders(valueOne);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace(); 
            }
            for(Offender o: offenders) 
                System.out.println("offender: "+ o.OffenderId);
            ModelAndView model = new ModelAndView("frontpage");
            model.addObject("offenderlists", offenders);
            // Returned the list of offenders to jsp here...
            return "frontpage";
    }

I know I am doing it wrong I have in image url in the offender object along with everything I need I have no issues loading the offenders from my database. How do I create a list of offenders as show in design?

QUESTION How to create what is show in design with Spring MVC Models? Offender objects are loaded and data is within the objects I just need to display in list form how would I go at doing such?

References below were viewed and didn't provide a good enough example/answer. References: List<Foo> as form backing object using spring 3 mvc, correct syntax?

http://www.mkyong.com/spring-mvc/spring-mvc-and-list-example/

3 Answers 3

0

You may use a layout like in the fiddle below. http://jsfiddle.net/josangel555/oahkou2f/

Instead of the text's, you can use values like ${listValue.property}.

Sign up to request clarification or add additional context in comments.

2 Comments

The main issue isn't how it's displayed its that I can't get <c:out value="${listValue.offenderId}"/> to display anything
can't you simply give ${listValue.property}
0

The reason why the didn't display is because I didn't return ModelAndView as the return value of the method name somemethod

Comments

0

try

<div id="result-panel">
   <ul>
      <c:forEach var="listValue" items="${offenderlists}">
         <li>OffenderId: ${listValue.offenderId}<li>
      </c:forEach>
   </ul>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.