JSF valueChangeListener 仅在第二次尝试时做出反应?

发布于 2024-09-19 03:04:03 字数 1241 浏览 5 评论 0原文

我的 JSF 页面有两个下拉列表,我想加载第二个下拉列表,其值基于第一个下拉列表中选择的值。但是,仅在我第二次更改选择时才检测到“onchange”事件!

网页代码片段:

<h:form id="selectRegion">
    <h:selectOneMenu id="governorate"
            value="#{SearchView.governorate}"
            styleClass="mediumInput" immediate="true"
            valueChangeListener="#{SearchView.goverValueChanged}"
            onchange="submit();">
            <f:selectItems value="#{SearchView.goverItemsList}" id="govItems" />
    </h:selectOneMenu>

    <h:selectOneMenu id="district"
            value="#{SearchView.district}"
            styleClass="mediumInput">
            <f:selectItems value="#{SearchView.districtItemsList}" id="distItems" />
    </h:selectOneMenu>
</h:form>

<h:form id="SearchFor">
<hx:commandExButton
    id="button1" styleClass="btn" type="submit"
    value="Search" action="#{SearchView.searchAction}"
    onclick="document.getElementById('selectRegion').submit();">
</hx:commandExButton>
</h:form>

问题在于,仅当我第二次修改省份的值而不是第一次修改省份值时才会调用goverValueChanged(ValueChangeEvent event)(我将系统放在goverValueChanged(ValueChangeEvent event)中才知道) 。

有人知道可能出了什么问题吗?提前致谢!我正在使用 JSF 1.1 并在 IBM WAS 上运行

I have JSF page has two drop down lists and I want to load the second one with values based on what was chosen in the first one. However, the "onchange" event is only detected the second time I change the selection!

Web page Code snippet:

<h:form id="selectRegion">
    <h:selectOneMenu id="governorate"
            value="#{SearchView.governorate}"
            styleClass="mediumInput" immediate="true"
            valueChangeListener="#{SearchView.goverValueChanged}"
            onchange="submit();">
            <f:selectItems value="#{SearchView.goverItemsList}" id="govItems" />
    </h:selectOneMenu>

    <h:selectOneMenu id="district"
            value="#{SearchView.district}"
            styleClass="mediumInput">
            <f:selectItems value="#{SearchView.districtItemsList}" id="distItems" />
    </h:selectOneMenu>
</h:form>

<h:form id="SearchFor">
<hx:commandExButton
    id="button1" styleClass="btn" type="submit"
    value="Search" action="#{SearchView.searchAction}"
    onclick="document.getElementById('selectRegion').submit();">
</hx:commandExButton>
</h:form>

The problem is that goverValueChanged(ValueChangeEvent event) is invoked only when I modify the value of the governorate for the second time but not for the first time (I put system out in goverValueChanged(ValueChangeEvent event) to know that).

Does anyone have an idea regarding what might be wrong? Thanks in advance! I am using JSF 1.1 and run on IBM WAS

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

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

发布评论

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

评论(1

说不完的你爱 2024-09-26 03:04:03

上次与 IBM 和 JSF 1.1 战斗已经是很久以前的事了,但我依稀记得一些古老的 JSF 1.1 bug,导致 valueChangeListener 在初始值为 null 时不会被触发。我建议将初始值(value="#{SearchView.governorate}" 后面的属性)设置为空字符串或其他值。

当然,您也可以将 JSF 1.1 升级到最新版本的 JSF 1.1_02。它有相当多的功能错误修复,也许它也能解决这个(和其他)问题。 IBM WAS 5.x 附带了 JSF 1.1 的早期版本,其中充斥着一些类似的奇怪错误。或者,也许您正在使用 IBM WAS 6.x,那么您也可以完全放弃 JSF 1.1,转而使用经过大幅改进的 JSF 1.2。您可以从此处下载 JSF 库。

It has been a long time ago I fighted with IBM and JSF 1.1 for last time, but I vaguely recall some ancient JSF 1.1 bug which caused that the valueChangeListener won't be fired when the initial value is null. I'd suggest to set the initial value (the property behind value="#{SearchView.governorate}") to an empty string or to something else.

You can of course also upgrade JSF 1.1 to the latest build JSF 1.1_02. It has pretty a lot of functional bugfixes, maybe it will also fix this (and other) problems. IBM WAS 5.x namely ships with a very early version of JSF 1.1 which is cluttered of some odd bugs like that. Or maybe you're using IBM WAS 6.x, then you can also dump JSF 1.1 altogether and go for the much improved JSF 1.2. You can download JSF libraries from the archives right here.

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