I have a page on which i am displaying a prime faces table using p dataTable whose value is coming from session scoped bean. One of the columns in table is a commmandLink. I have a h:commandLink under p:columns in the table. I need to render the h:commandLink depending on specific condition. I need to disable / enable the h:commandLink on another condition. The logic written for rendering the h:commandLink works correctly, but logic for disabling it does not work. the h:commandLink has a nested outputText and graphicImage. Even defaulting disabled = "true" does not work. when i click on image displayed for commandLink, i see the dialog which i am displaying using javascript on commandLink onClick.
<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.
If you just want to enable/disable command link, you should use disabled attribute instead of rendered and remove h:outputLabel .
h. Tag commandLink. Render an HTML "a" anchor element that acts like a form submit button when clicked.
Have a look at the generated HTML. Setting disabled=true will produce a span-Tag.
If the "disabled" attribute is specified, do not render the HTML "a" anchor element or its "href" attribute. Instead, render a "span" element.
https://javaserverfaces.java.net/nonav/docs/2.0/pdldocs/facelets/h/commandLink.html
If there is a attribute onClick, this will produce the client-side behaviour.
I had the same problem and solved by removing the rendered the h: commandLink and leaving only the h: graphicImage.
<h:commandLink>
<h:graphicImage rendered="#{varDataTable.atribute}"/>
</ h: commandLink>
Using Bootstrap:
I had the same problem and solved it by adding disabled on a EL condition.
<h:commandLink class="#{empty Backing.list?'disabled':''}" action="#{Backing.next}">
<i class="fa fa-calendar"></i>Label
<f:ajax render="@form" />
</h:commandLink>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With