Results 1 to 6 of 6

Thread: Allowing empty finder fields

  1. #1
    Join Date
    Dec 2011
    Location
    Paris, France
    Posts
    58

    Default Allowing empty finder fields

    Hello,

    I have generated a multifield finder using the following roo command:

    finder add --finderName findPhotosBySlugLikeAndBudgetLikeAndProjectLikeAnd ProjectStatusLike

    Unfortunately, the search only works if the user fills the four fields ("slug", "budget", "project" and "projectStatus"), although most users only fill one or two fields.

    Which code should I override in the project (java, javascript, AspectJ, ...) to let users leave particular search fields empty?

    input.aspx, form.jspx, Java files generated by AspectJ code?

    Many thanks.

    Philroc

  2. #2
    Join Date
    Mar 2007
    Posts
    561

    Default

    Push in the finder from the <Entity>_Roo_Finder.aj into <Entity>.java and change the code here.

  3. #3
    Join Date
    Dec 2011
    Location
    Paris, France
    Posts
    58

    Default Overriding methods

    Quote Originally Posted by spgmx View Post
    Push in the finder from the <Entity>_Roo_Finder.aj into <Entity>.java and change the code here.
    Thanks spgmx.

    However, Eclipse won't let me "override" the method in <Entity>.java.

    For instance, here's the Roo-generated Photo_Roo_Finder.aj code:

    -----------------------------------

    // WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
    // You may push code into the target .java compilation unit if you wish to edit any member(s).

    privileged aspect Photo_Roo_Finder {

    public static TypedQuery<Photo> Photo.findPhotosBySlugLikeAndBudgetLikeAndProjectL ikeAndProjectStatusLike(
    String slug, String budget, String project, String projectStatus) {

    if (slug == null || slug.length() == 0) throw new IllegalArgumentException("The slug argument is required);
    ...

    -----------------------------------------------

    If I add the "findPhotos..." method in Photo.java file, Eclipse tells me that it already exists (ie, in the
    .aj file).

    If, on the other hand, I rename it in the Photo class, as follows

    ---------------------------------------------------

    ...
    @RooJpaActiveRecord(finders = { "findPhotosBySlugLikeAndBudgetLikeAndProjectLikeAn dProjectStatusLike2" })
    ...


    public static TypedQuery<Photo> Photo.findPhotosBySlugLikeAndBudgetLikeAndProjectL ikeAndProjectStatusLike2(..

    String slug2 = "";

    if (slug == null) || slug.length == 0) {
    slug2 = "";

    } else {
    slug2 = slug;

    }
    // Do a search with slug2 as value.

    --------------------------------------

    ...the web application crashes with an internal error:

    -----------------------------

    or.apache.tiles.impl.CannotRenderException: JSP Exception including path '/WEB-INF/views/photos/findPhotosBySlugLikeAndBudgetLikeAndProjectLikeAnd ProjectStatusLike.jspx'


    -----------------------------

    Many thanks.

    Philroc

  4. #4
    Join Date
    Mar 2007
    Posts
    561

    Default

    Select the method in the AspectJ-File in Package-Explorer or Outline View. Right-click and chose Refactor|Push in..
    This will remove it from the aj-File and put it into the java-file. In Java the method has no prefix "Photo." then, because this would not compile.

    Btw.: slug2 = "" leads to a seach for "" or null, this is definitely not what you want. I bet you want to exclude this param from your query.

  5. #5
    Join Date
    Dec 2011
    Location
    Paris, France
    Posts
    58

    Default

    Thank you very much spgmx. I will try that tomorrow.

  6. #6
    Join Date
    Dec 2011
    Location
    Paris, France
    Posts
    58

    Default

    Tried Pushing in and it worked.

    Now I can modify my 'find' code.

    However, modifying Java code to handle cases when users do not input values in the form fields, does not seem very efficient.

    Is there a more direct way to tell Roo not to make particular search-form fields mandatory?

    I have set the 'required' variable in form/input.tagx to 'false', but, once again, this does not seem very efficient.

    Philroc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •