我正在尝试使用 <p:datatable>
制定时间表。目前我正在使用 <f:setPropertyActionListener>
测试它并尝试利用 rowIndexVar
从数据表中,您可以在我星期二的专栏中的以下代码中看到。不幸的是它不起作用。问题是底层模型包含 5 个列表(每个工作日 1 个),因此我在每列上处理不同的列表。
我不知道我的做法是否真的错误。但到目前为止还好,现在我遇到的只是问题,我想从我单击的相应单元格中提取数据。这是我到目前为止的表格:
<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>
这是对话框:
<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>
最佳答案
不知道为什么周二行没有调用你的 ManagedBeans 属性,但是关于对话框的刷新,通常的做法是将对话框放置在主窗体之外并在其中添加一个 inner
窗体对话框本身:
<p:dialog widgetVar="subjectDialog" header="Neues Fach anlegen" showEffect="clip" hideEffect="clip" resizable="false">
<h:form id="dialogForm">
...
</h:form>
</p:dialog>
然后您只需在数据表中执行 update=":dialogForm"
即可。
这种做法的原因是浏览器可能会将 p:dialog 的内容重新定位到 DOM 树的某个其他元素(通常位于任何表单元素的末尾和外部)。这会导致您的所有按钮和表单元素停止工作。
关于java - 使用每列的不同列表获取数据表中选定的单元格对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42039330/