Announcement Announcement Module
Collapse
No announcement yet.
finder with OR logic and required fields Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • finder with OR logic and required fields

    I have added a finder

    finder add --finderName findConfigurationsByConfigurationNameLikeOrConfigu rationSectionLikeOrConfigurationValueLike

    Where the entity Configuration has three string fields ConfigurationValue, ConfigurationName and ConfigurationSection.

    The problem I have is that the find form has all the fields but you cannot enter a value in just one as it throws

    Code:
    Required String parameter 'configurationName' is not present
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.raiseMissingParameterException(AnnotationMethodHandlerAdapter.java:717)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:501)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:340)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    The entity Controller.aj has

    Code:
    @RequestMapping(params = "find=ByConfigurationNameLikeOrConfigurationSectionLikeOrConfigurationValueLike", method = RequestMethod.GET)
        public String ConfigurationController.findConfigurationsByConfigurationNameLikeOrConfigurationSectionLikeOrConfigurationValueLike(@RequestParam("configurationName") String ConfigurationName, @RequestParam("configurationSection") String ConfigurationSection, @RequestParam("configurationValue") String ConfigurationValue, Model uiModel) {
            uiModel.addAttribute("configurations", Configuration.findConfigurationsByConfigurationNameLikeOrConfigurationSectionLikeOrConfigurationValueLike(ConfigurationName, ConfigurationSection, ConfigurationValue).getResultList());
            return "configurations/list";
        }
    I found the Controller_Finder.aj and pushed that in.

    I modified the applicable find method in the Controller.

    Code:
    @RequestMapping(params = "find=ByConfigurationNameLikeOrConfigurationSectionLikeOrConfigurationValueLike", method = RequestMethod.GET)
        public String findConfigurationsByConfigurationNameLikeOrConfigurationSectionLikeOrConfigurationValueLike(@RequestParam(required = false, value = "configurationName") String ConfigurationName, @RequestParam(required = false, value = "configurationSection") String ConfigurationSection, @RequestParam(required = false, value = "configurationValue") String ConfigurationValue, Model uiModel) {
            uiModel.addAttribute("configurations", Configuration.findConfigurationsByConfigurationNameLikeOrConfigurationSectionLikeOrConfigurationValueLike(ConfigurationName, ConfigurationSection, ConfigurationValue).getResultList());
            return "configurations/list";
        }
    to add the @RequestParam(required = false,

    I also modified the finder method in the entity...after pushing that in from the Finder.aj

    Code:
    public static TypedQuery<Configuration> findConfigurationsByConfigurationNameLikeOrConfigurationSectionLikeOrConfigurationValueLike(String ConfigurationName, String ConfigurationSection, String ConfigurationValue) {
            if (ConfigurationName == null || ConfigurationName.isEmpty()){
            	ConfigurationName = "";
            } else {
    			ConfigurationName = ConfigurationName.replace('*', '%');
    	        if (ConfigurationName.charAt(0) != '%') {
    	            ConfigurationName = "%" + ConfigurationName;
    	        }
    	        if (ConfigurationName.charAt(ConfigurationName.length() - 1) != '%') {
    	            ConfigurationName = ConfigurationName + "%";
    	        }
            }
            if (ConfigurationSection == null || ConfigurationSection.isEmpty()){
            	ConfigurationSection = "";
            } else {
    	        ConfigurationSection = ConfigurationSection.replace('*', '%');
    	        if (ConfigurationSection.charAt(0) != '%') {
    	            ConfigurationSection = "%" + ConfigurationSection;
    	        }
    	        if (ConfigurationSection.charAt(ConfigurationSection.length() - 1) != '%') {
    	            ConfigurationSection = ConfigurationSection + "%";
    	        }
            }
            if (ConfigurationValue == null || ConfigurationValue.isEmpty()){
            	ConfigurationValue = "";
            } else {
    	        ConfigurationValue = ConfigurationValue.replace('*', '%');
    	        if (ConfigurationValue.charAt(0) != '%') {
    	            ConfigurationValue = "%" + ConfigurationValue;
    	        }
    	        if (ConfigurationValue.charAt(ConfigurationValue.length() - 1) != '%') {
    	            ConfigurationValue = ConfigurationValue + "%";
    	        }
            }
            EntityManager em = Configuration.entityManager();
            TypedQuery<Configuration> q = em.createQuery("SELECT o FROM Configuration AS o WHERE LOWER(o.ConfigurationName) LIKE LOWER(:ConfigurationName)  OR LOWER(o.ConfigurationSection) LIKE LOWER(:ConfigurationSection)  OR LOWER(o.ConfigurationValue) LIKE LOWER(:ConfigurationValue)", Configuration.class);
            q.setParameter("ConfigurationName", ConfigurationName);
            q.setParameter("ConfigurationSection", ConfigurationSection);
            q.setParameter("ConfigurationValue", ConfigurationValue);
            return q;
        }
    But, while the find no longer throws errors, it also doesn't find anything with our without * or % characters.

    Stumped.

  • #2
    Originally posted by MikeOliverAZ View Post
    But, while the find no longer throws errors, it also doesn't find anything with our without * or % characters.

    Stumped.
    So I created same entities in new project and simple finder on just the ConfigurationName, no modifications, plain out of the box...

    Code:
    Requested Resource Not Found
    
    Sorry, we did not find the resource you were looking for.
    
    Details
    
    Required String parameter 'configurationName' is not present
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.raiseMissingParameterException(AnnotationMethodHandlerAdapter.java:717)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:501)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:340)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    So, turns out it probably doesn't have anything to do with my changes, it is something else.

    Here is the roo.log on the simple test.

    Code:
    // Spring Roo 1.1.5.RELEASE [rev d3a68c3] log opened at 2011-09-06 09:37:37
    project --topLevelPackage com.corenttech.cockpit --projectName SimpleRooFindTest --java 6
    // Spring Roo 1.1.5.RELEASE [rev d3a68c3] log closed at 2011-09-06 09:37:40
    // Spring Roo 1.1.5.RELEASE [rev d3a68c3] log opened at 2011-09-06 09:37:46
    persistence setup --database HYPERSONIC_PERSISTENT --provider HIBERNATE 
    entity --class ~.model.Tenant
    field string AddressLine1
    field string AddressLine2
    field number --fieldName BannerId --type java.lang.Long
    field string City
    field string Country
    field string --fieldName Description --notNull false --nullRequired false --sizeMax 255 --transient false --unique false --permitReservedWords false 
    field string Email
    field number --fieldName MtsId --type java.lang.Long
    field string OrganizationName
    field string PhoneArea
    field string PhoneNumber
    field string PostalCode
    field string TenantName
    field string StateOrProvince
    field string TimeZone
    enum type --class ~.model.UserApprovalTypeEnum
    enum constant --name MANUAL
    enum constant --name AUTOMATIC
    focus --class com.corenttech.cockpit.model.Tenant
    field enum --fieldName UserApprovalType --type com.corenttech.cockpit.model.UserApprovalTypeEnum --enumType STRING 
    field number --fieldName UserLimit --type java.lang.Integer
    field string Website
    entity --class ~.model.Configuration
    field string ConfigurationSection
    field string ConfigurationName
    field string ConfigurationValue
    web mvc setup 
    web mvc all --package ~.web
    focus --class com.corenttech.cockpit.model.Tenant
    finder add --finderName findTenantsByTenantNameLike
    focus --class com.corenttech.cockpit.model.Configuration
    finder add --finderName findConfigurationsByConfigurationNameLike
    // script --file "C:\Users\Corent CTO\IBM\Documents\workspace-sts-2.6.1.RELEASE\SimpleRooFindTest\SimpleFind.roo" --lineNumbers false 
    // Spring Roo 1.1.5.RELEASE [rev d3a68c3] log closed at 2011-09-06 09:47:24
    Is it Hypersonic? Is it that I added the finders after the web mvc all?

    CRUD works ok on all entities and fields.

    Comment


    • #3
      I went back to Roo 1.1.4 and moved the finder add before the web mvc all and no change, the same "Required String parameter 'configurationName' is not present"

      Comment


      • #4
        switched to MySql and no change.

        Comment


        • #5
          Ok, zeroing in.

          If my entity field names are CamelCase the form looks great but the corresponding fieldName camelCase is not found in the request.

          If my entity field names are lowercase then the form looks but the finder works. I guess I can fix the forms easier than the plumbing.

          Comment

          Working...
          X