p:p:dataTable中的commandButton
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了p:p:dataTable中的commandButton相关的知识,希望对你有一定的参考价值。
我在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?
答案
我发现了这个问题。还有第二个bean,它为第一个数据表提供了我的数据模型。这个bean是RequestScoped而不是ViewAccessScoped作为主要的支持bean。我更改了范围,现在按钮调用正在运行。
以上是关于p:p:dataTable中的commandButton的主要内容,如果未能解决你的问题,请参考以下文章
JSF p:dataTable 的奇怪行为(p:columns 中的第一个条目错误)
p:dataTable 中的 SummaryRow 不起作用
Primefaces:从p:dataTable中的行选择中排除列
在 <p:ajax event="cellEdit"> 完成时更新整个 <p:dataTable>
使用 DataTables,我从 API 中获取 HTML 字符串,但表格单元格显示的是“<p>Hello</p>”,而不仅仅是 p 标签中的“Hello”。做啥?