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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:38:12+00:00 2026-06-18T06:38:12+00:00

I have two components, one commandButton and a selectOneListbox. I need to update the

  • 0

I have two components, one commandButton and a selectOneListbox.

I need to update the value of the backing property binded to selectOneListBox after I click on the commandButton.

Both components are inside the same <h:form>.
The backing Bean is a Named/SessionScoped bean.

Here is the part of my page where the components are defined:

Button:

    <h:commandButton formnovalidate="formnovalidate" title="Select Variable" 
                     type="button" styleClass="button_green close_window" 
                     tabindex="2" id="btnSelectVar" value="Confirm">
         <f:ajax execute="lstVarSelected" event="click" 
                 listener="#{systemOptionsControl.updateText}" onevent="updateParent"/>
    </h:commandButton>


SelectOneListBox: (selectedVariable is a String and variables is a List of String)


    <h:selectOneListbox id="lstVarSelected" name="lstVarSelected" 
                        tabindex="1" value="#{systemOptionsControl.selectedVariable}" >
        <f:selectItems value="#{systemOptionsControl.variables}"/>
    </h:selectOneListbox>

After I click on button, I need to get the backing propert of the oneListBox, but JSF isnt calling the set method on backing bean. Then, when I try to get the value on my updateText method, i got a NullPointerException.

I’ve trie a lot of solutions and none worked, anyone can give any ideas?

Here is the xhtml:

    <!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:escriba="http://java.sun.com/jsf/composite/components/escriba"
      xmlns:f="http://java.sun.com/jsf/core" lang="pt-br" class="no-js">
    <body>
        <h:head>
            <h:outputScript name="jsf.js" library="javax.faces"/>
            <script language="javascript">
                function callParentButton(data) {
                    //Verifica o status da execução do ajax. 
                    var status = data.status;
                    //alert(status);
                    switch(status)
                    {
                        case 'begin':
                            break; 
                        case 'complete':
                            //Gets the name of parent button
                            var a = #{systemOptionsControl.idBtnAtualizarTextAreas}; 
                            //Calls the click.
                            var btn = document.getElementById(a.valueOf().name);
                            btn.click();
                            break;
                        } 
                    }
            </script>
        </h:head>
        <h:form prependId="false" id="frmVariables">
            <section class="box_padrao">
                <header id="box_padrao_header">
                    <h1>System Options</h1>            
                    <div id="actions_menu">
                        <h:commandButton type="button" title="Select Variable" styleClass="button_green" tabindex="2" 
                                         id="btnConfirmar" value="Confirm">
                            <f:ajax execute="lstVariables" event="click" listener="systemOptionsControl.updateText" onevent="callParentButton"/>
                        </h:commandButton>
                        <button type="button" title="Cancel" class="button_red close_window" tabindex="3" id="btnCancelar" name="btnCancel">Cancel</button>
                    </div> 
                </header>
                <div class="box_padrao_content">
                    <div class="grid_100">
                        <h2 class="legend">» Variables List </h2>   
                        <fieldset class="fieldset">
                            <div class="grid_100">
                                <h:selectOneListbox id="lstVariables" name="lstVariables" tabindex="1" value="#{systemOptionsControl.selectedVariable}" >
                                    <f:selectItems value="#{systemOptionsControl.variables}"/>
                                </h:selectOneListbox>
                            </div>
                        </fieldset>
                    </div>      
                </div>
            </section>
        </h:form> 
    </body>
</html>

And here is the Bean:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.xxx.rodrigoms.control;


import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

/**
 *
 * @author rodrigos
 */
@Named
@SessionScoped
public class SystemOptionsControl{    

    private String selectedVariable;

    @PostConstruct
    public void initialize() {
        //non-matter code
    }

    //<editor-fold desc="GETS/SETS">
    public String getIdBtnAtualizarTextAreas(){
        return "btnUpdateTextAreas";
    }

    public String getSelectedVariable() {
        return selectedVariable;
    }

    public void setSelectedVariable(String selectedVariable) {
        this.selectedVariable = selectedVariable;
    }

    public List<String> getVariables() {
        List<String> ret = new ArrayList<>();
        //just simulating
        ret.add("1");
        ret.add("2");
        ret.add("3");
        ret.add("4");
        return ret;
    }

    //</editor-fold>

    //<editor-fold desc="Other methods">
    public void updateText(){
        //I get the NullPointerException right on next line
        String variavelAInserir = "<".concat(this.selectedVariable).concat(">");,

        /*
        code do other suffs
        */
    }
    //</editor-fold>

    }

Sorry about any language errors, was need change some names because its a “job” for a company.

  • 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-06-18T06:38:13+00:00Added an answer on June 18, 2026 at 6:38 am

    Well, I solved using the binding property.

    After I bound a inputTextArea in my bean. I was able to get the selectedValue in my listener method.

    The reason for the execute not “really” execute the set method before the execution of the listener i didnt discover yet.

    Anyway, thank you two guys for the great help 🙂 This was my first time asking in stackoverflow and you two were very prestative 🙂

    Thanks!

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

Sidebar

Related Questions

I have two components. One is called InsideComp and one is called OutsideComp. OutsideComp
I have two JSF <h:selectOneMenu> components. One called category another is subcategory . If
Suppose I have two h:inputText components. I want to bind both of the text
I have two entities STOCK(name,amount) and PC_SYSTEMS(name,c_name), and i wish to update the components
In my metro application, I have two components one in C++ and another in
I have a JPanel with two components. one is a JFXPanel and JLabel, when
Imagine I have two TextInput components. How do I know which one is active,
We have two visual studio solutions for our product: one for our reusable components
I have two components with own maven dependencies combined into one enterprise project. It
In my JSF application I have two <h:inputText> components. I need to make sure

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.