H:selectManyChexkbox`s< F:Ajax事件="按一下[听者不火,并给出了一个错误 [英] h:selectManyChexkbox`s <f:ajax event="click" listener doesn't fire and gives an error

查看:304
本文介绍了H:selectManyChexkbox`s< F:Ajax事件="按一下[听者不火,并给出了一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当用户选择/取消选择一些在H火灾事件变化监听器:selectManyCheckbox,如果离开它单独什么都不发生。

我的XHTML:

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

< HTML LANG =EN的xmlns =htt​​p://www.w3.org/1999/xhtml
的xmlns:UI =htt​​p://java.sun.com/jsf/facelets
的xmlns:H =htt​​p://java.sun.com/jsf/html
的xmlns:F =htt​​p://java.sun.com/jsf/core
的xmlns:C =htt​​p://java.sun.com/jsp/jstl/core>

< H:头>
<链接相对=样式类型=文本/ CSS
    HREF =/ juritest /资源/ CSS / style.css文件/>
<脚本类型=文/ JavaScript的
    SRC =/ juritest /资源/ JS / jQuery的-1.8.2.js>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =/ juritest /资源/ JS / menu.js档案>< / SCRIPT>
< / H:头>

< H:身体GT;
<用户界面:作文模板=../../模板/ gridsTemplate.xhtml>
    < UI:定义名称=内容>
        ...
                < H:panelGroup中风格=文本对齐:左>
                    <小时/>
                    &所述; H:selectManyCheckbox
                        值=#{gridPopUpBean.oneQuestionUserAnswers}
                        布局=pageDirection>
                        < F:选择信息itemValue =A
                            itemLabel =#{gridPopUpBean.currentQuestion.a}/>
                        < F:选择信息itemValue =B
                            itemLabel =#{gridPopUpBean.currentQuestion.b}/>
                        < F:选择信息itemValue =C
                            itemLabel =#{gridPopUpBean.currentQuestion.c}/>
                        < F:Ajax事件=点击监听器=#{gridPopUpBean.changeListener()}/>
                    < / H:selectManyCheckbox>
                < /小时:panelGroup中>
   ...
 

我得到一个错误说一个或多个资源具有'头'的目标,但没有头组件已在视图中定义的。我有< H:头部>不仅仅是<头,我读了,这是一个可能的问题。

和从bean的片段:

 公共无效的ChangeListener(ValueChangeEvent E){

    改变=真;
}
 

我已经试过无< F:AJAX像

 < H:selectManyCheckbox
                        值=#{gridPopUpBean.oneQuestionUserAnswers}valueChangeListener =#{gridPopUpBean.changeListener()}的onclick =提交()
                        布局=pageDirection>
                        < F:选择信息itemValue =A
                            itemLabel =#{gridPopUpBean.currentQuestion.a}/>
                        < F:选择信息itemValue =B
                            itemLabel =#{gridPopUpBean.currentQuestion.b}/>
                        < F:选择信息itemValue =C
                            itemLabel =#{gridPopUpBean.currentQuestion.c}/>
                        < F:Ajax事件=点击监听器=#{gridPopUpBean.changeListener()}/>
                    < / H:selectManyCheckbox>
 

但没有运气...

解决方案
  

一个或多个资源具有'头'的目标,但没有头组件已在视图中定义的我有< H:头不只是< HEAD>,我读了这是一个可能的问题。

之外&LT任何东西; UI:组合物> 忽略。如果你需要一个< H:头> ,它需要去主模板中的 gridsTemplate.xhtml (或任何其父模板)。

另外,如果你没有使用一个可视化编辑器为您的XHTML文件(像Dreamweaver),那么我强烈建议停止把任何内容外&LT; UI:组合物&gt; ,<一个href="http://stackoverflow.com/questions/15991653/javascript-does-not-work-under-jsf-template-again">otherwise你把自己的困惑。

参见:

  • <一个href="http://stackoverflow.com/questions/4792862/how-to-include-another-xhtml-in-xhtml-using-jsf-2-0-facelets/4793959#4793959">How使用JSF 2.0 Facelets的包括另外XHTML在XHTML?

 &LT; F:Ajax事件=点击监听器=#{gridPopUpBean.changeListener()}/&GT;

公共无效的ChangeListener(ValueChangeEvent E){
 

你混淆 valueChangeListener &LT; F:AJAX收听GT; 。该 ValueChangeEvent 的说法只适用于 valueChangeListener UIInput 组件。摆脱这样的说法的。

 公共无效的ChangeListener(){
 

参见:

  • <一个href="http://stackoverflow.com/questions/11879138/when-to-use-valuechangelistener-or-fajax-listener/11883021#11883021">When使用valueChangeListener或f:ajax的听众

无关的具体问题,您正确使用点击(尽管你可以放心地完全忽略它),但是你的问题的标题提到变更键,这确实是错误的事件复选框和单选按钮。

参见:

  • <一个href="http://stackoverflow.com/questions/7886453/what-values-can-i-pass-to-the-event-attribute-of-the-fajax-tag/7889098#7889098">What值我可以传递给f的事件属性:AJAX标记

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.

My 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." I have < h:head> not just < head>, I read that this was a possible problem.

And the snippet from the bean:

public void changeListener(ValueChangeEvent e) {

    change = true;
}   

I have tried without < f:ajax like

<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.

Anything outside <ui:composition> is ignored. If you need a <h:head>, it needs to go in the master template, the gridsTemplate.xhtml (or any of its parent templates).

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.

See also:


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

public void changeListener(ValueChangeEvent e) {

You're confusing valueChangeListener with <f:ajax listener>. The ValueChangeEvent argument is only applicable to valueChangeListener attribute of an UIInput component. Get rid of that argument.

public void changeListener() {

See also:


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.

See also:

这篇关于H:selectManyChexkbox`s&LT; F:Ajax事件=&QUOT;按一下[听者不火,并给出了一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