当添加了render/disabled属性时,不会触发valueChangeListener [英] valueChangeListener Not fired when rendered/disabled attribute is added

查看:111
本文介绍了当添加了render/disabled属性时,不会触发valueChangeListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下安全代码:

        <h:selectOneMenu id="countrycode"
                styleClass="Width300"
                value="#{customer.countrycode}"
                valueChangeListener="#{customer.countrycodechange}"
                onchange="submit()"
                immediate="true"
                rendered="#{customer.validcountry}">
                <f:selectItem itemValue="None"
                    itemLabel="-------Select a Country------" />
                <f:selectItem itemValue="AU" itemLabel="Australia" />
                <f:selectItem itemValue="NZ" itemLabel="New Zealand" />
        </h:selectOneMenu>

仅当我省略了rendered属性时,ValueChangeListener才起作用,使用countrycodechange的rendered属性永远不会被解雇!有没有解决的办法?

The ValueChangeListener works only if i leave out the rendered attribute, with rendered attribute the countrycodechange never gets fired! Is there a way around this?

添加disabled属性也是如此,这会阻止valueChangeListener触发.我的valueChangeListener backbean具有:

Same is true for adding disabled attribute , which stops valueChangeListener from firing. My valueChangeListener backbean has:

    public void countrycodechange (ValueChangeEvent vce) {

        PhaseId phaseId = vce.getPhaseId();
        if (phaseId.equals(PhaseId.ANY_PHASE))
        {
            vce.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
            vce.queue();
        }
        else if (phaseId.equals(PhaseId.UPDATE_MODEL_VALUES))
        {
            ...

任何帮助将不胜感激.

any help would be appreciated.

推荐答案

仅当输入组件的rendereddisabled属性的值为truefalse 在表单提交.因此,您需要确保#{customer.validcountry}在表单提交期间的评估结果与在显示表单期间的评估结果相同.显然,在您的情况下,bean是请求范围的,或者isValidcountry()取决于请求范围的参数,该参数在表单提交期间未正确保留.您需要确保在提交表单期间保留相同的条件.

Input components will only be processed when their rendered and disabled attributes evaluate respectively to true and false during the form submit. So, you need to make sure that #{customer.validcountry} evaluates the same during the form submit as it did during displaying the form. Apparently in your case the bean is request scoped or the isValidcountry() depends on a request scoped parameter which isn't properly preserved during the form submit. You need to make sure that you preserve the same condition during the form submit.

在JSF 2.0中,可以将bean放在视图范围而不是请求范围内.但是,看到您的valueChangeListener hack,我认为您仍在使用JSF 1.x,它尚无视图范围.如果不看其余代码,很难提出正确的解决方案.对我而言,至少对是否是有效国家/地区"具有渲染属性没有任何意义.而输入组件本身应该选择一个有效的国家/地区.

In JSF 2.0 that would be a matter of putting the bean in the view scope instead of the request scope. However, seeing your valueChangeListener hack, I think that you're still using JSF 1.x which does not have the view scope yet. The right solution is hard to propose without seeing the rest of the code. It does at least not make sense to me to have a rendered attribute on "is a valid country?" while the input component itself should select a valid country.

这篇关于当添加了render/disabled属性时,不会触发valueChangeListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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