2 Replies Latest reply on Jan 10, 2009 3:06 AM by jerry426

    reading a form value in EntityHome constructor - how??

    jerry426

      I have the following EntityHome constructor (part of this is obviously psuedocode):



      public TicketList() { 
         if (theFormField > 0) {   
            EJBQL += " WHERE id IN (" + StringUtils.join(someMethod(theFormField), ",") + ")";  
         }
          
         setEjbql(EJBQL);
         setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
         setMaxResults(25);
      }



      I cannot figure out how to access theFormField from inside the constructor. Any suggestions? Or should I be doing this some other way?

        • 1. Re: reading a form value in EntityHome constructor - how??
          jerry426

          I meant to say EntityQuery, not EntityHome!

          • 2. Re: reading a form value in EntityHome constructor - how??
            jerry426

            I figured out a solution to my problem. I was trying to get access to a submitted form value in my EntityQuery constructor (which was originally created by seam-gen), however, every other way to do it I could find would not work in the constructor.


            Perhaps there's a cleaner/better way to do this - but it's working well so I'm happy :-)


            My relevant class level declarations:


            // WHERE 1=1 is in here so we can simply append AND statements elsewhere in this class.
            private String EJBQL = "SELECT ticket FROM Ticket ticket WHERE 1=1";
            
            // this gives us direct access to the RequestParameterMap.
            private Map<String, String> requestParameters = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();



            Then I made an override for getEjbql() like this:


            @Override
            public String getEjbql() {
                      
               applyGroupFilter();
               applyDateRangeFilter();
               applyLocationFilter();
                           
               return EJBQL;
                      
            }



            then I can modify EJBQL:


            private void applyGroupFilter() {
                      
               List<String> groupList = someMethod(requestParameters.get("groupId"));
            
               // make sure the SQL is harmlessly valid if groupList is empty
               groupList.add("-1"); 
            
               // and add the list to the EJBQL
               EJBQL += " AND id IN (" + StringUtils.join(groupList, ",") + ")";
                      
            }



            Now when the rest of the framework code executes, it will get the modified EJBQL value.