0

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 ?

Jalal Sordo
  • 1,605
  • 3
  • 41
  • 68

1 Answers1

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>
Stephane Lallemagne
  • 1,246
  • 11
  • 21
  • it gives error on not founding properties, i think the problem is with the property of properties : prop1.prop2.prop3, the error is javax.el.PropertyNotFoundException – Jalal Sordo Dec 27 '13 at 09:45
  • Is the error on "exam.examen.rapport.rapportWrittenState" ? exam is you datatable var (that represent one row object), then check you getExamen() method, then check the getRapport() method of your Examen object, then check getRapportWrittenState method of your Rapport object... Also, I suppose dyna is your backing bean ? – Stephane Lallemagne Dec 27 '13 at 12:11
  • If exam type is Examen class, you don't need to write `exam.examen.rapport.rapportWrittenState}.png` but `exam.rapport.rapportWrittenState}.png` – Stephane Lallemagne Dec 27 '13 at 13:25
  • Look if i used p:datatable with binding everything works just fine, only i need to click twice to update the p:datatable of which i couldn't understand why or even resolve, so i thought about using p:columns as an alternative solution, my real problem is how can i achieve the whole thing with p:columns, i give to the p:columns value an ArrayList of p:column created exactly as i want to with the order that i want, but showing them is the hard part. – Jalal Sordo Dec 27 '13 at 14:32
  • to answer correctly your first comment the error is given on the first column to show, the facelet doesn't understand the EL when it evaluates to property of property e.g :dyna.selectedExamen.examen.rapport.rapportId – Jalal Sordo Dec 27 '13 at 14:42
  • 1
    I guess what's wrong. You can't use nested properties for the columnModel.property. #{car['something']} is a short for #car.something, ie "car.getSomething()" on bean side. That is invalid if property name contains dots. I don't see another syntax that would do, but you can create direct properties on your exam class. Example : `public String getRapportID() { return getExamen().getRapport().getID(); }` and so use rapportID as property name. – Stephane Lallemagne Dec 27 '13 at 17:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44017/discussion-between-papa-jay-and-stephane-lallemagne) – Jalal Sordo Dec 27 '13 at 20:12