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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:47:47+00:00 2026-06-17T12:47:47+00:00

in this page either h:commandButton doesn’t trigger action method in managed bean but when

  • 0

in this page either h:commandButton doesn’t trigger action method in managed bean but when I click button it reloads current page. I don’t know why please help.

    <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition 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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Bootstrap 101 Template</title>
    <!-- Bootstrap -->
    <h:outputStylesheet library ="css" name="bootstrap.css"/>
    <h:outputStylesheet library ="css" name="bootstrap-responsive.css"/>
    <h:outputScript library="js" name="bootstrap.js"/>
    <h:outputScript library="js" name="bootstrap-responsive.js"/>
  </h:head>
  <h:body>
      <h:form>           
                              <label><h3>Search</h3></label>


                              <h:selectOneMenu id="searchtype" value="#{searchView.searchType}" style="width: 230px">
                                  <f:selectItems value="#{searchView.searchType}"/>

                              </h:selectOneMenu>
                              <br/>
                              <h:inputText id="searchvalue" value="#{searchView.searchvalue}" required="true" style="height: 30px; width: 230px">
                                  <p:watermark value="Search type" for="searchvalue"/>
                              </h:inputText>
                              <br/>

                              <h:commandButton id="searchbtn" value="Search" action="#{searchView.prepareSearchResultView()}" styleClass="btn"/>

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

And my searchView managed bean is session scoped and here is prepareSearchResultView() method in managed bean;

    public String prepareSearchResultView(){

    this.searchResultList = searchCustomer();
    if(!this.searchResultList.isEmpty()){
        this.citizenSearchResultList = getCitizenSearchList();
        this.orgSearchResultList = getOrganizationSearchList();
        if(getCitizenSearchList().getRowCount() >0){
            return "citizensearchlist";
        }else if(getOrganizationSearchList().getRowCount()>0){
            return "orgsearchlist";
        }

    }else
        return "nosearchresult";
    //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "no such result", "no such result"));
    return null;
}

and getSearchType() method

    public Map<String, Object> getSearchType(){
    Map<String, Object> returnMap = new LinkedHashMap<String, Object>();
    if(loginview.isAbleToGetCitizenInfo() || loginview.isUserAdmin()){
        returnMap.put("searchtype1", "searchcitizenbyregno");
        returnMap.put("searchtype2", "searchcitizenbyname");
    }
    if(loginview.isAbleToGetOrgInfo() || loginview.isUserAdmin()){
        returnMap.put("searchtype3", "searchorgbyregno");
        returnMap.put("searchtype4", "searchgorgbyname");
        returnMap.put("searchtype5", "searchorgbystateregno");
    }
    return returnMap;
}
  • 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-17T12:47:49+00:00Added an answer on June 17, 2026 at 12:47 pm

    You are using <h:selectOneMenu> in a wrong way. Your value in the selectMenu is a map and you cannot set a value of a type of map from a select menu without using a converter. In the selectitems you should bind the value attribute to some string in the managed bean. Then in your actionMethod you can retrieve the selected value from the map by using this selected type.

    <h:selectOneMenu id="searchtype" value="#{searchView.selectedType}" style="width: 230px">
        <f:selectItems value="{searchView.searchType}"/>
    </h:selectOneMenu>
    

    Please take a look at the following post to understand the concept better: Primefaces selectOneMenu listener not called with Objects other than Strings

    Also retrieving f:selectItems values through a getter which does business logic is not a good practice. You should create a property in your managed bean which initialize that map in the constructor. Even more instead of using a map, it is better to use a list and encapsulate your key and value in a custom object.

    <h:selectOneMenu id="searchtype" value="#{searchView.selectedType}" style="width: 230px">
        <f:selectItems value="{searchView.searchType}" 
                       var="searchType" 
                       itemLabel=#{searchType.key} 
                       itemValue=#{searchType.value}/>
    </h:selectOneMenu>
    
    List<RowItems> searchType = Lists.newArrayList(); // guave constructor
    
    @PostConstruct
    public void initBean(){
        if(loginview.isAbleToGetCitizenInfo() || loginview.isUserAdmin()){
            searchType.add(new RowItems("searchType1", "searchcitizenbyregno"));
            searchType.add(new RowItems("searchtype2", "searchcitizenbyname"));
        }
        if(loginview.isAbleToGetOrgInfo() || loginview.isUserAdmin()){
            searchType.add(new RowItems("searchtype3", "searchorgbyregno"));
            searchType.add(new RowItems("searchtype4", "searchgorgbyname"));
            searchType.add(new RowItems("searchtype5", "searchorgbystateregno"));
        }
    }
    
    public List<RowItems> getSearchType(){
        return searchType
    }
    

    Lastly your prepareSearchList function’s last statement return null is not necessary and should be removed as it is an unreachable code according to what you have posted.

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

Sidebar

Related Questions

Check this page. On either firefox, chrome, or IE9 / 10 the tabs on
This page should display a Google ad. I Tried everything but it's not working.
This page indicates that TabPage has a GotFocus event, but in Visual Studio 2008
This page says to use: var object = $.extend({}, object1, object2); But I prefer
http://leaverou.github.com/animatable/ On this page, click a block and see the black box that appears.
I'm doing rel=external on the link that opens this page, so the DOM reloads
On this page of association mapping, there's an example in the manytomany section. But
I accidentally come across this page new keyword in method signature and I found
To see the issue go to this page and click the next text. The
I want to use this page to determine if the user has either updated

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.