为什么不跳过转换?

发布于 2024-11-15 20:10:01 字数 1439 浏览 8 评论 0原文

我的页面上有两个输入组件。它们每个都有一个转换器(这是一个检查空值的转换器,就像 JSF 需要的那样,但由于某些原因我不能使用 jsf 转换器,所以我制作了自己的转换器)。

我还有一个 ice:selectBooleanCheckbox

<ice:selectBooleanCheckbox
                    styleClass="graUserAppUserGroupAddChk"
                    value="#{userGroupTableNewRecordBean.addNewDomain}"
                    partialSubmit="true"
                    immediate="true"
                    valueChangeListener="#{userGroupTableNewRecordBean.addDomainListener}"></ice:selectBooleanCheckbox>

如您所见,我在其上放置了 immediate=true 属性,因为当我选择此复选框时,我确实希望转换阶段被跳过但不起作用,转换器仍然显示警告。你知道为什么吗?

我还在这个复选框上添加了一个 valueChangeListener 并根据以下引用直接调用 renderResponse:

因此,在下拉列表的值更改侦听器方法中,只需 

从以下位置调用 renderResponse() FacesContext 对象和验证以及 转换被绕过,你可以 还是做自己想做的事吧。

public void addDomainListener(final ValueChangeEvent valueChangeEvent) {
    // skip validation
    logger.info("listener calleddddddddddddd");
    FacesContext.getCurrentInstance().renderResponse();
}

也许 JSF 大师可以提供帮助?

非常感谢...

更新:我知道解决方案是将复选框放在单独的表单中,但我负担不起...

更新2:我'已经更正了一些有关侦听器的代码,因此现在单击时会调用它,但转换器仍然失败并且渲染响应阶段未完成...

更新 3:这不是一个冰面问题...我尝试过h:selectBooleanCheckbox 并且它发生同样的事情......

I have two input components on my page. Each of them has a converter (It's a converter which checks for empty values, like JSF required one, but for some reasons I cannot use jsf one so I've made my own converter).

I also have a ice:selectBooleanCheckbox:

<ice:selectBooleanCheckbox
                    styleClass="graUserAppUserGroupAddChk"
                    value="#{userGroupTableNewRecordBean.addNewDomain}"
                    partialSubmit="true"
                    immediate="true"
                    valueChangeListener="#{userGroupTableNewRecordBean.addDomainListener}"></ice:selectBooleanCheckbox>

As you see I put immediate=true attribute on it, becase when I select this checkbox I do want the conversion phase to be skipped but it does not work, the converters still show their warnings. Do you know why?

I also add a valueChangeListener on this checkbox and called there the renderResponse directly, based on this quote:

So in the value changed listener method for the dropdown lists, just 

call renderResponse() from the
FacesContext object and validation and
conversion is bypassed and you can
still do what you want.

public void addDomainListener(final ValueChangeEvent valueChangeEvent) {
    // skip validation
    logger.info("listener calleddddddddddddd");
    FacesContext.getCurrentInstance().renderResponse();
}

Maybe a JSF guru can help?

Thanks a lot...

UPDATE: I know that a solution would be to put the checkbox in a separate form but I cannot afford this...

UPDATE 2: I've corrected some code about listener, so now it is called when clicked but still the converter fails and render response phase is not done...

UPDATE 3: This is not an icefaces issue... I've tried with a h:selectBooleanCheckbox and it happens the same...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋你朝朝暮暮 2024-11-22 20:10:01

整个问题和这一切背后的功能需求非常令人困惑。为什么使用转换器而不是验证器来验证输入?如果您似乎不关心转换/验证结果,为什么要使用转换器/验证器?

正如您所见,我在其上添加了immediate=true属性,因为当我选择此复选框时,我确实希望跳过转换阶段,但它不起作用,转换器仍然会显示警告。

输入组件上的 code>immediate="true" 不会跳过转换/验证。他们只是将转换/验证转移到较早的阶段(即,它发生在应用请求值阶段而不是验证阶段)。您基本上需要从这些输入中删除 immediate="true" 并将其放在命令链接/按钮上,以便跳过这些输入的转换/验证。另请参阅调试 JSF 生命周期

好的,我什么时候应该使用立即属性?< /a>

