Announcement Announcement Module
Collapse
No announcement yet.
Customizing views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Customizing views

    I've developed roo mvc project for crud app.
    As of now, I'm able to see, list, delete or update data.

    now i want filtered list, like only those data which has value greater than 500, but i dont want to use finder, as i have stable filter requirment

    how i can do this, using spring mvc, as roo created much complex UI??

    for primary i created new link in menu.jspx which says go for customized list, what to do next??

  • #2
    So here's list link provided in menu.jspx

    <menu:item id="i_employee_list" messageCode="global_menu_list" url="/employees?page=1&amp;size=${empty param.size ? 10 : param.size}" z="IfTXfF5mBLDCW+DUkfuN3Wgvias="/>
    <menu:item id="i_employee_blacklistA" messageCode="global_menu_list" url="/employees?page1=1&amp;size=${empty param.size ? 10 : param.size}" z="user-managed"/>

    then this is code written in controller: for normal list:

    @RequestMapping(produces = "text/html")
    public String list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, 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("employees", Employee.findEmployeeEntries(firstResult, sizeNo));
    float nrOfPages = (float) Employee.countEmployees() / sizeNo;
    uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
    } else {
    uiModel.addAttribute("employees", Employee.findAllEmployees());
    }
    addDateTimeFormatPatterns(uiModel);
    return "employees/list";
    so i wrote for second list as follows:

    @RequestMapping(produces = "text/html")
    public String blacklist(@RequestParam(value = "page1", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, 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("employees", Employee.findAllBlacklisted_reqEmployees(firstResu lt, sizeNo));
    float nrOfPages = (float) Employee.countBlacklist_reqEmployees()/ sizeNo;
    uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
    }
    addDateTimeFormatPatterns(uiModel);
    return "employees/blacklist";
    }

    but now im getting error as Ambiguous mapping found. Cannot map 'employeeController' bean method[/SIZE]

    Comment


    • #3
      I am not an expert at this yet, but I think the fact that your @RequestMapping has two of the exact same signatures is your issue. You will need something unique for the second function so that the system knows how to treat it uniquely.

      Comment


      • #4
        thats true,
        dilemma is i dont knw how to change signature.

        Can you please help me in that??

        Comment


        • #5
          e.g.
          Code:
          @RequestMapping(produces = "text/html", params = "page")

          Comment


          • #6
            I guess i've done same thing:


            @RequestParam(value = "page1", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel)

            Comment


            • #7
              forget it;


              just tell me how i can show two list-views of same class.


              1st one is created by default by roo. Now i want another one whch will gave me only that data which cntains salary>500

              Comment


              • #8
                Right, but @RequestMapping != @RequestParam
                You get this error (Ambiguous mapping found), because you have two identical request mappings (@RequestMapping(produces = "text/html")). To distinguish them you can do something like I posted before.

                If you want to show second list with different data, you have to modify query in your function in domain model (findAllBlacklisted_reqEmployees(firstResult, sizeNo)). You can try something like this:
                Code:
                public static List<your.domain.Employee> findAllBlacklisted_reqEmployees(int firstResult, int maxResults) {
                        return entityManager().createQuery("SELECT o FROM Emplyee o WHERE o.salary > 500", Employee.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();}
                Of course it's not the best way to do something like this, because hard-coded queries are not very elegant and could be problematic in later stage of development, but it works. Better way is to use some external parameters to set up salary.

                Comment


                • #9
                  Thanks a lot sir,
                  Indeed its not best method, but works absolutely fine!!!

                  Comment

                  Working...
                  X