How can I get the nested components of a

in a

2020-05-07 18:20发布

Let's say I have this:

<p:column headerText="R"
          style=" text-align: center;"
          width="10"
          rendered="true">
  <p:commandLink id="MRepShowButton" update=":form1:display" onclick="EditorDialog.show();"  title="Editer le compte rendu"> 
  <f:setPropertyActionListener value="#{exam}" target="#{dyna.selectedExamen}" />  
     <p:graphicImage id="img1" value="/images/study_Report_icons/Text/0.png" rendered="#{exam.examen.rapport.rapportWrittenState == null}"/>
     <p:graphicImage id="img2" value="/images/study_Report_icons/Text/#{exam.examen.rapport.rapportWrittenState}.png" rendered="#{exam.examen.rapport.rapportWrittenState != null}"/>
  </p:commandLink>
</p:column> 

Now how can I achieve that using the <p:columns>

<p:columns value="#{tableBean.columns}" var="column" columnIndexVar="colIndex" 
           sortBy="#{column.property}" filterBy="#{column.property}">
                    <f:facet name="header">
                        #{column.header}
                    </f:facet>

                    #{car[column.property]}

                </p:columns>

all the examples and tutorials about this topic only covers the simple <h:outptText> what about components (p:graphicImage,p:commandLink ,etc..) nested in a column like the code above. how do you achieve that ?

1条回答
Bombasti
2楼-- · 2020-05-07 18:53

You can render any element inside the <p:columns> element.

What you want to do is probably render the cell contents differently, depending on the column. You can try something like this :

  //classic rendering (for all cells)
  <h:outputText value="#{car[column.property]}"/>

  //conditional rendering (for 'report' cells only)
  <h:panelGroup rendered="#{column.property == 'report'}">
    <p:commandLink id="MRepShowButton" update=":form1:display" onclick="EditorDialog.show();"  title="Editer le compte rendu">
      <f:setPropertyActionListener value="#{exam}" target="#{dyna.selectedExamen}" />  
      <p:graphicImage id="img1" value="/images/study_Report_icons/Text/0.png" rendered="#{exam.examen.rapport.rapportWrittenState == null}"/>
      <p:graphicImage id="img2" value="/images/study_Report_icons/Text/#{exam.examen.rapport.rapportWrittenState}.png" rendered="#{exam.examen.rapport.rapportWrittenState != null}"/>
    </p:commandLink>
  </h:panelGroup>
查看更多
登录 后发表回答