Code redundancy in my .xhtml JSF - Primefaces

0

I have this table in 2 pages of mine and I ended up copying and pasting this code, the only thing I had to change was the "bean", in one I used "bean1", the other I used "bean2" p>

Is there any solution to avoid this code redundancy? Or better make that copy yourself. I'm sure it will always always be like this.

<p:dataTable id="listDataTable" value="#{bean.list}" var="x"
                            widgetVar="dataTableList" filteredValue="#{bean.listFilter}"
                            dataLocale="pt"
                            emptyMessage="Nenhum registro para filtro selecionado"
                            reflow="true" paginator="true" rows="100"
                            rowsPerPageTemplate="100,200,500,1000"
                            styleClass="whiteSpaceNowrap">
                            <f:facet name="header">
                                <h:outputText value="List" />
                            </f:facet>

                            <p:column headerText="Coluna 1" filterBy="#{x.coluna1}"
                                filterMatchMode="startsWith" style="text-align: center;"
                                width="90">
                                <f:facet name="filter">
                                    <p:selectOneMenu onchange="PF('dataTableList').filter()">
                                        <f:selectItem itemLabel="" itemValue="#{null}"
                                            noSelectionOption="true" />
                                        <f:selectItems value="#{bean.filter.coluna1}" />
                                    </p:selectOneMenu>
                                </f:facet>
                                <h:outputText value="#{x.coluna1}" />
                            </p:column>
                            <p:column headerText="Coluna 2" filterBy="#{x.coluna2}"
                                filterMatchMode="startsWith" style="text-align: center;"
                                width="90">
                                <f:facet name="filter">
                                    <p:selectOneMenu onchange="PF('dataTableList').filter()">
                                        <f:selectItem itemLabel="" itemValue="#{null}"
                                            noSelectionOption="true" />
                                        <f:selectItems value="#{bean.filter.coluna2}" />
                                    </p:selectOneMenu>
                                </f:facet>
                                <h:outputText value="#{x.coluna1}" />
                            </p:column>
                            <p:column headerText="Coluna 3" filterBy="#{x.coluna3}"
                                filterMatchMode="startsWith" style="text-align: center;"
                                width="90">
                                <f:facet name="filter">
                                    <p:selectOneMenu onchange="PF('dataTableList').filter()">
                                        <f:selectItem itemLabel="" itemValue="#{null}"
                                            noSelectionOption="true" />
                                        <f:selectItems value="#{bean.filter.coluna3}" />
                                    </p:selectOneMenu>
                                </f:facet>
                                <h:outputText value="#{x.coluna3}" />
                            </p:column>

                        </p:dataTable>
    
asked by anonymous 04.08.2017 / 20:44

1 answer

1

I think the best way is to create a custom component

Link to article

    
04.08.2017 / 21:37