p:commandButton action and f:setpropertyactionlistener not invoked in p:columngroup

kalym4ik picture kalym4ik · Jul 24, 2013 · Viewed 7.4k times · Source

I need to put child components in primefaces subtable footer (p:columngroup type="footer"), but standard subtable renderer doesn't provide such opportunity. So I have overrided org.primefaces.component.SubTableRenderer to add children rendering:

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");
}

}

When I put some child components in p:column group like:

<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>

Button is rendered and onClick event invokes fine, but neither button's action nor f:setPropertyActionListener don't invokes. How to make them work?

if I change p:columnGroup type="footer" construction to p:column tag than button action and f:setPropertyActionListener both work fine

Answer

patstuart picture patstuart · Aug 2, 2013

PrimeFaces has a bug wherein a commandButton or commandLink doesn't fire the action listener if it is located in the header (source - see second defect). I have a hunch you've encountered the same problem in the footer.

This was fixed in a recent release, but it's not yet available to the public. If you want to use a PrimeFaces button (rather than a standard HTML button), you will have to buy a PrimeFaces Elite subscription or compile the source from scratch.