2013-11-15 3 views
1

<p:dataTable> 관리 대상 빈에서 프로그래밍 방식으로 만드는 글로벌 필터를 추가하려고합니다. 테이블이 잘 작동하고 올바르게 렌더링되지만 마지막으로 추가 된 구성 요소 만 datatable 패싯에 렌더링됩니다. 여기에 내가 노력 코드입니다 : 일반 XHTML/Facelets의 코드처럼p : dataTable facet에 프로그래밍 방식으로/동적으로 구성 요소를 추가하는 방법

//config 
    FacesContext fc = FacesContext.getCurrentInstance(); 
    Application application = fc.getApplication(); 
    ExpressionFactory ef = application.getExpressionFactory(); 
    ELContext elc = fc.getELContext(); 

    //Table 
    table = (DataTable) application.createComponent(DataTable.COMPONENT_TYPE); 
    table.setId("tabexam"); 
    table.setValue(listexam); 
    table.setVar("exam"); 
    table.setWidgetVar("examTable"); 
    table.setEmptyMessage("aucun résultat trouvé pour votre recherche"); 
    table.setFilteredValue(filteredexams); 
    table.setPaginator(true); 
    table.setPaginatorPosition("bottom"); 
    table.setRows(25); 
    table.setPaginatorTemplate("{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"); 
    table.setRowsPerPageTemplate("10,25,50,100"); 


    /////////this is the part that regards this question/////////// 
    /* 
    this is the HTML code that i want to translate to java code : 
    <f:facet name="header" > 
    <h:outputText value="Rechercher: "/> 
    <p:inputText id="globalFilter" onkeyup="examTable.filter();" style="width:200px" /> 
    </f:facet> 
    */ 
    UIOutput tableTitle = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE); 

    tableTitle.setValue("Rechercher :"); 

    HtmlInputText globalfilterinput = (HtmlInputText) application.createComponent(HtmlInputText.COMPONENT_TYPE); 
    globalfilterinput.setId("globalFilter"); 
    ValueExpression globalfilterJSaction = ef.createValueExpression(elc, "examTable.filter()", Object.class); 
    globalfilterinput.setValueExpression("onkeyup", globalfilterJSaction); 


    Map comps = new HashMap(); 

    comps.put("header", tableTitle); 
    comps.put("header", globalfilterinput); 

    table.getFacets().putAll(comps); 

    /////////////////////////////////////////////////// 

    //Index 
    Column indexColumn = (Column) application.createComponent(Column.COMPONENT_TYPE); 
    UIOutput indexColumnTitle = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE); 
    indexColumnTitle.setValue("Index"); 
    indexColumn.getFacets().put("header", indexColumnTitle); 
    //table.getColumns().add(column); 
    table.getChildren().add(indexColumn); 

    ValueExpression indexValueExp = ef.createValueExpression(elc, "#{exam.examen.studyPatientState}", Object.class); 
    HtmlOutputText indexOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE); 
    indexOutput.setValueExpression("value", indexValueExp); 
    indexColumn.getChildren().add(indexOutput); 

    //Name Column 
    Column nameColumn = (Column) application.createComponent(Column.COMPONENT_TYPE); 
    UIOutput nameColumnTitle = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE); 
    nameColumnTitle.setValue("Name"); 
    nameColumn.getFacets().put("header", nameColumnTitle); 
    table.getChildren().add(nameColumn); 

    ValueExpression nameValueExp = ef.createValueExpression(elc, "#{exam.examen.rapport.rapportOraleState}", Object.class); 
    HtmlOutputText nameOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE); 
    nameOutput.setValueExpression("value", nameValueExp); 
    nameColumn.getChildren().add(nameOutput); 

답변

2

가하는 <f:facet>하나 아이를 가질 수 있습니다. 코드 주석에 표시된대로

,

<f:facet name="header" > 
    <h:outputText value="Rechercher: "/> 
    <p:inputText id="globalFilter" onkeyup="examTable.filter();" style="width:200px" /> 
</f:facet> 

은 이미 유효하지 않습니다. Facelets에서도 작동하지 않았을 것입니다. <h:panelGroup>에 포장해야합니다.

<f:facet name="header" > 
    <h:panelGroup> 
     <h:outputText value="Rechercher: "/> 
     <p:inputText id="globalFilter" onkeyup="examTable.filter();" style="width:200px" /> 
    </h:panelGroup> 
</f:facet> 

그냥 자바 코드에서 동일한 않습니다. 기억 : 아무 것도은 X0ML이 아닌 Java 코드로 또는 그 반대로 이루어질 수 있습니다. Java에서 가능한 모든 것은 JSP와는 달리 순수 XHTML을 사용하여 가능합니다. 차이점은 XHTML은 일반적으로이 영역에서 훨씬 덜 장황하고 유지 관리가 더 쉽다는 것입니다.

+0

내가 사람을 말할 수있는 무엇, 당신은 또한 내가 column.setFilterBy()와 column.setSortBy (문제가있어, 감사합니다, 다만 천재 야) 또는 나는이에 대해 별도의 질문을해야한다. –

+0

반갑습니다. 예. 별도의 질문을하십시오. 현재 질문에서 프로그래밍 방식으로 패싯을 만드는 것과는 아무 관련이 없습니다. – BalusC

+0

괜찮습니다, 다시 한번 감사드립니다. –

관련 문제