Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

h:commandLink rendered working disabled not working

Tags:

jsf-2

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.
like image 217
Walker Avatar asked Jan 30 '14 05:01

Walker


People also ask

How do I disable a command link?

If you just want to enable/disable command link, you should use disabled attribute instead of rendered and remove h:outputLabel .

What is h commandLink?

h. Tag commandLink. Render an HTML "a" anchor element that acts like a form submit button when clicked.


3 Answers

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.

like image 118
Guest568 Avatar answered Sep 20 '22 09:09

Guest568


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>
like image 39
Ednilson Campos Avatar answered Sep 22 '22 09:09

Ednilson Campos


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>
like image 20
eera Avatar answered Sep 19 '22 09:09

eera