H:selectManyChexkbox`s< F:Ajax事件="按一下[听者不火,并给出了一个错误出了、听者、并给、错误

2023-09-10 14:58:27 作者:别回忆你回不去

我想,当用户选择/取消选择一些在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){

    改变=真;
}
 
陈冠希又晒出了一款Air Jordan 1联名,确认将限量发售

我已经试过无< 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),那么我强烈建议停止把任何内容外< UI:组合物> ,otherwise你把自己的困惑。

参见:

How使用JSF 2.0 Facelets的包括另外XHTML在XHTML?

 < F:Ajax事件=点击监听器=#{gridPopUpBean.changeListener()}/>

公共无效的ChangeListener(ValueChangeEvent E){
 

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

 公共无效的ChangeListener(){
 

参见:

When使用valueChangeListener或f:ajax的听众

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

参见:

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:

How to include another XHTML in XHTML using JSF 2.0 Facelets?

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

When to use valueChangeListener or f:ajax listener?

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:

What values can i pass to the event attribute of the f:ajax tag?
 
精彩推荐