Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5949819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:18:18+00:00 2026-05-22T17:18:18+00:00

The page is generated correctly with appropriate values in managed bean, but ajax events

  • 0

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 be somewhere within tags, but I don’t see it.

<f:view>
    <h:form>
        <h:messages />
        <h:panelGrid columns="3">

            <h:outputLabel value="Choose your faculty: *" for="faculties" />
            <h:selectOneMenu id="faculties" value="#{registrateStudent.selectedFaculty}" >
                <f:ajax event="change" listener="#{registrateStudent.genSpecializations}" execute="faculties" render="specializations" />                        
                <f:selectItems value="#{registrateStudent.listFaculty}" var="curFac" itemLabel="#{curFac.name}" itemValue="#{curFac}" />
            </h:selectOneMenu>
            <h:message id="message_faculties" for="faculties" />

            <h:outputLabel value="Choose your specialization: *" for="specializations" />
            <h:selectOneMenu id="specializations" value="#{registrateStudent.selectedSpecialization}" >
                <f:selectItems value="#{registrateStudent.listSpecialization}" var="curSpec" itemLabel="#{curSpec.name}" itemValue="#{curSpec}"/>
            </h:selectOneMenu>
            <h:message id="message_specializations" for="specializations" />                    

Managed Bean:

@ManagedBean(name = "registrateStudent")
@ViewScoped
public class RegistrateStudent {


    private Faculty selectedFaculty;
    private List<Faculty> listFaculty;
    private Specialization selectedSpecialization;
    private List<Specialization> listSpecialization;
    private boolean showSpecialization = false;


    /** Creates a new instance of RegistrateStudent */
    public RegistrateStudent() {
        users = new Users();
        System.out.println("poaposd1");
        student = new Student();
    }

    @PostConstruct
    public void init() {
        listFaculty = ff.findAll();
        if (listFaculty != null) {
            selectedFaculty = listFaculty.get(0);
            listSpecialization = sf.findByFaculty(selectedFaculty.getIdFaculty());
            if (listSpecialization != null) {
                selectedSpecialization = listSpecialization.get(0);
            }
            else {}
        } else {}
    }

   public void genSpecializations(AjaxBehaviorEvent event) {
        if (sf.findByFaculty(selectedFaculty.getIdFaculty()) != null) {
            this.showSpecialization = true;
        } else {
            JsfUtil.addSuccessMessage("faculties", "We don't have specializations for such faculty");
        }
    }
}

UPDATE:

I’ve found out a few interesting things:

<f:ajax> tag doesn’t work at <h:link>, <h:selectOneMenu>, <h:button>, <h:commandButton>. In this cases incorrect values in render attribute is not noticed, but incorrect value of event attribute generate an error.

<h:outputLabel>, <h:inputText> work with <f:ajax> properly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:18:18+00:00Added an answer on May 22, 2026 at 5:18 pm

    The <f:ajax> requires jsf.js file being included in the HTML <head>. It contains all JS functions for doing the JSF ajax magic.

    To achieve this, ensure that you’re using <h:head> instead of <head> in the master template. JSF will then automatically include the necessary <script> element there pointing to jsf.js.

    <!DOCTYPE html>
    <html lang="en"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets">
        <h:head>
            <title>Look, with h:head</title>
        </h:head>
        <h:body>
            Put your content here.
        </h:body>
    </html>
    

    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:

    <f:ajax> tag doesn’t work at <h:link>, <h:selectOneMenu>, <h:button>, <h:commandButton>. In this cases incorrect values in render attribute is not noticed, but incorrect value of event attribute generate an error.

    <h:outputLabel>, <h:inputText> work with <f:ajax> properly.

    The <h:link> and <h:button> are intented for GET requests only, not POST requests. It should however work just fine on <h:selectOneMenu> and <h:commandButton>. 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

    <!DOCTYPE html>
    <html lang="en"
        xmlns:h="http://java.sun.com/jsf/html" 
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
    >
        <h:head>
            <title>SO question 6089924</title>
        </h:head>
        <h:body>
            <h:form>
                <h:selectOneMenu value="#{bean.selected}">
                    <f:selectItem itemValue="#{null}" itemLabel="Select..." />
                    <f:selectItem itemValue="one" />
                    <f:selectItem itemValue="two" />
                    <f:selectItem itemValue="three" />
                    <f:ajax listener="#{bean.listener}" render="result" />
                </h:selectOneMenu>
            
                <h:commandButton value="commandButton" action="#{bean.submit}">
                    <f:ajax listener="#{bean.listener}" render="result" />
                </h:commandButton>
            
                <h:outputText id="result" value="#{bean.selected} #{bean.result}" />
                
                <h:messages />
            </h:form>
        </h:body>
    </html>
    

    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'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have generated .xlsx reports on server, and page with direct links to these
I have the following Regex to match all link tags on a page generated
I have a PHP-generated page which is displaying some data about a set of
I have a wordpress-generated page where I need some posts (in a specific category)
I have a page that is generated which inserts an HTML comment near the
I have a generated HTML page with flash content in it. I am trying
On my web site I have XMLs with my page contents (automatically generated from
I have a page with a few fields and a runtime-generated image on it.
I would like to turn the HTML generated by my CFM page into a
I have long tables generated by datagrid control that go beyond the page width.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.