How can I get the nested components of a <p:column> in a facelet using EL

匆匆过客 提交于 2020-01-11 13:53:32

问题


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:


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>


来源:https://stackoverflow.com/questions/20789832/how-can-i-get-the-nested-components-of-a-pcolumn-in-a-facelet-using-el

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!