如果还不完全清楚,这里有一个总结,其中包含可能有益的实际使用示例:

  • 如果仅在 UIInput(s) 中设置,则流程验证阶段将在应用请求值阶段进行。使用它来优先验证相关 UIInput 组件。当其中任何一个验证/转换失败时,非直接组件将不会被验证/转换。

  • 如果仅在 UICommand 中设置,则任何 UIInput 组件都将跳过应用请求值阶段,直到更新模型值阶段。使用它可以跳过表单的整个处理过程。例如“取消”或“返回”按钮。

  • 如果在 UIInputUICommand 组件中都进行了设置,则任何 都将跳过应用请求值阶段,直至更新模型值阶段。没有设置此属性的 UIInput 组件。使用它可以跳过整个表单的处理,除了某些字段(带有立即数)。例如,登录表单中的“忘记密码”按钮带有必填但非即时密码字段。

The whole question and the functional requirement behind this all is pretty confusing. Why are you using a converter instead of a validator to validate the inputs? Why are you using a converter/validator if you don't seem to care about the conversion/validation outcome?

As you see I put immediate=true attribute on it, becase when I select this checkbox I do want the conversion phase to be skipped but it does not work, the converters still show their warnings.

Putting the immediate="true" on input components does not skip conversion/validation. They just shifts conversion/validation to an earlier phase (i.e. it takes place in apply request values phase instead of validations phase). You basically need to remove immediate="true" from those inputs and put it on the command link/button in order to skip conversion/validation of those inputs. See also Debug JSF lifecycle:

Okay, when should I use the immediate attribute?

If it isn't entirely clear yet, here's a summary, complete with real world use examples when they may be beneficial:

  • If set in UIInput(s) only, the process validations phase will be taken place in apply request values phase instead. Use this to prioritize validation for the UIInput component(s) in question. When validation/conversion fails for any of them, the non-immediate components won't be validated/converted.

  • If set in UICommand only, the apply request values phase until with update model values phases will be skipped for any of the UIInput component(s). Use this to skip the entire processing of the form. E.g. "Cancel" or "Back" button.

  • If set in both UIInput and UICommand components, the apply request values phase until with update model values phases will be skipped for any of the UIInput component(s) which does not have this attribute set. Use this to skip the processing of the entire form expect for certain fields (with immediate). E.g. "Password forgotten" button in a login form with a required but non-immediate password field.

春庭雪 2024-11-22 20:10:01

终于解决了......

我在这里发布问题和解决方案的总结。

我的弹出窗口中有一个复选框。当我选择它时,我想显示一些隐藏字段,但这不起作用,因为我在同一页面上还有两个必填字段,所以jsf PROCESS_VALIDATIONS 阶段出现了...

我认为放置 immediate=true 可以解决这个问题,但事实并非如此...

因此,在复选框的 ValueChangeListener 中,我必须手动跳过

public void addDomainListener(final ValueChangeEvent valueChangeEvent) {
        // skip validation
        final PhaseId phaseId = valueChangeEvent.getPhaseId();
        final Boolean newValue = (Boolean) valueChangeEvent.getNewValue();
        if (phaseId.equals(PhaseId.ANY_PHASE)) {
            valueChangeEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
            valueChangeEvent.queue();

            this.addNewDomain = newValue;
            FacesContext.getCurrentInstance().renderResponse();
        }
    }

Solved it finally...

I post here the sum up of the question and the solution.

I had a checkbox in my popup. When I select it I want to show some hidden fields but this did not work because I also had two required fields on the same page so jsf PROCESS_VALIDATIONS phase came up...

I thought that putting immediate=true will solve this, but it did not...

So, in my ValueChangeListener of the checkbox I had to manually skip the jsf validation phase:

public void addDomainListener(final ValueChangeEvent valueChangeEvent) {
        // skip validation
        final PhaseId phaseId = valueChangeEvent.getPhaseId();
        final Boolean newValue = (Boolean) valueChangeEvent.getNewValue();
        if (phaseId.equals(PhaseId.ANY_PHASE)) {
            valueChangeEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
            valueChangeEvent.queue();

            this.addNewDomain = newValue;
            FacesContext.getCurrentInstance().renderResponse();
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文