仅在单击其他组件后才触发ValueChangeEvents [英] ValueChangeEvents being fired only after other components are clicked

查看:159
本文介绍了仅在单击其他组件后才触发ValueChangeEvents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JSF(1.1.7)和Apache Trinidad(1.0.11)中使用InputFile.我为其定义了一个更改事件,但是当我更改文件选择但单击表单的另一个组件时,不会触发该事件.

I'm trying to use an InputFile within JSF (1.1.7) and Apache Trinidad (1.0.11). I define a change event for it but the event is not being fired when I change the file selection but when I click on another component of the form.

这是jsp代码:

    <trh:body>
        <tr:panelPage>
            <tr:form usesUpload="true" id="myForm"> 
                <tr:inputFile columns="80" id="archivo" 
                    valueChangeListener="#{myBean.changeInputFile}" 
                    immediate="true">
                </tr:inputFile>
                <tr:commandButton text="Begin"/>
            </tr:form>
        </tr:panelPage>
    </trh:body>

这是bean的相关部分:

Here is the relevant part of the bean:

public void changeInputFile(ValueChangeEvent event) {
    UploadedFile f = (UploadedFile)event.getNewValue();
}

仅当我单击开始"按钮时,代码才进入myBean.changeInputFile方法(之前已更改了文件选择).当我更改inputFile组件中的选定文件时,我希望它进入myBean.changeInputFile.

The code only enters into the myBean.changeInputFile method when I click the Begin button (having changed the file selection previously). I would like it to enter into myBean.changeInputFile when I change the selected file in the inputFile component.

知道为什么会这样吗?

推荐答案

您的扩展名是错误的. valuechangelistener是服务器端的操作,当将某些内容提交到服务器时会触发,并且实际上具有与以前不同的值. 告诉组件的行为类似于现代ajax(jsf 1.1.7及其valuechangelistener早于ajax时代).仅当您以旧" html术语使用表单提交(例如按下提交按钮)时,才将表单值提交到服务器(或者像使用旧的纯HTML天一样使用某些javascript触发该表单值).而且,由于无需按下按钮或添加的javascript,就不会向服务器提交任何内容,因此valuechangelistener不会自发执行任何操作.

Your expextation is wrong. The valuechangelistener is a server-side action that will fire when something is submitted to the server and effectively has a different value than it did before. It is NOT telling the component to behave like modern ajax (jsf 1.1.7 and its valuechangelistener predate the ajax era). The form value is only submitted to the server when you, well, in 'old' html terms use form submission like pressing a submit button (or use some javascript to trigger that like you would in the old plain html days). And since without pressing a button or the added javascript, nothing is submitted to the server the valuechangelistener will not spontaneously do something.

所以您所看到的行为完全正确.

So the behaviour you see is exactly as it should be.

这篇关于仅在单击其他组件后才触发ValueChangeEvents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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