ajax - JSF f :ajax listener not called

我试图在单击 h:commandButton 时将 h:inputText 切换为另一个。为此,我试图将 f:ajax 命令与 h:commandButton 联系起来,监听器在 bean 上设置一个值(决定显示哪个),并重新渲染该区域。

我尝试过在 f:ajax 上使用监听器,在 h:commandButton 上使用 actionListener,在 h:commandButton 上使用 action,在 f:ajax 上使用 execute。没有任何效果。我试图调用的 mothed 根本没有被调用——没有 println(见下文)。

panelGroup 正在重新呈现,这就是为什么我需要 onevent 属性来根据标题重新附加一些 JavaScript 提示文本(我之前有一个问题涉及到这个)。

我尝试调用的方法:

public void morePressed(AjaxBehaviorEvent e) {
    easySearch = !easySearch;
    System.out.println("Made it!");
}

不工作的 JSF 段(注意最后一个 h:commandButton 正在尝试重新呈现 panelGroup):

<h:form>
    <h:panelGroup id="switchSearchTexts">
        <h:inputText accesskey="s" alt="Search" id="searchBoxPeople" title="Search Plebeians" valueChangeListener="#{peopleBean.simplePersonQuery}" size="25" rendered="#{peopleBean.easySearch}">
            <f:ajax render="peopleDataTable" event="keyup" />
        </h:inputText>

        <h:inputText accesskey="s" alt="Search First Name" id="searchBoxFN" title="Search First Name" size="25" rendered="#{!peopleBean.easySearch}">
            <f:ajax render="peopleDataTable" event="keyup" />
        </h:inputText>
    </h:panelGroup>

    <div id="expandBox">
        <h:inputText id="searchBoxLN" alt="Search Last Name" styleClass="hideToggle" title="Search Last Name" size="25" />
        <h:inputText id="searchBoxAddress" alt="Search Address" styleClass="hideToggle" title="Search Address" size="25" />
    </div>

    <h:commandButton type="button" styleClass="moreButtonAsText" id="moreButtonAsText" value="&#x25b8;More">
        <f:ajax listener="#{peopleBean.morePressed}" render="switchSearchTexts" event="click" onevent="callFunctionAjaxRequest"  />
    </h:commandButton>

这是我在页面加载时附加到“更多”按钮的 JavaScript (jQuery)。我提供它并不是因为我认为它有帮助,但我不知道这是否会以任何方式干扰 ajax 监听器:

$(function() {
    textboxHint();
    $('input[id$="moreButtonAsText"]').toggle(function(e) {
        $(this).prop('value', '\u25c2Less');
        $(".hideToggle").show(300);
    }
    , function () {
        $(this).prop('value', '\u25b8More');
        $(".hideToggle").hide(100);
        $('input[id$="searchBoxAddress"]').prop('value', function() {
            return $(this).prop('title');
        });
        $('input[id$="searchBoxAddress"]').blur();
    });
});

我不知道。正如我所说,我已经在 h:commandButton 上尝试了 actionListener,那里有各种方法,以及 ajax 上的监听器的各种方法。谁能看出为什么监听器不起作用?

更新:

在得到答案之前,我最终做的是基于 JavaScript 将所有内容转换为显示和隐藏,如果它们最初没有隐藏 javascript,我需要隐藏的东西,等等。

但是我现在在别处需要 f:ajax。

解决方法是去掉h:commandButton上的event="click"。我仍然现在知道为什么这会导致它崩溃,但是嘿,不管用什么。

最佳答案

我遇到过这样的问题。事实证明,某处的 inputText 有一个 value="#{something.something}",其中属性不可设置。任何地方都没有报告异常。我必须在 Exception 和所有子类上设置断点才能找到它。

https://stackoverflow.com/questions/9848203/

相关文章:

optimization - 更好的初始猜测可能对优化收敛更差

ruby-on-rails - 创建 Rails 音乐播放器应用程序(类似于 Rdio)

ruby-on-rails - 在 Rails 迁移中排序的模式字段

asp.net - 如何检查 Amazon S3 存储桶中文件夹的子文件夹大小

django - 如何为基于ListView的类写get方法

matlab - 不同长度的向量之间的相关性

php - DOMPDF 安装选项

oracle - 如何以编程方式在 PL/SQL 中设置表名?

asp.net-mvc - MVC 3 : Test controllers VS integrat

ruby-on-rails - 消息 Controller 中未定义的方法 `stringify_k