【发布时间】:2014-02-22 06:50:29
【问题描述】:
我有一个页面,我在该页面上使用 p dataTable 显示主要面孔表,其值来自会话范围的 bean。表中的一列是 commmandLink。我在表中的 p:columns 下有一个 h:commandLink。我需要根据具体情况渲染 h:commandLink 。我需要在另一种情况下禁用/启用 h:commandLink。为渲染 h:commandLink 编写的逻辑工作正常,但禁用它的逻辑不起作用。 h:commandLink 有一个嵌套的 outputText 和 graphicsImage。即使默认 disabled = "true" 也不起作用。当我单击为 commandLink 显示的图像时,我看到了我在 commandLink onClick 上使用 javascript 显示的对话框。
<p:dataTable value="#{myBean.items}"
id="pdatatableid"
var="oneItem"
rowIndexVar="rowIdxVar"
rows="#{myBean.displayRows}"
cellspacing="0"
width="500px"
emptyMessage="Item(s) requested cannot be found"
lazy="true"
first="#{myBean.firstRow}"
paginator="true"
paginatorPosition="top">
<p:columns value="#{myBean.headerList}" var="colHeader"
columnIndexVar="colIdx" sortBy="#{oneItem[colHeader.attribute]}" headerText="#{colHeader.label}" rendered="#{not empty myBean.headerList}">
<h:commandLink action="#{myBean.performLinkAction(colHeader)}"
rendered="#{colHeader.commandLink && colHeader.linkAction != 'removeWorkItemEscalation' && colHeader.linkAction == 'orderCancellation' && oneItem.cancelOrder}"
disabled="true" immediate="true"
onclick="#{rich:component('cancellationDlg')}.show();return false;">
<h:outputText rendered="#{(colHeader.valueImage) == null}"
value="#{myBean.getColumnValue(colHeader,colIdx)}" />
<h:graphicImage rendered="#{(colHeader.valueImage) != null}"
value="#{colHeader.valueImage}"
alt="#{myBean.getColumnValue(colHeader,colIdx) ? 'Yes':'No'}"
title="Cancel Quote" />
</h:commandLink>
</p:columns>
</p:dataTable>
public boolean getCancelOrder(){
boolean cancelOrder = false;
if(!StringUtils.isEmpty(getOrderVO().getRealm())
&& "NETWORK".equalsIgnoreCase(getOrderVO().getRealm())){
cancelOrder = true;
}
return cancelOrder;
}
above is the bean method used for rendered attribute which is working.
Similar implementation and even defaulting disabled to "true" does not work.
【问题讨论】:
-
使用 commandButton 代替 commandLink 解决了这个问题。在搜索 jsf commandButton 和 commandLink 之间的差异时,我发现它们分别生成不同类型的 HTML 元素 input 和 href a,并且 commandLink 使用 javascript 进行提交。在 commandButton 的 onClick 上编写的 javascript 按预期工作,并且在禁用按钮时不会被调用。即使按钮被禁用,也会在 commandLink 上调用 javascript。
标签: jsf-2