【问题标题】:Prime faces commandbutton not working after enabled启用后 Primefaces 命令按钮不起作用
【发布时间】:2013-05-26 12:06:28
【问题描述】:

我正在尝试在进度条完成后启用命令按钮,但是当我加载页面时,命令按钮已经启用,除此之外它工作正常。

我做了一些研究和类似的问题: commandButton not working when disable=“true” initially 但该解决方案对我不起作用。

我做错了什么?有什么我遗漏的吗?

这是 index.xhtml

            <p:growl id="growl" />
            <h3>Deskarga</h3>
            <p:messages id="messages" showDetail="true" autoUpdate="true"
                closable="true" />
            <p:commandButton value="Start" type="button"
                onclick="pbAjax.start();startButton2.disable();"
                widgetVar="startButton2" />
            <p:commandButton value="Cancel"
                actionListener="#{progressBean.cancel}"
                oncomplete="pbAjax.cancel();startButton2.enable();" />

            <p:progressBar widgetVar="pbAjax" ajax="true" rendered="true"
                value="#{progressBean.progress}" labelTemplate="{value}%"
                styleClass="animated" interval="250">
                <p:ajax event="complete" listener="#{progressBean.onComplete}"
                    update="messages"
                    oncomplete="startButton2.enable();#{progressBean.setDisabled(false)};"/>
            </p:progressBar>


            <p:separator id="separator2" />

            <p:commandButton value="Parseatu" widgetVar="parserButton" ajax="true"
                disabled="#{progressBean.disabled}" actionListener="#{progressBean.parseatu()}"
                update="growl" />

        </h:form>

这是会话范围的托管 bean:

public class ProgressBean implements Serializable {  

    private boolean disabled= true;



    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled= disabled;
    }

}  

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    首先,您不能在 oncomplete 属性中使用 bean 方法。这不应该工作

    oncomplete="startButton2.enable();#{progressBean.setDisabled(false)};"
    

    如果您还想使用 oncomplete 属性禁用 ProgressBar 组件,您应该调用 javascript 函数。为此可以使用RemoteCommand 或至少更新侦听器方法上的禁用属性

    其次。

    当我加载页面时,命令按钮已经启用,除了 这个很好用。

    CommandButton 组件在false 中默认具有disabled 属性。如果你想在true 中显示禁用的put 属性disabled

    【讨论】:

    • 谢谢你的回答,我会尝试使用RemoteCommad,我正在学习PrimeFaces,我只知道最常见的元素。
    • 解决了我的问题,谢谢!但我还必须向 bean 添加一个构造函数,将 disabled 值设置为 true。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2011-12-31
    相关资源
    最近更新 更多