我需要将子组件放在素数面子表页脚(p:columnggroup type="footer")中,但标准的子表渲染器不提供这样的机会。所以我重写了org.timefaces.component.SubTableRenderer来添加子级渲染:
public class CustomSubTableRenderer extends SubTableRenderer{
@Override
protected void encodeColumnFooter(FacesContext context, SubTable table, Column column) throws IOException {
ResponseWriter writer = context.getResponseWriter();
String style = column.getStyle();
String styleClass = column.getStyleClass();
styleClass = styleClass == null ? DataTable.COLUMN_FOOTER_CLASS : DataTable.COLUMN_FOOTER_CLASS + " " + styleClass;
writer.startElement("td", null);
writer.writeAttribute("class", styleClass, null);
if(column.getRowspan() != 1) writer.writeAttribute("rowspan", column.getRowspan(), null);
if(column.getColspan() != 1) writer.writeAttribute("colspan", column.getColspan(), null);
if(style != null) writer.writeAttribute("style", style, null);
//encode children
for(UIComponent footerColumnChild : column.getChildren()) {
if(footerColumnChild.isRendered()) {
footerColumnChild.encodeAll(context);
}
}
UIComponent facet = column.getFacet("footer");
String text = column.getFooterText();
if(facet != null) {
facet.encodeAll(context);
} else if(text != null) {
writer.write(text);
}
writer.endElement("td");
}
}
当我把一些子组件放在p:column组中时,比如:
<p:dataTable>
<p:subTable>
<p:column>..</p:column>
<p:columnGroup type="footer"> <p:row> <p:column colspan="3">
<p:commandButton id="button"
action="#{myBean.someAction}"
oncomplete="jQuery('#select').modal('show');return false;"
value="#{val.add}" alt="#{val.add}"
title="#{val.add}"> </p:commandButton>
<f:setPropertyActionListener value="#{otherBean.id}"
target="#{anotherBean.selectedBackId}" /></p:column> </p:row>
</p:columnGroup> </p:subTable>
</p:dataTable>
按钮被呈现,onClick事件调用fine,但按钮的操作和f:setPropertyActionListener都不调用。如何让它们发挥作用?
如果我将p:columnGroup type="footer"构造更改为p:column标记而不是按钮操作和f:setPropertyActionListener都能很好地工作
PrimeFaces有一个错误,其中commandButton或commandLink如果位于标头中,则不会触发动作侦听器(来源-请参阅第二个缺陷)。我有预感你在页脚也遇到了同样的问题。
这在最近的一个版本中得到了修复,但它还没有向公众开放。如果你想使用PrimeFaces按钮(而不是标准的HTML按钮),你必须购买PrimeFacesElite订阅或从头开始编译源代码。
我想你可以把setPropertyActionListener放在commandButton中,如下所示:
<p:commandButton ...>
<f:setPropertyActionListener value="#{otherBean.id}" target="#{anotherBean.selectedBackId}"/>
</p:commandButton>
<p:commandButton
action="#{customerBean.remove}"
value="Delte"
title="Delete"
update="customer_table">
<f:setPropertyActionListener
target="#{customerBean.customer}"
value="#{cursomer}" />
<p:confirm
header="Confirmation"
message="Are you sure?"
icon="ui-icon-alert" />
</p:commandButton>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>