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

  • SEARCH
  • Home
  • 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 1041723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:23:48+00:00 2026-05-16T15:23:48+00:00

This is my code in my managed bean :- <?xml version=’1.0′ encoding=’UTF-8′ ?> <!DOCTYPE

  • 0

This is my code in my managed bean :-

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <center>
            <h:form>
                <h2> <u>Select Fruit(s). </u> </h2>

                <!-- Value Change Listener is entirely superflous. You can make a full blown project without requiring the need to ever use this...This is
                just for demo purpose..-->

                <h:selectManyMenu onchange="document.forms[0].submit();" style="height: 200px;font-size: 1.5em;width: 200px;"   >
                    <f:selectItems value="#{actionValueLisBean.fruitsList}" var="fruit" itemLabel="#{fruit}" itemValue="#{fruit}"/>

                    <f:valueChangeListener type="beans.ActionValueLisBean"/>
                </h:selectManyMenu>

                <h3> Your previous selection is :<h:outputText value="#{actionValueLisBean.prevSel}"/></h3>
                <h3>Your current selection is :<h:outputText value="#{actionValueLisBean.currSel}"/></h3>

            </h:form>
        </center>
    </h:body>
</html>

This is my bean :-

package beans;

import com.sun.jmx.remote.internal.ArrayQueue;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;

@ManagedBean
@RequestScoped
public class ActionValueLisBean implements ValueChangeListener {


    private List<String> fruitsList;
    private String currSel;
    private String prevSel;

    public String getCurrSel() {
        return currSel;
    }

    public void setCurrSel(String currSel) {
        this.currSel = currSel;
    }

    public String getPrevSel() {
        return prevSel;
    }

    public void setPrevSel(String prevSel) {
        this.prevSel = prevSel;
    }



    public List<String> getFruitsList() {
        return fruitsList;
    }

    public void setFruitsList(List<String> fruitsList) {
        this.fruitsList = fruitsList;
    }



    public ActionValueLisBean() {
        fruitsList = new ArrayQueue<String>(5);

        fruitsList.add("Apple");
        fruitsList.add("Mango");
        fruitsList.add("Banana");
        fruitsList.add("Peach");
        fruitsList.add("Plum");

    }

    @Override
    public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {

            if(event.getOldValue() != null)
                prevSel = event.getOldValue().toString();
            if(event.getNewValue() != null)
                currSel  = "abc";

    }


}

And then i have prevSel and currSel is bound to h:outputText. But the value is not getting even though the processValueChange is fired correctly and System.out.println(event.getNewValue()); is also working fine. I tried setting different scopes of bean too but no use. I know ValueChangeListener is entirely useless. Still i want to know how it works.

Thanks in advance 🙂

  • 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-16T15:23:49+00:00Added an answer on May 16, 2026 at 3:23 pm

    I am not sure what you mean with “the value is not getting”. You should clarify that bit more.

    At least, its sole purpose is to listen on a value change so that you can do some business stuff based on the change such as logging or preloading some stuff related to the new value. When the initial value equals to the submitted value, then this method won’t be invoked.

    Here’s a code snippet to play around with it yourself:

    <h:form>
        <p>Input value: <h:inputText value="#{bean.value}" valueChangeListener="#{bean.change}"/></p>
        <p>Old value: <h:outputText value="#{bean.oldValue}" /></p>
        <p>New value: <h:outputText value="#{bean.newValue}" /></p>
        <p><h:commandButton value="submit" action="#{bean.submit}" /></p>
    </h:form>
    

    Bean:

    package com.example;
    
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    import javax.faces.event.ValueChangeEvent;
    
    @ManagedBean
    @ViewScoped
    public class Bean {
    
        private String value;
        private String oldValue;
        private String newValue;
    
        public void submit() {
            System.out.println("Submit: " + value);
        }
    
        public void change(ValueChangeEvent event) {
            oldValue = (String) event.getOldValue();
            newValue = (String) event.getNewValue();
            System.out.println("Change: " + oldValue + " to " + newValue);
        }
    
        public String getValue() {
            return value;
        }
    
        public String getOldValue() {
            return oldValue;
        }
    
        public String getNewValue() {
            return newValue;
        }
    
        public void setValue(String value) {
            this.value = value;
        }
    
    }
    

    Update: as per your update: you’re using two different instances of the bean. You’re actually displaying the values of the managed bean, not of the bean which is newly created by f:valueChangeListener.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the easiest way to do this? Is it possible with managed code?
Everyone uses source-code control to manage versions (right?) and this provides some level of
This code in JS gives me a popup saying i think null is a
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a
This code always works, even in different browsers: function fooCheck() { alert(internalFoo()); // We
This code does not seem to compile, I just need to write something to
This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
This code is executed by many way. When it's executed by the form button

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.