P:commandButton in p:dataTable

commandbuttondatatablejakarta-eejsfprimefaces

I got a problem with a p:commandButton inside a p:dataTable
My button does not call the procedure in my backing bean.
Does anyone have an idea why this button won't work?

Best Regards

Button Code:

 <p:column headerText="Details" style="width: 10px;">
                            <p:outputPanel id="buttonDetail">
                                <p:commandButton icon="ui-icon-vwfList" 
                                                styleClass="colButton" 
                                                action="#{customerChangeHistoryHandler.selectHistoryElement()}"
                                                id="buttonDetail"                                           
                                                update=":historyDetail"
                                                title="GO!!!">
                                </p:commandButton>
                            </p:outputPanel>
                        </p:column>

Full Code of JSF-Page:

 <?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:m="http://java.sun.com/jsf/composite/components/mmnet">

        <h:form id="historyList">


                <p:dataTable id="historyTable"
                            value="#{customerChangeHistoryListHandler.dataModel}"
                            var="_history"
                            lazy="true"
                            paginator="true" 
                            rows="20"
                            paginatorAlwaysVisible="false"
                            paginatorPosition="bottom" 
                            rowsPerPageTemplate="5,10,15,20,25,50"
                            paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                            selectionMode="single"
                            selection="#{customerChangeHistoryHandler.entity}"
                            style="margin-top:5px;">


                <f:facet name="header">
                    <h:outputText   value="#{labels.historie} (#{customerChangeHistoryListHandler.dataModel.rowCount})"/>
                </f:facet>

                    <p:ajax event="rowSelect" listener="#{customerChangeHistoryHandler.onRowSelect}" update=":contentPanel"/>

                        <p:column headerText="#{labels.typ}"
                            style="width: 10px;">
                            <p:outputPanel id="buttonImage">
                                <p:commandButton icon="ui-icon-workflow" 
                                                styleClass="colButton" 
                                                action="#{customerChangeHistoryHandler.onRowSelect}"
                                                update=":contentPanel" 
                                                rendered="#{_history.changeType == 'WORKFLOW_CHANGED' or _history.changeType == 'WORKFLOW_CREATED' or _history.changeType == 'WORKFLOW_DELETED'}">
                                </p:commandButton>
                                <p:commandButton icon="ui-icon-note" 
                                                styleClass="colButton" 
                                                action="#{customerChangeHistoryHandler.onRowSelect}"
                                                update=":contentPanel" 
                                                rendered="#{_history.changeType == 'NOTE_CHANGED' or _history.changeType == 'NOTE_CREATED' or _history.changeType == 'NOTE_DELETED'}">
                                </p:commandButton>
                                <p:commandButton icon="ui-icon-diso" 
                                                styleClass="colButton" 
                                                action="#{customerChangeHistoryHandler.onRowSelect}"
                                                update=":contentPanel" 
                                                rendered="#{_history.changeType == 'ERP_CHANGE'}">
                                </p:commandButton>
                                <p:commandButton icon="ui-icon-info" 
                                                styleClass="colButton" 
                                                action="#{customerChangeHistoryHandler.onRowSelect}"
                                                update=":contentPanel" 
                                                rendered="#{_history.changeType == 'CUSTOMER_MERGED'}">
                                </p:commandButton>
                                <p:commandButton icon="ui-icon-arrowthickstop-1-s" 
                                                styleClass="colButton" 
                                                action="#{customerChangeHistoryHandler.onRowSelect}"
                                                update=":contentPanel" 
                                                rendered="#{_history.changeType == 'FILE_UPLOADED'}">
                                </p:commandButton>
                            </p:outputPanel>
                        </p:column>

                        <p:column headerText="Details" style="width: 10px;">
                            <p:outputPanel id="buttonDetail">
                                <p:commandButton icon="ui-icon-vwfList" 
                                                styleClass="colButton" 
                                                action="#{customerChangeHistoryHandler.selectHistoryElement()}"
                                                id="buttonDetail"                                           
                                                update=":historyDetail"
                                                title="GO!!!">
                                </p:commandButton>
                            </p:outputPanel>
                        </p:column>

                        <p:column headerText="ChangeType"
                                    sortBy="#{_history.changeType}">
                            <h:outputText value="#{labels[_history.changeType]}" />
                        </p:column>

                        <p:column headerText="#{labels.beschreibung}">
                            <h:outputText value="#{_history.description}" />
                        </p:column>

                        <p:column headerText="#{labels.modDate} und #{labels.modUser}"
                                sortBy="#{_history.modDate}">
                            <m:outputDateUser valueDate="#{_history.modDate}" valueUser="#{_history.modUser}" />
                        </p:column>

                </p:dataTable>

        </h:form>

        <h:form id="historyDetail">

                <p:panel id="detailPanel" rendered="#{customerChangeHistoryHandler.entity != null}">
                History Detail --> ToDo
                </p:panel>  

        </h:form>

