0
votes

I'm trying to filter a column using backing bean function.

<p:dataTable id="cars" 
             var="car" 
             value="#{manageAllCoursesBean.courses}"
             filteredValue="#{manageAllCoursesBean.filteredCourse1}"> 

    <f:facet name="header">
        <p:outputPanel>
            <p:inputText id="globalFilter" 
                         onkeyup="PF('carsTable1').filter()" 
                         style="width:250px" 
                         placeholder="Entrer un mot clé"/>
        </p:outputPanel>
    </f:facet>

    <p:column headerText="Name"
              filterBy="#{car.name}"
              sortBy="#{car.name}"
              style="color: #400040; font-size: 10px; width: 150px; text-align:center">
        <h:outputText value="#{car.name}" />
    </p:column>

    <p:column headerText="Teacher"
              filteredBy="#{manageAllCoursesBean.findTeacherByIdCourse(car.id)}"
              sortBy="#{manageAllCoursesBean.findTeacherByIdCourse(car.id)}"
              style="color: #400040; font-size: 10px; width: 175px; text-align:center">
        <h:outputText value="#{manageAllCoursesBean.findTeacherByIdCourse(car.id)}" />
    </p:column>

</p:dataTable>

the backing bean method is:

public String findTeacherByIdCourse(String courseId) throws IOException
{
    return serviceManager.findTeacherByCourseId(courseId);
}

the filter with Name is working as well. However, is not the case with Teacher.

Have you please any idea about solving that ?. Big thanks.

1
Hello Sir @Kukeltje, you're right. I changed the tags. I meant that - As explained on PrimeFaces showcase - the filter gives the desired resultes with filterBy="#{car.name}" . However can't work with filteredBy="#{manageAllCoursesBean.findTeacherByIdCourse(car.id)}" - misseoui nahla
Why do you expect the filteredBy="#{manageAllCoursesBean.findTeacherByIdCourse(car.id)}" to work? Where did you read it should? And "can't work" is not really a good description a developer would give... is the method called? And there still is no version info, not a minimal reproducible example not any indication what you tried searching/reading etc... Please improve the question - Kukeltje

1 Answers

0
votes

As described on Primefaces showcase, there's no way to use managed bean method with filterBy under p:column.

I proposed that solution: You can convert your entity Course to a courseModel and then add teachers as a list of strings.

then in your managed bean will be :

List<CourrierModel> lacmss = new ArrayList<CourrierModel>();
DataModel allDatasAssociatedCE = new ListDataModel();

//...

allDatasAssociatedCE.setWrappedData(lacmes);
for(Course c: courses)
{
   CourseModel cme = new CourseModel();
   cme.setCourse(c);
   cme.setTeachers(findTeacherByIdCourse(c));
   lacmss.add(cme);
}

HTH.