I'm trying to build a time schedule using <p:datatable>
. At the moment I was testing it using <f:setPropertyActionListener>
and trying to make use of the rowIndexVar
from the datatable as you can see in the following code in my column tuesday. Unfortunately it wasn't working. The problem is that the underlying model holds 5 lists (for each weekday 1) so I'm addressing a different list on each column.
I don't know if I'm approaching really wrong. But so far it was okay, and now I am only having the problem, that I want to extract the data from the respective cell I clicked. This is my table so far:
<p:dataTable id="schedule" var="rows" value="#{scheduleBean.emptyRowDefault}"
editMode="cell"
rowIndexVar="index"
widgetVar="cellCars" >
<f:facet name="header">
#{msg['schedule']}
</f:facet>
<p:column headerText="#{msg['hour']}">
<h:outputText value="#{index+1}" />
</p:column>
<p:column headerText="#{msg['time']}">
<h:outputText value="#{scheduleBean.schedule.times[index]}" />
</p:column>
<p:column headerText="#{msg['monday']}">
<p:commandLink value="#{scheduleBean.schedule.monday[index].name}" onclick="PF('subjectDialog').show();" />
</p:column>
<p:column headerText="#{msg['tuesday']}">
<p:commandLink update=":form:eventDetails" onclick="PF('subjectDialog').show();" >
<f:setPropertyActionListener value="#{scheduleBean.schedule.tuesday.get(index)}" target="#{scheduleBean.subject}" />
<h:outputText value="#{scheduleBean.schedule.tuesday[index].name}" />
</p:commandLink>
</p:column>
<p:column headerText="#{msg['wednesday']}" >
<p:commandLink value="#{scheduleBean.schedule.wednesday[index].name}" onclick="PF('subjectDialog').show();" />
</p:column>
<p:column headerText="#{msg['thursday']}">
<p:commandLink value="#{scheduleBean.schedule.thursday[index].name}" onclick="PF('subjectDialog').show();" />
</p:column>
<p:column headerText="#{msg['friday']}">
<p:commandLink value="#{scheduleBean.schedule.friday[index].name}" onclick="PF('subjectDialog').show();" />
</p:column>
</p:dataTable>
This the dialog:
<p:dialog widgetVar="subjectDialog" header="Neues Fach anlegen" showEffect="clip" hideEffect="clip" resizable="false">
<h:panelGrid id="eventDetails" columns="2">
<p:outputLabel for="name" value="#{msg['subject']}" />
<p:inputText id="name" value="#{scheduleBean.subject.name}" required="true" />
<p:outputLabel for="hour" value="#{msg['hour']}" />
<h:selectOneMenu id="hour" value="#{scheduleBean.subject.hourTime}" style="width:100%">
<f:selectItems value="#{scheduleBean.schedule.hours}" var="day" itemLabel="#{hour}" itemValue="#{hour}" />
</h:selectOneMenu>
<p:outputLabel for="weekday" value="#{msg['weekday']}" />
<h:selectOneMenu id="weekday" value="#{scheduleBean.subject.weekday}" style="width:100%">
<f:selectItems value="#{scheduleBean.schedule.weekdays}" var="day" itemLabel="#{day}" itemValue="#{day}" />
</h:selectOneMenu>
<p:outputLabel for="teacher" value="#{msg['teacher']}" />
<p:inputText id="teacher" value="#{scheduleBean.subject.teacher}" required="true" />
<p:outputLabel for="room" value="#{msg['room']}" />
<p:inputText id="room" value="#{scheduleBean.subject.room}" required="true" />
</h:panelGrid>
<h:panelGroup style="text-align: center; width: 340px; float: left">
<p:commandButton id="addButton" styleClass="button button2" value="#{msg['save']}" action="#{scheduleBean.save}" update="schedule :form:eventDetails" oncomplete="PF('subjectDialog').hide();" />
<p:commandButton id="delete" styleClass="button button2" value="#{msg['delete']}" action="#{scheduleBean.remove(scheduleBean.subject)}" update="schedule msgs" oncomplete="PF('subjectDialog').hide();" />
<p:commandButton id="cancel" styleClass="button button2" value="#{msg['cancel']}" immediate="true" oncomplete="PF('subjectDialog').hide();" />
</h:panelGroup>
</p:dialog>