33310

h:selectManyChexkbox`s

Question:

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

Answer1:

<blockquote>

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

</blockquote>

Anything outside <ui:composition> is <strong>ignored</strong>. 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>, <a href="https://stackoverflow.com/questions/15991653/javascript-does-not-work-under-jsf-template-again" rel="nofollow">otherwise you keep confusing yourself</a>.

<h3>See also:</h3> <ul><li><a href="https://stackoverflow.com/questions/4792862/how-to-include-another-xhtml-in-xhtml-using-jsf-2-0-facelets/4793959#4793959" rel="nofollow">How to include another XHTML in XHTML using JSF 2.0 Facelets?</a></li> </ul><hr /><blockquote> <f:ajax event="click" listener="#{gridPopUpBean.changeListener()}"/> public void changeListener(ValueChangeEvent e) { </blockquote>

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() { <h3>See also:</h3> <ul><li><a href="https://stackoverflow.com/questions/11879138/when-to-use-valuechangelistener-or-fajax-listener/11883021#11883021" rel="nofollow">When to use valueChangeListener or f:ajax listener?</a></li> </ul><hr />

<strong>Unrelated</strong> 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.

<h3>See also:</h3> <ul><li><a href="https://stackoverflow.com/questions/7886453/what-values-can-i-pass-to-the-event-attribute-of-the-fajax-tag/7889098#7889098" rel="nofollow">What values can I pass to the event attribute of the f:ajax tag?</a></li> </ul>

Recommend

  • javax.faces.view.facelets.TagAttributeException
  • Update component in a different window/tab without manually refreshing it
  • PrimeFaces poll does not work
  • Drag and drop of images between layout units in primefaces layout is not working?
  • Redirect to page using JSF PhaseListener
  • java.io.FileNotFoundException when file is in folder
  • Injecting @Stateful bean into another @Stateful bean
  • Define a property in Facelets page
  • How to handle non-ASCII Characters in Java while using PDPageContentStream/PDDocument
  • JSF Managed bean in jar not instantiated
  • won't render when list-property of object is used
  • Netbeans reports “no library found for namespace” for PrimeFaces tags from Maven
  • Change color/syntax highlighting for JSF/Facelets EL expressions in Eclipse
  • How to use Facelets' ui:repeat tag in JSP?
  • Drag and Drop between different layout units in Primefaces
  • Batching in py2neo
  • How to display the hotel names that have the maximum count from data base by calculating sum in PHP?
  • Why are views not counted if you embed a youtube iframe dynamically using jquery?
  • NetBeans doesn't see style.css [duplicate]
  • Jquery Show & ScrollTop (or ScrollTo)
  • How to add regEx in angular filter
  • JSF2.0 + Primefaces 3.0.1 + jquery 1.6.4 + p:commandLink + IE8 throws Unexpected call to method or p
  • Angularjs pass function from Controller to Directive (or call controller function from directive) -
  • Simulate click Geckofx vb,net
  • How to view images from protected folder with php?
  • Adjust width of select element according to selected option's width
  • Webgrid not refreshing after delete MVC
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Jquery UI tool tip close icon
  • HTML download movie download link
  • Traverse Array and Display in markup
  • trying to dynamically update Highchart column chart but series undefined
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • How do I configure my settings file to work with unit tests?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs
  • java string with new operator and a literal