Code redundancy in my . xhtml JSF - Primefaces

Asked

Viewed 34 times

0

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

Is there a solution to avoid this code redundancy? Or is it better to make this copy. I’m sure it will 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>
  • 1

    I think the best way is to create a Component. See: http://blog.globalcode.com.br/2011/03/jsf-2-composite-components-voce-nao.html

  • that’s exactly what I was looking for. thanks! @Nilsonuehara

  • if you want, you can put as an answer for me to accept!

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.