p:commandbutton与我需要的相反 [英] p:commandbutton doing the opposite of what i require

查看:72
本文介绍了p:commandbutton与我需要的相反的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试完成操作之前,我一直在尝试禁用按钮,然后应该启用该按钮

I have been trying to have a disabled button until and action is complete and then this should enable the button

按钮的代码:

<p:commandButton action="#{navigationBean.naviagtion}"   value="Next" disabled="#{!fileUploadController.uploadComplete}"/>

这是bean FileUploadController,它是一个受管理的视图范围的bean

This is the bean FileUploadController it is a managed and view scoped bean

    private boolean uploadComplete;

            uploadComplete = false;
            System.out.println("Upload complete value before copy file " + uploadComplete);
            copyFile(event.getFile().getFileName(), event.getFile().getInputstream());


        } catch (IOException e) {
//handle the exception
            e.printStackTrace();
        }

    }



    public void copyFile(String fileName, InputStream in) throws IOException {
        try {
            uploadComplete = true;

//does things 

    public boolean isUploadComplete() {
        return uploadComplete;
    }

    public void setUploadComplete(boolean uploadComplete) {
        this.uploadComplete = uploadComplete;
    }

在控制台中,我已将其设置为每次uploadComplete从false更改为true时都打印出来,我得到了:

In the console i have set it to out print at each time uploadComplete changes from false to true and i get :

INFO: Upload complete value before copy file false
INFO: upload complete value is : true

如您所见,值从false变为true,问题是按钮再也不会激活,这是为什么?

As you can see the value changes from false to true, the issue is the button never becomes active again, why is this ?

这工作正常,没有错误等,只是按钮问题

This works just fine, no errors etc, it is just the button issue

经过一些测试,我发现了以下代码:

After some testing i have found with this code:

<p:commandButton id="Nav" action="#{navigationBean.naviagtion}"   value="Next"  ajax="False" update ="Nav" disabled="#{fileUploadController.uploadComplete}"/> 

它使按钮在启动时处于活动状态,但是当我上传文件并单击按钮时,它刷新页面,然后变为禁用状态,这与我要发生的情况完全相反,所以该动作如何受到尊重?我已经尝试过围绕正确和错误的语句进行交换,但这是行不通的,这从未使按钮处于禁用状态

it makes the button live on start up but when i upload the file it and click on the button it refreshes the page and then becomes disables, the exact oposite of what i want to happen lol, so how can this action be reveresed ? i have tried swapping around the true and false statements but this did not work, this never made the button disabled

我该如何翻转控件,使其与现在所做的相反

How can i flip the controls so it does the opposite of what is doing now

推荐答案

官方文档.
我发现,就像Sujoy所评论的那样,p:fileOupload具有属性update,该属性在上载完成后呈现组件.因此,您可以通过在<p:fileUpload>中添加update="Nav"来更新Nav.这样,您的按钮应该可以正确地重新呈现.
另外,也许您应该将disabled="#{fileUploadController.uploadComplete}"/>切换回disabled="#{!fileUploadController.uploadComplete}"/>,因为如果uploadComplete == true,则应该禁用 not 按钮.
您必须将更新放置在上传组件中,而不是按钮本身中!
希望您的测试不会弄乱您的代码;)

After our latest conversation I had a look at the official documentation.
I found that, like Sujoy commented, p:fileOupload has an attribute update, that renders a component after the upload has finished. So you update your Nav via adding update="Nav" to your <p:fileUpload>. This way your button should be re-rendered properly.
Also maybe you should switch disabled="#{fileUploadController.uploadComplete}"/> back to disabled="#{!fileUploadController.uploadComplete}"/> since if uploadComplete == true, the button should not be disabled.
You have to place update in the upload-component, not in the button itself!
Hopefully your testing hasn't messed up your code ;)

这篇关于p:commandbutton与我需要的相反的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