[英]h:selectManyChexkbox`s <f:ajax event=“click” listener doesn't fire and gives an error
I want to fire an event change listener when the user selects / deselects something in the h:selectManyCheckbox, if it leaves it alone nothing should happen. 当用户在h:selectManyCheckbox中选择/取消选择某项时,我想触发一个事件更改侦听器,如果不理会它,则不会发生任何事情。
My xhtml: 我的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>
...
I get an error saying "One or more resources have the target of 'head', but no 'head' component has been defined within the view." 我收到一条错误消息:“一个或多个资源的目标是'head',但是视图中没有定义'head'组件。” I have < h:head> not just < head>, I read that this was a possible problem.
我有<h:head>而不只是<head>,我读到这是一个可能的问题。
And the snippet from the bean: 以及来自Bean的代码段:
public void changeListener(ValueChangeEvent e) {
change = true;
}
I have tried without < f:ajax like 我试过没有<f:ajax像
<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>
but with no luck... 但是没有运气
One or more resources have the target of 'head', but no 'head' component has been defined within the view." I have < h:head> not just < head>, I read that this was a possible problem.
一个或多个资源的目标是“ head”,但是视图中没有定义“ head”组件。”我有<h:head>而不只是<head>,我读到这是一个可能的问题。
Anything outside <ui:composition>
is ignored . <ui:composition>
之外的任何内容都将被忽略 。 If you need a <h:head>
, it needs to go in the master template, the gridsTemplate.xhtml
(or any of its parent templates). 如果需要
<h:head>
,则需要进入主模板, gridsTemplate.xhtml
(或其任何父模板)。
Further, if you aren't using a visual editor for your XHTML files (like Dreamweaver), then I strongly recommend to stop putting any content outside <ui:composition>
, otherwise you keep confusing yourself . 此外,如果您没有为XHTML文件(例如Dreamweaver)使用可视化编辑器,那么我强烈建议您停止将任何内容放在
<ui:composition>
, 否则您会感到困惑 。
<f:ajax event="click" listener="#{gridPopUpBean.changeListener()}"/> public void changeListener(ValueChangeEvent e) {
You're confusing valueChangeListener
with <f:ajax listener>
. 您将
valueChangeListener
与<f:ajax listener>
混淆了。 The ValueChangeEvent
argument is only applicable to valueChangeListener
attribute of an UIInput
component. ValueChangeEvent
参数仅适用于UIInput
组件的valueChangeListener
属性。 Get rid of that argument. 摆脱那个争论。
public void changeListener() {
Unrelated to the concrete problem, you correctly used click
(although you could safely omit it altogether), but your question title mentions change
and that is indeed the wrong event for a checkbox and radio button. 与具体问题无关 ,您可以正确使用
click
(尽管可以安全地完全忽略它),但是您的问题标题提到change
,对于复选框和单选按钮,这确实是错误的事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.