【问题标题】:h:commandLink rendered working disabled not workingh:commandLink 呈现工作禁用不工作
【发布时间】: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 &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.

【问题讨论】:

  • 使用 commandButton 代替 commandLink 解决了这个问题。在搜索 jsf commandButton 和 commandLink 之间的差异时,我发现它们分别生成不同类型的 HTML 元素 input 和 href a,并且 commandLink 使用 javascript 进行提交。在 commandButton 的 onClick 上编写的 javascript 按预期工作,并且在禁用按钮时不会被调用。即使按钮被禁用,也会在 commandLink 上调用 javascript。

标签: jsf-2


【解决方案1】:

查看生成的 HTML。设置 disabled=true 会产生一个 span-Tag。

如果指定了“disabled”属性,则不要渲染 HTML“a”锚元素或其“href”属性。相反,渲染一个“span”元素。

https://javaserverfaces.java.net/nonav/docs/2.0/pdldocs/facelets/h/commandLink.html

如果有 onClick 属性,这将产生客户端行为。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,并通过删除渲染的 h: commandLink 解决了 只留下 h:graphicImage。

    <h:commandLink> 
        <h:graphicImage rendered="#{varDataTable.atribute}"/> 
    </ h: commandLink>
    

    【讨论】:

      【解决方案3】:

      使用 引导程序:

      我遇到了同样的问题,并通过在 EL 条件下添加禁用来解决它。

      <h:commandLink class="#{empty Backing.list?'disabled':''}" action="#{Backing.next}">
                              <i class="fa fa-calendar"></i>Label
                              <f:ajax render="@form" />
                          </h:commandLink>
      

      【讨论】:

        【解决方案4】:

        使用 commandButton 代替 commandLink 解决了这个问题。在搜索 jsf commandButton 和 commandLink 之间的差异时,我发现它们分别生成不同类型的 HTML 元素 input 和 href a,并且 commandLink 使用 javascript 进行提交。在 commandButton 的 onClick 上编写的 javascript 按预期工作,并且在禁用按钮时不会被调用。即使按钮被禁用,在 commandLink 上的 JavaScript 也会被调用。

        【讨论】:

          猜你喜欢
          • 2015-03-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-05-26
          • 1970-01-01
          • 2019-01-19
          相关资源
          最近更新 更多