【问题标题】:h:selectManyChexkbox`s <f:ajax event="click" listener doesn't fire and gives an errorh:selectManyChexkbox`s <f:ajax event="click" 监听器不触发并给出错误
【发布时间】:2023-04-08 16:10:01
【问题描述】:

当用户选择/取消选择 h:selectManyCheckbox 中的某些内容时,我想触发一个事件更改侦听器,如果它不理会它什么都不应该发生。

我的 xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">

<h:head>
<link rel="stylesheet" type="text/css"
    href="/juritest/resources/css/style.css" />
<script type="text/javascript"
    src="/juritest/resources/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="/juritest/resources/js/menu.js"></script>
</h:head>

<h:body>
<ui:composition template="../../templates/gridsTemplate.xhtml">
    <ui:define name="content">
        ...
                <h:panelGroup style="text-align: left">
                    <hr />
                    <h:selectManyCheckbox
                        value="#{gridPopUpBean.oneQuestionUserAnswers}" 
                        layout="pageDirection">
                        <f:selectItem itemValue="a"
                            itemLabel="#{gridPopUpBean.currentQuestion.a}" />
                        <f:selectItem itemValue="b"
                            itemLabel="#{gridPopUpBean.currentQuestion.b}" />
                        <f:selectItem itemValue="c"
                            itemLabel="#{gridPopUpBean.currentQuestion.c}" />
                        <f:ajax event="click" listener="#{gridPopUpBean.changeListener()}"/>
                    </h:selectManyCheckbox>
                </h:panelGroup>
   ...

我收到一条错误消息,提示“一个或多个资源的目标是 'head',但视图中没有定义 'head' 组件。”我有 不只是 ,我读到这是一个可能的问题。

还有来自 bean 的 sn-p:

public void changeListener(ValueChangeEvent e) {

    change = true;
}   

我试过没有

<h:selectManyCheckbox
                        value="#{gridPopUpBean.oneQuestionUserAnswers}" valueChangeListener="#{gridPopUpBean.changeListener()}" onclick="submit()"
                        layout="pageDirection">
                        <f:selectItem itemValue="a"
                            itemLabel="#{gridPopUpBean.currentQuestion.a}" />
                        <f:selectItem itemValue="b"
                            itemLabel="#{gridPopUpBean.currentQuestion.b}" />
                        <f:selectItem itemValue="c"
                            itemLabel="#{gridPopUpBean.currentQuestion.c}" />
                        <f:ajax event="click" listener="#{gridPopUpBean.changeListener()}"/>
                    </h:selectManyCheckbox>

但没有运气......

【问题讨论】:

    标签: ajax jsf jsf-2 event-handling selectmanycheckbox


    【解决方案1】:

    一个或多个资源的目标是 'head',但视图中没有定义 'head' 组件。”我有 而不仅仅是 ,我读到这是一个可能的问题。

    &lt;ui:composition&gt; 之外的任何内容都被忽略。如果您需要&lt;h:head&gt;,它需要进入主模板,gridsTemplate.xhtml(或其任何父模板)。

    此外,如果您没有对 XHTML 文件使用可视化编辑器(例如 Dreamweaver),那么我强烈建议您停止将任何内容放在 &lt;ui:composition&gt;otherwise you keep confusing yourself 之外。

    另见:


    <f:ajax event="click" listener="#{gridPopUpBean.changeListener()}"/>
    
    public void changeListener(ValueChangeEvent e) {
    

    您将valueChangeListener&lt;f:ajax listener&gt; 混淆了。 ValueChangeEvent 参数仅适用于UIInput 组件的valueChangeListener 属性。摆脱那个论点。

    public void changeListener() {
    

    另见:


    与具体问题无关,您正确使用了click(尽管您可以完全省略它),但您的问题标题提到了change,这确实是复选框的错误事件和单选按钮。

    另见:

    【讨论】:

    • 非常感谢!我很抱歉回答我的琐碎甚至愚蠢的问题给您带来不便。非常感谢您花时间回答。
    猜你喜欢
    • 2014-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多