The page is generated correctly with appropriate values in managed bean, but ajax events in these two h:selectOneMenus don\'t works. Listener is not called. An error has to
The
requires jsf.js
file being included in the HTML . It contains all JS functions for doing the JSF ajax magic.
To achieve this, ensure that you're using
instead of in the master template. JSF will then automatically include the necessary
element there pointing to
jsf.js
.
Look, with h:head
Put your content here.
Note that in a bit decent webbrowser with a bit decent webdeveloper toolset like Firefox's Web Developer Toolbar and/or Firebug you should immediately have noticed JS errors like jsf is undefined
when the ajax request is to be executed. That should at least have given something to think about.
Update: as per your update
I've found out a few interesting things:
tag doesn't work at
,
,
,
. In this cases incorrect values in
render
attribute is not noticed, but incorrect value ofevent
attribute generate an error.
,
work with
properly.
The
and
are intented for GET requests only, not POST requests. It should however work just fine on
and
. Don't you have more code into the complete picture which you omitted from the question for simplicity? Which JSF impl/version are you using? Are you using the right libraries in classpath? It look like that you must really have messed up something.
To convince you (and myself) I just created the following copy'n'paste'n'runnable testcase
SO question 6089924
with this bean
package com.example;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;
@ManagedBean
@ViewScoped
public class Bean implements Serializable {
private String selected;
private String result;
public void submit() {
System.out.println("submit");
}
public void listener(AjaxBehaviorEvent event) {
System.out.println("listener");
result = "called by " + event.getComponent().getClass().getName();
}
public String getSelected() {
return selected;
}
public void setSelected(String selected) {
this.selected = selected;
}
public String getResult() {
return result;
}
}
It runs fine with Mojarra 2.1.1 on Tomcat 7.0.12.
INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
INFO: Initializing Mojarra 2.1.1 (FCS 20110408) for context '/playground'