Hi everyone,
first time poster here and I have been googling for an answer to this for the last three days. I apologize if this has already been posted already!
I am using the following.
Spring 3 MVC, Apache tiles, Hibernate as the JPA. I use Spring roo as the code generate. I currently using eclipse as an IDE.
I am trying to implement the following controller that can take the output of the form.
Please see the wire frame below.
test.jpg
Use case:
If I click on the submit button in the filters tile on the left hand side. I want all the classes (lessons) that I have checked to be filters that determine the output of the classes that are run in the right hand content. For now, I will sue two basic fileds in this example, the startdate and enddate files. Where the start date field is a field you state you wish to start on and the end date is the last date you would consider starting on.
There are two main issues I have currently.
1> The request mapping and how the form integrates into the page.
2> How to structure the query to get the desired effect.
code created so far - ps this code does not work at present. (it's currently broken)
Controller LectureController.java
The Lecture.java has many methodes however the two methods that are important to this example are below.Code:@RequestMapping(produces = "text/html") public String list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, @RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate, @Valid lecture lecturefilter, Model uiModel) { if (page != null || size != null) { int sizeNo = size == null ? 10 : size.intValue(); final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo; uiModel.addAttribute("events", lecture.findlectureEntries(firstResult, sizeNo, startDate, endDate)); float nrOfPages = (float) Event.countEvents() / sizeNo; uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages)); } else { uiModel.addAttribute("lecture", lecture.findAllEvents(startDate, endDate)); } addDateTimeFormatPatterns(uiModel); return "lecture/list"; }
(I need to include the following mysql queries in here)
http://www.artfulsoftware.com/infotree/queries.php#576
current lecturefilter.jsp (the tile that goes into the left hand menu in the wireframe)Code:public static List<Event> findAllEvents() { return entityManager().createQuery("SELECT o FROM Event o", Event.class).getResultList(); } public static List<Event> findEventEntries(int firstResult, int maxResults) { return entityManager().createQuery("SELECT o FROM Event o", Event.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList(); }
current list.jsp (the tile that goes into the right hand content tile in the wire frame)HTML Code:<div id="navFilter" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form"> <form:form method="Post" action="lectureFilter.jsp" commandName="lecturefilter"> <h1>Event Filter</h1> <h2>Data Range</h2> <form:input path="startDate"/><h2> to </h2> <form:input path="endDate"/> <input type="submit" value="Search"/> <input type="reset" value="Reset"/> </form:form> </div>
My head is about to explode with all these things I have to keep in mind. any help is valued and appreciated. If I am doing this all the wrong way, please let me know.HTML Code:<?xml version="1.0" encoding="UTF-8" standalone="no"?> <div xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:page="urn:jsptagdir:/WEB-INF/tags/form" xmlns:table="urn:jsptagdir:/WEB-INF/tags/form/fields" version="2.0"> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <jsp:output omit-xml-declaration="yes"/> <page:list id="lecture_data_lecture" items="${events}" z="qlZXZpm/HrI6BBepeL9Y3/Q29NU="> <table:table data="${lecture}" id="lecture_data_lecture" path="/lecture" z="9pLdDAMURB73KCEBQlRkffi1iHU="> <table:column id="lecture_data_lecture_owner" property="owner" z="ROGv1xAsVKN9Esevg4buuRkMbBo="/> <table:column id="lecture_data_lecture_title" property="title" z="88gXXze1ali0jJ98NQSYOf6fSfk="/> <table:column id="lecture_data_lecture_description" property="description" z="JC2myl01760Lo1rUh3pGoALM4jg="/> <table:column id="lecture_data_lecture_location" property="location" z="fbOUCOvesZ0pE6HYXQYvuiPz4dg="/> <table:column date="true" dateTimePattern="${event_startdate_date_format}" id="c_uk_co_oxconsulting_events_data_Event_startDate" property="startDate" z="gBzZJT629VPCwpWqZ7q/HRQtBPo="/> </table:table> </page:list> </div>
So basically how do you create a form that acts as a search filter (modifies the mysql query) on the items you want look for in the database?
Please save me from this nightmare.


Reply With Quote