我在p:dataTable中遇到了p:commandButton的问题 我的按钮不会调用我的支持bean中的过程。 有没有人知道为什么这个按钮不起作用?
最好的问候
按钮代码:
<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>
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>
支持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);
}
}
有没有办法让bean为数据模型RequestScoped?
答案 0 :(得分:4)
我发现了问题。 还有第二个bean,它为第一个数据表提供了我的数据模型。这个bean是RequestScoped而不是ViewAccessScoped作为主要的支持bean。我更改了范围,现在按钮调用正在运行。