Search code examples
javajsfcalendaroracle-adfjdeveloper

af:Calendar component, filter by column type


Does anyone know how to filter the calendar events based on a certain property?

For example based on the provider ID or something else. What I want is to have some checkboxes and by checking those the calendar events will display accordingly.


Solution

  • Using View Object View Criterias are the best way.

    If you want to access the Providers, you can access it through Calendar bindings. Setup the bindings attribute of the Calendar Tag, so it's bound to a backing bean.

    private RichCalendar thecal;
    //getter and setter for ca
    public RichCalendar getthecal() {
        return thecal;   
    }
    public void setthecal(RichCalendar calendar) {
        this.thecal = calendar;
    }
    

    Then you can access the calendar model data (like providers) via getthecal().getValue() to get the CalendarModel object. see here for java reference: http://docs.oracle.com/cd/E14571_01/apirefs.1111/e10684/oracle/adf/view/rich/model/CalendarModel.html

    However, I do all my filtering via View Object Attributes and View Criterias. I created a method in my application module implementation class and called it from a button bound to a backing bean action.

    Button Action:

        //get the application module
        DCBindingContainer dcbindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        AppModule am = (AppModule)dcbindings.getDataControl().getApplicationModule();
    
        //Run the filtering logic
        am.nameOfYourMethod(PassSomeData,BlahBlah);
    

    AM Method:

    //get the view object your calendar uses
    CalendarVOImpl voImpl = getCalendarVO();
    ViewCriteria vc = voImpl.createViewCriteria();
    //Just some name for the view criteria
    vc.setName("filterCalendar");
    ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
    //Set the name of the attribute and the value you're looking to filter by
    vcRow.setAttribute("NameOfAttribute", "IN (" + valueFilter + ")");
    vc.insertRow(vcRow);
    voImpl.applyViewCriteria(vc);
    voImpl.executeQuery();
    

    Make sure your have some partial triggers setup to refresh your calendar after this method runs.