我有一個頁面,我正在顯示一個使用p數據表的頁面,其數值來自會話作用域bean。表中的一列是commmandLink。我在表中的p:columns下有一個h:commandLink。我需要根據具體情況呈現h:commandLink。我需要在另一個條件中禁用/啓用h:commandLink。爲呈現h:commandLink而編寫的邏輯正常工作,但禁用它的邏輯不起作用。 h:commandLink有一個嵌套的outputText和graphicImage。即使默認禁用=「真」不起作用。當我點擊顯示的commandLink圖像時,我看到了我在commandLink onClick上使用javascript顯示的對話框。h:commandLink呈現工作禁用不起作用
<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.
代碼在哪裏? – kolossus
使用commandButton代替commandLink解決了這個問題。當搜索jsf commandButton和commandLink之間的區別時,我發現它們分別生成不同類型的HTML元素輸入和href a,並且commandLink使用javascript進行提交。寫在onClick的commandButton的JavaScript按預期工作,並且在禁用按鈕時不會被調用。在commandLink javascript被調用,即使按鈕被禁用。 – Walker