</ui:composition>

Backing Bean:

import javax.inject.Inject;
import javax.inject.Named;

import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;
import org.primefaces.event.SelectEvent;

@Named
@ViewAccessScoped
public class CustomerChangeHistoryHandler extends JccPersistenceHandler<Integer, CustomerChangeHistory>{

    @Inject
    NewsMessageHandler newsMessageHandler;

    @Inject
    DebitorenakteState debitorenakteState;

    @Inject
    private WorkflowHandler workflowHandler;


    @Override
    protected Class<CustomerChangeHistory> getEntityType() {
        return CustomerChangeHistory.class;
    }

    @Override
    public CustomerChangeHistory getEntity() {
        return super.getEntity();
    }

    @Override
    public void onRowSelect(SelectEvent event) {
        Integer tmpId = this.entity.getLinkedId();
        try {
            ChangeType tmpChangeType = this.entity.getChangeType(); 
            if(tmpChangeType.equals(CustomerChangeHistory.ChangeType.WORKFLOW_CHANGED) || tmpChangeType.equals(CustomerChangeHistory.ChangeType.WORKFLOW_CREATED) || tmpChangeType.equals(CustomerChangeHistory.ChangeType.WORKFLOW_DELETED)){
                workflowHandler.setSelectionId(tmpId);
                workflowHandler.selectById();
                workflowHandler.select();
            } else if(tmpChangeType.equals(CustomerChangeHistory.ChangeType.NOTE_CHANGED) || tmpChangeType.equals(CustomerChangeHistory.ChangeType.NOTE_CREATED) || tmpChangeType.equals(CustomerChangeHistory.ChangeType.NOTE_DELETED)){
                newsMessageHandler.setSelectionId(tmpId);
                newsMessageHandler.selectById();
                newsMessageHandler.onRowSelect(event);
                debitorenakteState.setActivePage(DebitorenakteEnvironment.PAGE_MORE_NOTES);
                debitorenakteState.setActiveTabIndex(6);
            } else if(tmpChangeType.equals(CustomerChangeHistory.ChangeType.ERP_CHANGE)){

                //TODO

            } else if(tmpChangeType.equals(CustomerChangeHistory.ChangeType.CUSTOMER_MERGED)){

                //TODO

            } else if(tmpChangeType.equals(CustomerChangeHistory.ChangeType.FILE_UPLOADED)){

                //TODO

            } else {
                logError("ChangeType nicht gefunden: " + this.entity.getChangeType().toString());
            }
            super.onRowSelect(event);
        } catch (Exception e) {
            // TODO: handle exception
            jsfMessageService.info("Eintrag nicht mehr vorhanden", event);
        }   
    }

    public void selectHistoryElement(){
        System.out.println("<-------------------------YEA, Button pressed!!! --------------------------------->");
//      logDebug("Showing History Entity: " + this.entity);
    }

}

Is there a way to let the bean for the data model RequestScoped?

Best Answer

I found the problem. There is a second bean, which provides my datamodel for the first datatable. This bean was RequestScoped and not ViewAccessScoped as the main backing bean. I changed the scope and now the button call is working.

Related Topic