1

I have already successfully displayed a dynamic datatable in my JSF page.

However, i need to add column header for month column as given below but it's not displaying month column header

<ul type="none">
    <ui:repeat  value="#{caseStudy.pojoListsForCaseStudyAttendance}"
               var="caseStudyDetails">
        <li>
            <p:dataTable value="#{caseStudyDetails}"
                         var="pojo1"
                         rendered="#{addCampus.campusDetails.campus=='C'}">

                <p:column>
                    <f:facet name="header">
                        <p:outputLabel value="#{pojo1.subjectName}"></p:outputLabel>
                    </f:facet>
                    <p:outputLabel value="#{pojo1.monthValue}"></p:outputLabel>
                </p:column>

                <p:column headerText="#{message['label.msg.student.leave.list.list']}">
                    <p:outputLabel value="#{pojo1.appliedLeavesList}"></p:outputLabel>
                </p:column>
            </p:dataTable>
        </li>
    </ui:repeat>
</ul>

Actual Output that I'm getting

Tiny
  • 27,221
  • 105
  • 339
  • 599
qwerty
  • 9
  • 1
  • 7
  • Do you have any ui design for your expected output? – mehere Sep 28 '15 at 06:43
  • @EvaMariam Please check the following link https://drive.google.com/file/d/0B35RvCPmuQMtSUM5X0NkVDBNRW8/view?usp=sharing – qwerty Sep 28 '15 at 06:53
  • @EvaMariam from that screen shot if you observes attendance details you can see that months list column header is not getting .Please have a look on it – qwerty Sep 28 '15 at 06:57
  • can you post the code used to set values to caseStudy.pojoListsForCaseStudyAttendance ?? – mehere Sep 28 '15 at 07:00
  • is the .subjectName a list or string? – mehere Sep 28 '15 at 07:08
  • for (i = 0; i < monthList.size(); i++) { obj=new PeriodWiseStudentAttendancePojo1(); obj.setMonthValue(monthList.get(i)); obj.setAbsentList(absentDetailsList.get(i)); obj.setAppliedLeavesList(leavesList.get(i)); obj.setLateAttendanceList(lateAttendanceList.get(i)); obj.setSubjectName(subject.getSubjectname()); pojoList.add(obj); } int listCount=ij; for(;ij<=listCount;) { ij++; } – qwerty Sep 28 '15 at 07:09
  • 1
    @EvaMariam It is a String – qwerty Sep 28 '15 at 07:10
  • Try using a datable instead of ui:repeat. see http://stackoverflow.com/questions/4947744/ui-repeat-p-datatable-question – mehere Sep 28 '15 at 07:25

1 Answers1

2

There's a fundamental misunderstanding here.

<p:dataTable value="#{caseStudyDetails}" var="pojo1">
    <p:column>
        <f:facet name="header">#{pojo1.subjectName}</f:facet>
        #{pojo1.monthValue}
    </p:column>
</p:dataTable>    

You're basically trying to display a row-based value as column header. A table can have more than one row. There can be only one column header. Which row exactly did you mean to display in the column header? You have nowhere specified that. How should the table know that? While rendering the table head, the table has no idea what exactly #{pojo1} is, let alone which one of many exactly you meant to use. It's only available while rendering each row of the table body. Inside the column header, only the #{caseStudyDetails} or its parents is available.

If each row has exactly the same subjectName value in the same column (which indicates an inefficient model full of duplicated data, but that aside), then you could just explicitly grab the first item like below:

<p:dataTable value="#{caseStudyDetails}" var="pojo1">
    <p:column>
        <f:facet name="header">#{caseStudyDetails[0].subjectName}</f:facet>
        #{pojo1.monthValue}
    </p:column>
</p:dataTable>    

If each row has however a different subjectName, then you should not display that in a single place in the column header, but you should display that in every row. Something like this:

<p:dataTable value="#{caseStudyDetails}" var="pojo1">
    <p:column>
        <strong>#{pojo1.subjectName}</strong><br/>
        #{pojo1.monthValue}
    </p:column>
</p:dataTable>    

Unrelated to the concrete problem, the abuse of <p:outputLabel> over all place doesn't give me the impression that you're using the right resources to learn JSF. Carefully read Purpose of the h:outputLabel and its "for" attribute. I already removed those from the above snippets.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555