我需要将子组件放在primefaces子表格页脚中(p:columngroup type =“footer”),但标准子表格渲染器不提供这样的机会。所以我已经覆盖了org.primefaces.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:列组中时,如:
<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事件调用正常,但是按钮的动作和f:setPropertyActionListener都不会调用。如何使它们工作?
如果我将p:columnGroup type =“footer”构造更改为p:列标记而不是按钮操作,并且f:setPropertyActionListener都可以正常工作
答案 0 :(得分:1)
我可以将setPropertyActionListener放在commandButton中,如下所示:
<p:commandButton ...>
<f:setPropertyActionListener value="#{otherBean.id}" target="#{anotherBean.selectedBackId}"/>
</p:commandButton>
答案 1 :(得分:1)
PrimeFaces有一个错误,如果它位于标题中,则commandButton或commandLink不会触发动作侦听器(source - 请参阅第二个缺陷)。我有一个预感,你在页脚中遇到了同样的问题。
这是在最近发布的版本中修复的,但尚未向公众开放。如果您想使用PrimeFaces按钮(而不是标准的HTML按钮),则必须购买PrimeFaces Elite订阅或从头开始编译源代码。
答案 2 :(得分:0)
<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>