5

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 &amp;&amp; colHeader.linkAction != 'removeWorkItemEscalation' &amp;&amp; colHeader.linkAction == 'orderCancellation' &amp;&amp; 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.
1
  • Using commandButton in place of commandLink solved the problem. while searching for differences between jsf commandButton and commandLink, i found that they generate different kind of HTML elements input and href a respectively and commandLink uses javascript for submit. javascript written on onClick of commandButton is working as expected and is not being invoked when button is disabled. on commandLink javascript was being invoked even if button was disabled.
    – Walker
    Commented Jan 31, 2014 at 7:11

4 Answers 4

4

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.

2

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>
2

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>
0

Using commandButton in place of commandLink solved the problem. while searching for differences between jsf commandButton and commandLink, i found that they generate different kind of HTML elements input and href a respectively and commandLink uses javascript for submit. javascript written on onClick of commandButton is working as expected and is not being invoked when button is disabled. on commandLink javascript was being invoked even if button was disabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.