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 7635595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:28:00+00:00 2026-05-31T07:28:00+00:00

I am trying to make a simple admin page for managing users list. The

  • 0

I am trying to make a simple admin page for managing users list. The jsf code looks like this:

 <h:selectOneMenu  id="selectUser" value="#{adminBean.user_id}" valueChangeListener="#{adminBean.userSelected}" >
                    <f:selectItems value="#{adminBean.myModelUsersValues}" />   
                    <a4j:ajax event="valueChange" render="login password privilege_list" execute="@this"/>      
                 </h:selectOneMenu > 

   <table>
      <tr>
        <td><h:outputLabel styleClass="LabelStyle" value="login: "/></td>         
      </tr>
      <tr>
        <td>
            <h:inputText id="login" value="#{adminBean.login}"/>
        </td>   
        <td>
        <h:message for="login" style="color:red"/>
        </td>                        
      </tr>
      <tr>
        <td><h:outputLabel styleClass="LabelStyle" value="password: "/></td>         
      </tr>
      <tr>
        <td>
            <h:inputText id="password" value="#{adminBean.password}"/>
        </td>   
        <td>
        <h:message for="password" style="color:red"/>
        </td>                      
      </tr>       
      <tr>
        <td><h:outputLabel styleClass="LabelStyle" value="privilege list: "/></td>         
      </tr>
      <tr>
        <td>
            <h:selectManyListbox  id="privilege_list" value="#{adminBean.privilegeList}">
                <f:selectItems value="#{adminBean.privilegeValues}" />                          
             </h:selectManyListbox > 
        </td>    
        <td>
        <h:message for="privilege_list" style="color:red"/>
        </td>                      
      </tr>
    </table>
    <br/>
    <h:commandButton id="addButton" value="Add" action="#{adminBean.addUser}" styleClass="ButtonStyle"/>               
    <h:commandButton id="deleteButton" value="Delete" action="#{adminBean.deleteUser}" styleClass="ButtonStyle"/>                  
    <h:commandButton id="clearButton" value="Clear" action="#{adminBean.clear}" styleClass="ButtonStyle"/>  

The problem is that when the page loads, all the items are empty. Now When I click on ‘add’ button I have discovered that the valueChangeListener="#{adminBean.userSelected}" runs, which replaces my privilege list with the ones from the first user. The same is when I use the clear button – all fields are empty, but when I click on the add button again, the list is the one from the first user (and only the list – no other input texts). I tried adding immediate="true" to the add button and that solves this problem, but off course then all the values I put into input text are not passed through to the adminBean.addUser action method. My bean is viewscoped (I needed to use it because of the validation error on selectManyListBox). Here is the Java code (the addUser method so far only sends a logger method and checks i login exists, and if sth was selected on the priv. list):

@ManagedBean(name="adminBean")
@ViewScoped
public class AdminBean {
private String user_id ="";
private String login ="";
private String password ="";
private ArrayList<String> privilegeList = new ArrayList<String>();

private User model = new User();
private TreeMap<String, User> usersValuesBackendMap = new TreeMap<String, User>();
private TreeMap<String, String> privilegesValues = new TreeMap<String, String>();
private TreeMap<String, String> myModelUsersValues = new TreeMap<String, String>();

...

    @javax.annotation.PostConstruct
    public void init()
    {       

        usersValuesBackendMap = queryDAO.getAllUsers();

        for (Map.Entry<String, User> usr : usersValuesBackendMap.entrySet()) {
            myModelUsersValues.put(usr.getValue().getLogin(), usr.getKey() );
        }

        privilegesValues = queryDAO.getFullPrivilegeList();
        user_id = ""; 
    }
    public void userSelected(ValueChangeEvent event){
           String newValue = event.getNewValue().toString();       

           User user = usersValuesBackendMap.get(newValue);

           login = user.getLogin();
           password = user.getPassword();
           privilegesValues.clear();
           for (String privilege: user.getPrivilegeValues() ){      
               privilegesValues.put(privilege, privilege);
           }
       }

        public String clear(){

            user_id ="";
            login ="";
            password ="";
            privilegesValues = queryDAO.getFullPrivilegeList(); 
            return "";
        }

Interestingly I added immediate=”true” to the clearing method and then sth. opposite happens – the list is OK but the inputTexts are filled.

  • 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-31T07:28:01+00:00Added an answer on May 31, 2026 at 7:28 am

    Some facts:

    1. The valueChangeListener runs when !oldValue.equals(newValue).
    2. The valueChangeListener is not a client side event listener. It’s entirely server side.
    3. The valueChangeListener is completely independent on whether it’s an ajax or normal request. It’s invoked on all types of requests, including the normal form submit.

    You need <a4j:ajax listener> instead.

    <h:selectOneMenu  id="selectUser" value="#{adminBean.user_id}">
        <f:selectItems value="#{adminBean.myModelUsersValues}" />   
        <a4j:ajax event="valueChange" listener="#{adminBean.userSelected}" render="login password privilege_list" execute="@this"/>      
    </h:selectOneMenu > 
    

    with

    public void userSelected(AjaxBehaviorEvent event){
        User user = usersValuesBackendMap.get(user_id);
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
I am trying to make a simple redirector controller in CakePHP. I'd like the
This one is killing me. I'm trying to make a simple console app that
I'm trying to make a simple MySQL Admin thing with php and jQuery. I've
I am trying to make a query with Hibernate criteria API. It looks simple
Trying to make simple minesweeper game in python, but have one problem. I have
I am trying to make simple notepad application for learning android development. So, to
I'm trying to make simple script using jquery $post function to pass data to
I'm trying to make a simple drawing app in c++, but i'm having trouble

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.