12 Replies Latest reply on Oct 9, 2013 1:56 PM by Brian Leathem

    How to add another Filter ?

    Asim Shaikh Novice

      I have two filters YearFilter and MonthFilter  YearFilter working fine but MonthFilter not working How can I add this MonthFilter

       

       

      <rich:select value="#{eventMaster.caseYearId}"
                   onchange="this.form.submit()"
                   disabled="#{eventMaster.viewMode}"
                   styleClass="rf-sel"
                   enableManualInput="true"
                   immediate="true" >
          <f:selectItem itemValue="0" itemLabel="" />
          <f:selectItems value="#{eventMaster.yearDropDown}" />
      </rich:select>
      
      <rich:select value="#{eventMaster.caseMonthId}"  
                   onchange="this.form.submit()"
                   disabled="#{eventMaster.viewMode}"
                   styleClass="rf-sel"
                   enableManualInput="true"
                   immediate="true" >
          <f:selectItem itemValue="0" itemLabel="" />
          <f:selectItems value="#{eventMaster.monthDropDown}" />
      </rich:select>
      

       

      public void valueChangeListener(ValueChangeEvent event)  {
          Integer sessionFilterYear = (Integer) event.getNewValue();
      
          FacesContext facesContext = FacesContext.getCurrentInstance();
          HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
      
          if (sessionFilterYear != null) {
              session.setAttribute("eventyearfilter", sessionFilterYear);
          }
      }
      
      
        • 1. Re: How to add another Filter ?
          Asim Shaikh Novice
          <h:selectOneMenu value="#{eventMaster.yearFilter}"
                           onchange="submit()"
                           valueChangeListener="#{eventMaster.valueChangeListener}">
              <f:selectItems value="#{eventMaster.yearDropDown}" />
          </h:selectOneMenu>
          
          <h:selectOneMenu value="#{eventMaster.monthFilter}"
                           onchange="submit()"
                           valueChangeListener="#{eventMaster.monthValueChangeListener}">
              <f:selectItems value="#{eventMaster.monthDropDown}" />
          </h:selectOneMenu>
          
          
          

           

          public void valueChangeListener(ValueChangeEvent event) {
              Integer sessionFilterYear = (Integer) event.getNewValue();
              FacesContext facesContext = FacesContext.getCurrentInstance();
              HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
          
              if (sessionFilterYear != null) {
                  session.setAttribute("eventyearfilter", sessionFilterYear);
              }
          
              //log.info("CaseMaster:valueChangeListener():event.getNewValue():::" + event.getNewValue());
          
              //log.info("CaseMaster:valueChangeListener():this.yearFilter:::" + this.yearFilter);
              //log.info("HAS BEEN CALLED");
          }
          
            public void monthValueChangeListener(ValueChangeEvent event) {
                                   Integer sessionFilterMonth = (Integer) event.getNewValue();
          
              FacesContext facesContext = FacesContext.getCurrentInstance();
              HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
          
              if (sessionFilterMonth != null) {
                session.setAttribute("eventmonthfilter", sessionFilterMonth);
              }
          
              //log.info("CaseMaster:valueChangeListener():event.getNewValue():::" + event.getNewValue());
          
              //log.info("CaseMaster:valueChangeListener():this.yearFilter:::" + this.yearFilter);
              //log.info("HAS BEEN CALLED");
          }
          
          
          

           

          but this is also not working???

          • 2. Re: How to add another Filter ?
            Brian Leathem Master

            What do you mean by "is not working"?  Please describe:

            1. What you *expect* to observe.
            2. What you *actually* observe.
            • 3. Re: How to add another Filter ?
              Asim Shaikh Novice

              I allready have yearFilter and it is working smoothly but now I wanted to add MonthFilter I have created another valueChangeListener (monthValueChangeListener) but it is not working

              what changes I need to do in List ???

               

              public List<EventMasterBean> getEventMasterList() {
                  if ((this.inputSearch == null || this.inputSearch.equals("")) && this.searchVariableAvailable == false) {
                    this.eventMasterList = new ArrayList<EventMasterBean>();
                    EventMasterOps opsObj = new EventMasterOps();
                    if (this.yearFilter == 0 ) {
                        System.out.println("IN EventMaster getEventMasterList()::1: "+this.yearFilter);
                        defaultSetYearFilter(); 
                    }
                    opsObj.init(Integer.toString(this.yearFilter));
                    this.eventMasterList = opsObj.getEventmaster();
                  } else if (this.inputSearch != null && this.searchVariableAvailable == false) {
                    searchInputScreenRecords();
                  }
                  return this.eventMasterList;
              }
              

               

              searchInputScreenRecords in this method I am calling query () to search All records

              • 4. Re: Re: How to add another Filter ?
                Brian Leathem Master

                rather than using the change event to trigger the javascript submit() method, try nesting an ajax behaviour in your component, as in:

                 

                <rich:select ...>
                  <f:selectItems ... />
                  <a4j:ajax event="change" />
                </rich:select>
                
                • 5. Re: Re: How to add another Filter ?
                  Asim Shaikh Novice

                  did not get the Expected Results I need to change something in getEventMasterList() this List Fetching

                  • 6. Re: How to add another Filter ?
                    Asim Shaikh Novice

                    I have made following changes in my list and now it is showing Current month  bur still not showing other months correctly

                     

                    public List<EventMasterBean> getEventMasterList() {
                            if ((this.inputSearch == null || this.inputSearch.equals("")) && this.searchVariableAvailable == false) {
                                this.eventMasterList = new ArrayList<EventMasterBean>();
                                EventMasterOps opsObj = new EventMasterOps();
                                if (this.yearFilter == 0 && this.monthFilter.equals("")) {
                                  System.out.println("IN EventMaster getEventMasterList()::1: "+this.yearFilter);
                                  defaultSetYearFilter();
                              } else if (this.yearFilter != 0 && !this.monthFilter.equals("")) {
                                  opsObj.init(Integer.toString(this.yearFilter),"");    // added a  new variable in method name
                                  this.eventMasterList = opsObj.getEventmaster();
                              }else if (this.yearFilter != 0 && !this.monthFilter.equals("")) {
                                  opsObj.init(Integer.toString(this.yearFilter),(this.monthFilter));
                                  this.eventMasterList = opsObj.getEventmaster();
                              }if ((this.yearFilter == 0) && (!this.monthFilter.equals(""))) {
                                  defaultSetYearFilter();
                                   opsObj.init(Integer.toString(this.yearFilter),(this.monthFilter));
                                  this.eventMasterList = opsObj.getEventmaster();
                              }       
                      opsObj.init(Integer.toString(this.yearFilter),(this.monthFilter));
                                this.eventMasterList = opsObj.getEventmaster();
                            } else if (this.inputSearch != null && this.searchVariableAvailable == false) {
                                searchInputScreenRecords();      
                            }
                            return this.eventMasterList;
                        }
                    
                    1 of 1 people found this helpful
                    • 7. Re: How to add another Filter ?
                      Brian Leathem Master

                      Can you post the facelet code that accompanies the above java changes?

                      • 8. Re: How to add another Filter ?
                        Asim Shaikh Novice

                        Hi Brian I am sending you my code

                        <tr> 
                            <td width="20%" class="inputtext"><h:outputText value="#{lbl['label.eventyear']}"/></td> <td>
                        <rich:select value="#{eventMaster.caseYearId}" disabled="#{eventMaster.viewMode}"
                        styleClass="rf-sel" enableManualInput="true" ><f:selectItem itemValue="0" itemLabel="" />
                           <f:selectItems value="#{eventMaster.yearDropDown}" />  </rich:select>
                          </td> <td> </td>  </tr>
                        
                          <tr> <td> </td>
                        <td class="inputtext"><h:outputText value="#{lbl['label.eventdecription']}"/></td>
                        <td><h:inputTextarea rows="3" cols="50" styleClass="max" size="500"
                          readonly="#{eventMaster.viewMode}"   value="#{eventMaster.eventDesc}"/></td><td> </td> </tr>
                          <tr>
                          <td> </td>
                        <td class="inputtext"><h:outputText value="#{lbl['label.eventtype']}"/></td>
                        <td>
                        <rich:select value="#{eventMaster.eventTypeId}"
                          disabled="#{eventMaster.viewMode}"
                        styleClass="rf-sel" enableManualInput="true">
                          <f:selectItem itemValue="0" itemLabel="" />
                          <f:selectItems value="#{eventMaster.eventTypeDropDown}"/>
                          </rich:select>
                          </td><td> </td></tr>
                          <tr>
                          <td> </td><td width="40%" class="formtdwidth">
                        <h:outputText value="#{lbl['label.eventdate']}" /> </td>
                        <td> <rich:calendar value="#{eventMaster.eventDate}"
                          popup="#{eventMaster.popup}" datePattern="#{eventMaster.pattern}" showApplyButton="#{eventMaster.showApply}" cellWidth="24px" cellHeight="22px" style="width:200px"
                        disabled="#{eventMaster.disabled or eventMaster.viewMode}">
                        </rich:calendar>
                          </td><td> </td>
                          </tr>
                        <all command buttons for save edit update delete>
                        
                        <tr>
                        
                        <td width="30%" align="left"> 
                          <h:selectOneMenu value="#{eventMaster.yearFilter}" onchange="submit()" immediate="true"
                        
                        valueChangeListener="#{eventMaster.valueChangeListener}" >
                           <f:selectItems value="#{eventMaster.yearDropDown}" />
                        </h:selectOneMenu>
                        <h:selectOneMenu value="#{eventMaster.monthFilter}"  onchange="submit()" immediate="true"
                          valueChangeListener="#{eventMaster.monthValueChangeListener}">
                        <f:selectItems value="#{eventMaster.monthDropDown}" />
                         </h:selectOneMenu>
                             </td>
                        </tr>
                        
                        
                        <rich:dataTable value="#{eventMaster.eventMasterList}" var="event" id="table"
                                        rows="10" style="width:100%;border: 2px;"
                                      reRender="datascroller">
                        
                            <rich:column style="width:5%;">
                                <f:facet name="header">
                        
                                </f:facet>
                                <h:selectBooleanCheckbox value="#{event.checked[event.eventId]}"/>
                            </rich:column>
                            <rich:column style="width:3%;" sortBy="#{event.eventId}" filter="#{event.eventId}"
                                         filterEvent="onkeyup"
                                         sortOrder="#{dataTableStateHolder.sortOrders[event.eventId]}"
                                         filterValue="#{dataTableStateHolder.columnFilterValues[event.eventId]}">
                                <f:facet name="header">Event Id</f:facet>
                                <h:outputText value="#{event.eventId}"/>
                            </rich:column>
                        
                            <rich:column style="width:7%;">
                                <f:facet name="header">Case No.</f:facet>
                                <h:outputText value="#{event.caseNo}"/>
                            </rich:column>
                        
                            <rich:column style="width:12%;">
                                <f:facet name="header">Event Schedule</f:facet>
                                <h:outputText value="#{event.eventDateString}"/>
                            </rich:column>
                        
                            <rich:column style="width:10%;">
                                <f:facet name="header">Event Type</f:facet>
                                <h:outputText value="#{event.eventTypeDesc}"/>
                            </rich:column>
                        
                            <rich:column style="width:35%;">
                                <f:facet name="header">Event Description</f:facet>
                                <h:outputText value="#{event.shortDesc}"/>
                        
                                <rich:tooltip followMouse="false"
                                              showDelay="500"
                                              direction="topRight"
                                              style="width: 300px;"
                                              layout="block">
                                    <h:outputText value="#{event.eventDesc}" style="width: 200px;"/>
                                </rich:tooltip>
                            </rich:column>
                            <rich:column style="width:8%;">
                                <f:facet name="header">Event Status</f:facet>
                                <h:outputText value="#{event.eventStatusDesc}"/>
                                <h:outputText value="    "/>
                                <h:outputText value="#{event.resheduleDateString}"/>
                            </rich:column>
                        </rich:dataTable>
                        
                        
                        
                        
                        
                        
                        
                        
                        • 9. Re: How to add another Filter ?
                          Brian Leathem Master

                          What happened to the selectOneMenu?

                          • 10. Re: How to add another Filter ?
                            Asim Shaikh Novice

                            The code in Bold help me to set Default Month but after changing dropdown value it shows different values............

                             

                            public void init(String yearFilter, String monthFilter) {

                                    this.eventmaster = new ArrayList<EventMasterBean>();

                                    try {

                                        PrimaryCache pc = PrimaryCache.getInstance();

                                        List eventMasterList = pc.getEventmaster();

                                        Iterator it = eventMasterList.iterator();

                                        while (it.hasNext()) {

                                            EventMasterBean beanObj = new EventMasterBean();

                                            EventMasterDao daoBean = (EventMasterDao) it.next();

                                            if (yearFilter != null && daoBean.getYearId() == Integer.parseInt(yearFilter)) {

                                                beanObj = copyDataFromDao(daoBean);

                                                this.eventmaster.add(beanObj);

                                            }

                                            if (monthFilter != null && daoBean.getMonthId() == (Integer.parseInt(monthFilter))) {

                                             beanObj = copyDataFromDao(daoBean);

                                                this.eventmaster.add(beanObj);

                                            }

                                        }

                                        outputList = generateOutList(this.eventmaster);

                                    } catch (Exception e) {

                                    } finally {

                                    }

                                }

                            • 11. Re: How to add another Filter ?
                              Asim Shaikh Novice

                              Guys I am still Stuck with this problem can anybody help ?

                              From this method I am calling my query bold statement call my month query but the problem is with both init and searchRecordInDatabase methods

                              public List<EventMasterBean> searchRecordsInDatabase(String searchValue, String formType) {

                                      FindDescriptionHelper fdHelp = new FindDescriptionHelper();

                                      PreparedStatement pstmt = null;

                                      ResultSet rs = null;

                                      try {

                                          this.eventmaster = new ArrayList<EventMasterBean>();

                                          SqlSearchQuriesUtil searchqueryUtil = new SqlSearchQuriesUtil();

                                          String query = "";

                                          if (formType.equals(ConstantsUtility.searchInputForm)) {

                                              query = searchqueryUtil.getEventSearchInputQuery(searchValue);

                                          } else if (formType.equals(ConstantsUtility.searchOutputForm)) {

                                              query = searchqueryUtil.getEventSearchOutputQuery(searchValue);

                                          } else if (formType.equals(ConstantsUtility.searchInputmnthForm)) {

                                              query = searchqueryUtil.getEventmnthSearchInputQuery(searchValue);

                                          }

                              • 12. Re: How to add another Filter ?
                                Brian Leathem Master

                                I'm not able to follow the variations in the code sample you've provided.  try posting a sscce example, and we'll see if that's more clear.