3 Replies Latest reply: Sep 27, 2013 4:39 PM by Eelse RSS

    Programatically Creating View Criteria - Problem

    svn123

      Hi folks,

       

      Today I gave a try to this blog post on the CASE 2: I want to create a view criteria dynamically and execute it programmatically.

      Oracle ADF: ADF - Programatically Applying and Creating View Criteria

       

      But it is not working for me.

      I have a method in Application module implementation

       

      public void searchByDeptId(Number did,String dname){
              ViewObjectImpl vo = getDepartmentsView1();
              ViewCriteria vc = vo.createViewCriteria();
              ViewCriteriaRow vcr = vc.createViewCriteriaRow();
              vcr.setAttribute("DepartmentId", did);
              vcr.setAttribute("DepartmentName", dname);
              vc.addRow(vcr);
              vo.applyViewCriteria(vc);
              vo.executeQuery();
             }
      

       

       

      public String cb1_action() {
              BindingContainer bindings = getBindings();
              OperationBinding operationBinding = bindings.getOperationBinding("searchByDeptId");
              operationBinding.getParamsMap().put(did, did.getValue());
              operationBinding.getParamsMap().put(dname, dname.getValue());
              System.out.println("hi" +did.getValue());
              Object result = operationBinding.execute();
              if (!operationBinding.getErrors().isEmpty()) {
                  return null;
              }
              return null;
          }
      

       

       

      <af:form id="f1">
              //from here two fields for search -- start
          <af:inputText label="Label 1" id="it5"
                            binding="#{backingBeanScope.Mbean.did}"
                            autoSubmit="true"/>
              <af:inputText label="Label 2" id="it6"
                            binding="#{backingBeanScope.Mbean.dname}"
                            autoSubmit="true"/>
              <af:commandButton
                                text="searchByDeptId"
                                disabled="#{!bindings.searchByDeptId.enabled}"
                                id="cb1"
                                action="#{backingBeanScope.Mbean.cb1_action}"
                                partialTriggers="pfl1" partialSubmit="true"/> //here ended
      
      
      //here result shoul show in another panel form layout
              <af:panelFormLayout id="pfl1" partialTriggers="cb1">
                <af:inputText value="#{bindings.DepartmentId.inputValue}"
                              label="#{bindings.DepartmentId.hints.label}"
                              required="#{bindings.DepartmentId.hints.mandatory}"
                              columns="#{bindings.DepartmentId.hints.displayWidth}"
                              maximumLength="#{bindings.DepartmentId.hints.precision}"
                              shortDesc="#{bindings.DepartmentId.hints.tooltip}"
                              id="it1">
                  <f:validator binding="#{bindings.DepartmentId.validator}"/>
                  <af:convertNumber groupingUsed="false"
                                    pattern="#{bindings.DepartmentId.format}"/>
                </af:inputText>
                <af:inputText value="#{bindings.DepartmentName.inputValue}"
                              label="#{bindings.DepartmentName.hints.label}"
                              required="#{bindings.DepartmentName.hints.mandatory}"
                              columns="#{bindings.DepartmentName.hints.displayWidth}"
                              maximumLength="#{bindings.DepartmentName.hints.precision}"
                              shortDesc="#{bindings.DepartmentName.hints.tooltip}"
                              id="it3">
                  <f:validator binding="#{bindings.DepartmentName.validator}"/>
                </af:inputText>
                <af:inputText value="#{bindings.ManagerId.inputValue}"
                              label="#{bindings.ManagerId.hints.label}"
                              required="#{bindings.ManagerId.hints.mandatory}"
                              columns="#{bindings.ManagerId.hints.displayWidth}"
                              maximumLength="#{bindings.ManagerId.hints.precision}"
                              shortDesc="#{bindings.ManagerId.hints.tooltip}"
                              id="it2">
                  <f:validator binding="#{bindings.ManagerId.validator}"/>
                  <af:convertNumber groupingUsed="false"
                                    pattern="#{bindings.ManagerId.format}"/>
                </af:inputText>
                <af:inputText value="#{bindings.LocationId.inputValue}"
                              label="#{bindings.LocationId.hints.label}"
                              required="#{bindings.LocationId.hints.mandatory}"
                              columns="#{bindings.LocationId.hints.displayWidth}"
                              maximumLength="#{bindings.LocationId.hints.precision}"
                              shortDesc="#{bindings.LocationId.hints.tooltip}"
                              id="it4">
                  <f:validator binding="#{bindings.LocationId.validator}"/>
                  <af:convertNumber groupingUsed="false"
                                    pattern="#{bindings.LocationId.format}"/>
                </af:inputText>
              </af:panelFormLayout>
            </af:form>
      

       

      if i put the dept id or dept name in input text box by pressing the button i can't able to get that search result where am missing.

      thanks.

        • 1. Re: Programatically Creating View Criteria - Problem
          Frank Nimphius-Oracle

          Hi,

           

          1. try a longer scope for the managed bean holding the input data. Try view scope. (Auto-submit performs a request. After this however your managed bean is reset in backing bean scope, which means that dname is set back to whatever the default is

          2. Use the debugger and look at what gets passed to the managed bean and also what is received by the method on the AM

           

          Frank

          • 2. Re: Programatically Creating View Criteria - Problem
            svn123

            hi frank,

             

            Eventhough i put autosubmit on that particular fields. i can able to get the value using s.o.p

            and i changed to viewscope. no luck.


            thanks

            • 3. Re: Programatically Creating View Criteria - Problem
              Eelse

              Hi,

               

              in your action method, you gave the following:

               

              1. operationBinding.getParamsMap().put(did, did.getValue()); 
              2. operationBinding.getParamsMap().put(dname, dname.getValue()); 


              Are did and dname pointers to the binding components? Or did you have a typo in this code? I think it should be this instead (with the parameter names being Strings not components):


              1. operationBinding.getParamsMap().put("did", did.getValue()); 
              2. operationBinding.getParamsMap().put("dname", dname.getValue());


              The names of the parameters should be the same as configured in the methodAction for the application module method in the page definition file.

               

              Regards,

              Eelse