Question

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

Was it helpful?

Solution

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.

OTHER TIPS

I thing you can put the setPropertyActionListener inside the commandButton like this:

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top