Need to invoke bean method prior to initial page

I have a web application with a default welcome page (index.jsp) that automatically forwards to a page with JSF tags in it (home.jsp). I use:
<jsp:forward page="home.faces" />to accomplish this. This works fine for rendering the JSF tags in the page as long as the page does not need data from the server.
However, this is not the case. I need to have a backing bean method invoked as follows:
  // ActionListener handler.
  public void retrievePagerList(ActionEvent event) {
    if (logger.isDebugEnabled()) {
      logger.debug("In retrievePagerList method of backing PagerBean.");
    try {
      setPagers(PagerDAO.selectAll());
    catch (SQLException e) {
      logger.error("Error retrieving list of pagers: ", e);
  public void setPagers(List pagers) {
    this.pagers = pagers;
    if (logger.isDebugEnabled()) {
      logger.debug("Number of pagers set: " + pagers.size());
  }I want to load a list of objects from the database so that the initial page shown to the users has a list of pagers displayed as follows:
<f:view>
  <h:form>
  <h:dataTable styleClass="dataTable"
               value="#{pagerBean.pagers}"
               var="pager">
    <h:column>
    <h:commandLink id="editPager"
                   title="Edit Pager"
                   value="Edit"
                   action="edit"
                   actionListener="#{pagerBean.editPager}">
    </h:commandLink>
    </h:column>
    <h:column>
      <h:outputText value="#{pager.pagerType}"/>
    </h:column>
    <h:column>
      <h:outputText value="#{pager.pagerName}"/>
    </h:column>
  </h:dataTable>
  </h:form>
</f:view>How can I accomplish this? I cannot seem to find a way to have a backing bean method invoked to put objects into the request (or session scope) in order for the initial JSP to display properly.

jsf 1.2 will contains beforePhaseListener attribute for f:view that allows to call some code before page is loaded. For the current jsf version, it is usually recommended to register your own phase listener that is invoked "before Render Response" phase.
Sergey : jsfTutorials.net

Similar Messages

  • How to invoke bean method after query executed?

    Jdeveloper 11.1.1.2:
    I have a bean that backs a JSF page.
    The bean has a method that shows/hides certain GUI components based on the values of other components.
    I would like to invoke this method automatically after the page has been fully loaded.
    I tried invoking the method in the AfterPhase of the f:view and at bean construction time. Both approaches failed.
    I think I need a listener that gets invoked after the query has been executed.
    Any idea?
    thanks

    Hi,
    if the bean is a backing bean and it is supposed to hide components, then why don't you create a reference of the components to the backing bean so that the displayed property is dynamically evaluated ? Sounds like this is what you want to do
    Frank

  • Which component invoked bean method

    When a form is submitted and validation errors occur, I'd like to indicate the component that caused the validation error with a different style.
    For example:
    JSF page:
                <h:form id="form">
                    <h:panelGrid columns="2">
                        <t:outputText value="Name"/>
                        <h:panelGroup>
                            <t:inputText value="#{UserBean.newUser.name}" id="name" required="true" style="#{UserBean.styleBorder}" />
                            <h:message for="name" style="color:red;text-decoration:overline" />
                        </h:panelGroup>
                        <t:outputText value="First name" />
                        <h:panelGroup>
                            <t:inputText value="#{UserBean.newUser.firstname}" id="firstname" required="true" />
                            <h:message for="firstname" style="color:red;text-decoration:overline" />
                        </h:panelGroup>
                        <h:outputText value="" />                  
                        <t:commandButton action="#{UserBean.addUser}" value="Add user" />
                    </h:panelGrid>
                </h:form>UserBean code:
        public String getStyleBorder() {
            FacesContext context = FacesContext.getCurrentInstance();
            if (context.getMessages("form:name").hasNext() == true) {  //Er zijn messages aanwezig voor deze component
                return "border-style:solid;border-color:#FF0000";
            else {
                return "";
        }In this example, when the user didn't fill in the name component correctly, a red border is drawed at the name-component.
    In the context.getMessages method in the UserBean whoever, I need to hardcode the id of the component that needs to be checked for validation errors.
    Therefore, I would need a getStyleBorder method for each component of the form.
    Like this:
    JSF page:
                <h:form id="form">
                    <h:panelGrid columns="2">
                        <t:outputText value="Name"/>
                        <h:panelGroup>
                            <t:inputText value="#{UserBean.newUser.name}" id="name" required="true" style="#{UserBean.styleBorderName}" />
                            <h:message for="name" style="color:red;text-decoration:overline" />
                        </h:panelGroup>
                        <t:outputText value="First name" />
                        <h:panelGroup>
                            <t:inputText value="#{UserBean.newUser.firstname}" id="firstname" required="true" style="#{UserBean.styleBorderFirstName}" />
                            <h:message for="firstname" style="color:red;text-decoration:overline" />
                        </h:panelGroup>
                        <h:outputText value="" />                  
                        <t:commandButton action="#{UserBean.addUser}" value="Add user" />
                    </h:panelGrid>
                </h:form>UserBean code:
        public String getStyleBorderName() {
            FacesContext context = FacesContext.getCurrentInstance();
            if (context.getMessages("form:name").hasNext() == true) {  //Er zijn messages aanwezig voor deze component
                return "border-style:solid;border-color:#FF0000";
            else {
                return "";
        public String getStyleBorderFirstName() {
            FacesContext context = FacesContext.getCurrentInstance();
            if (context.getMessages("form:firstname").hasNext() == true) {  //Er zijn messages aanwezig voor deze component
                return "border-style:solid;border-color:#FF0000";
            else {
                return "";
        }This causes a lot of duplicate code.
    Is it possible to have only 1 getStyleBorder method that can handle the style for every component in the form?
    Is there a way to get the id of the component that invoked the getStyleBorder method?

    I'd to implement a PhaseListener for that. Listen on the beforePhase of PhaseId.RENDER_RESPONSE, get all client IDs with facesmessages by FacesContext#getClientIdsWithMessages(), retrieve the appropriate UIComponent for the client ID by UIViewRoot#findComponent() and set its style.

  • How to execute a backing-bean method before loading JSP Page?

    Hi everybody.
    Scene:
    An AdfForm, with
    -SelectChoice, referenced to a <list> of pageDef, which is referenced to an ADF BC.
    Goal:
    -Executing the query of the ADF BC before load the SelectChoice, to load the correct values.
    A good question to know:
    Exists any way to execute a method of backing before loading a JSP Page?
    Any similar to onload method of javascript. It could be fantastic.
    Thanks in advance,
    Jaime

    hi Jaime
    If I understand correctly, you are using the ADF Model for data binding.
    Because your goal is "Executing the query of the ADF BC ...", maybe you can also consider to refresh an executable in your Page Definition.
    See also "10.5.5 How to Use Refresh Correctly for InvokeAction and Iterator Bindings"
    at http://download.oracle.com/docs/html/B25947_01/bcdcpal005.htm#BJECHBHF
    It says "... You can use the Refresh property on iterator bindings and invokeAction executables in your page definition to control when each are evaluated during the ADF page lifecycle, either during the prepareModel phase, the prepareRender phase, or both. ...".
    Although you have posted your question in a structured way, which is a good thing, I think it would help to understand your question if you can explain how you determine "the correct values" for your list, what is varying?
    success
    Jan Vervecken

  • Invoke a method dynamically

    Hi,
    I want to invoke a method dynamically. I have the class name and method name in a variable and the list of import and export parameter for this method in an internal table. Now I need to invoke this method dynamically i.e. without having it to call in code like this classname->methodname(.....). I want something like reflection in java, where we can call the method using invoke method of method class ex:
    try {
    Method method = cls.getMethod( "setColor",
    new Class[] {Color.class} );
    method.invoke( obj, new Object[] );
    It would be helpful if you can provide a simple example on how it can be implemented in ABAP.
    Thanks,
    Raghavendra

    Hi,
         You can perform calls in that way as follows.
    You need to pass the parameters usingthe following table of type ABAP_PARAMBIND_TAB.
    DATA: ptab type ABAP_PARAMBIND_TAB,
               ptab_line like line of ptab.
    DATA: clas_name type stirng VALUE 'CLASS_NAME',
               method_name type string VALUE 'METHOD_NAME'.
    DATA: obj  type ref to OBJECT.
    create object obj type class_name.
    ptab_line-name = 'PARAM_NAME'.
    ptab_line-kind = CL_ABAP_OBJECTDESCR=>EXPORTING.
    Then you can use
    CALL METHOD  obj->(method_name) PARAMETER-TABLE ptab.
    Regards,
    Sesh

  • URGENT: How to Configure Ruote to Business Service that invokes 2 methods

    Hi,
    I am using ALSB 2.6.
    Currently I am working on a project, in which i have to configure business service and proxy service.
    Now the problem which i am facing is the following :-
    I'm trying to configure my Proxy service to route to 1 Business Service which in turn invokes 2 methods.
    I want to know how can i configure this route to business service that invokes 2 methods.
    Right now, to execute/ invoke any of the method i need to invoke each method by changing manually in the rotuing flow.
    Can any one tell me how can i configure both the methods for the same business service in a single rotuing flow only.
    Presently i am configuring it in this way:
    Route to BUSINESSSERVICE invoking METHOD1.
    At the place of method 1 theres a drop box from where you select the desired method.
    I want to know how to configure both the methods in single rotuing flow so that it invokes the desired method without manually editing it each time.
    What is the best solution to this problem? I would very much appreciate any help on this!
    Regards,
    Samir

    Hi,
    You can create a pipeline pair, add one (or more stages), and inside of the stage, invoke the a service callout to your business service.
    Regards,
    Fabio Douek.
    Regards,
    Fabio Douek

  • How to call a bean method through javascript?

    Hi,
    i want to call a bean method using the javascript.
    thansk in advance.

    hi
    i want to call a backing bean method thought javscript on the button click.
    i am inplementing addition of textbox at runtime.i wrote method and i am calling that on the button click.but the textbox is not created.
    the code is bleow
    public String doAction() {
         tryStuff1();
    return "samplejsf";
    public void tryStuff1()
    System.out.println("Enter the trystuff method");
         FacesContext facesContext = FacesContext.getCurrentInstance();
    UIViewRoot uIViewRoot = facesContext.getViewRoot();
    Application application = facesContext.getApplication();
    UIComponent formComp=uIViewRoot.findComponent("subbody:form1");
    HtmlPanelGrid grid= new HtmlPanelGrid();
    grid.setId("panelgrid2");
    grid.setColumns(2);
    grid.setBorder(2);
    //UIComponent panelGridComp=formComp.findComponent("subbody:panelgrid1");
    //UIComponent panelGroupComp=panelGridComp.findComponent("panelgroup2");
         HtmlOutputText output = new HtmlOutputText();
    output.setValue("dynamic jsf text2");
    System.out.println("hello output text2");
    output.setRendered(true);
    grid.getChildren().add(output);
    HtmlInputText input = new HtmlInputText();
    input.setSize(40);
    input.setValueBinding("value", (ValueBinding) application.createValueBinding("#{sample.text2}"));
    input.setRendered(true);
    grid.getChildren().add(input);
    System.out.println("hello output text1");
    grid.setRendered(true);
    formComp.getChildren().add(grid);
    System.out.println("hello output text3:");
    formComp.getRendersChildren();
    formComp.setRendered(true);
    public boolean getRendersChildren() {
         return true;
    jsp code is
    <h:form id="form1">
    <h:panelGrid columns="2" binding="#{sample.formElements}">
    </h:panelGrid>
    <h:panelGrid id="panelgrid1" columns="1">
    <h:panelGroup id="panelgroup1">
    <h:outputText value="hardcoded jsf text1"/>
    <h:inputText value="#{sample.text1}"/>
    </h:panelGroup>
    </h:panelGrid>
    <h:commandButton id="add" action="#{sample.doAction}" value="add" type="SUBMIT"/>
    </h:form>
    when i click on the button its going into the method and diaplying s.o.p but the text box is not updated to the page.
    why is it so.
    i thought there may be a problem in calling the method directly thru button. i want to try thru javascript calling the bean method.
    why is the page not updated.
    can u help me out
    thanks in advance
    sree

  • How to call a void bean method in a jsp ?

    I want to call a bean method from the jsp page. The method is void i.e it returns nothing.
    Lets say the bean id is mybean and the method name is beanmethod( ). I want to know in what type of jsp tags should I put mybean.beanmethod( ). Using jsp expression <%= mybean.beanmethod( ) %> gives error and so does scriptlet <% mybean.beanmethod( ) %>
    Can someone help me out. Thanx.
    Arshad

    did you already implement this?
    <jsp:useBean id="mybean" class="yourPackage.YourBean scope="session"/>
    use ";" at the end:
    <% mybean.beanmethod(); %>

  • How to call AMImpl method before loading the page(task_flow_config.xml)

    Hi experts,
    I have requirement like,
    I need to call AmImpl method, before rendering the page.(I heard like we can do it in task_flow_config.xml by using method_Invoke operation,But I am not sure about How it is going to work, also i need to know the implementation part,,,help pls )
    (I need to do in Task_Flow.)
    Inside that method I have some logic, where I will setting the BindVariable of my one ViewObject and I need to run the ViewOblect,So that DataShuold be available while page loading.
    I have some different logic after that,,,,
    can anyone suggest me for this??
    thanks
    Santosh

    thanks to Timo n TK,
    I have use case like,
    In the search page I have 2 LOV dropdowns say LOV1 and LOV2. Both list of values are created based on the independent View Objects based on the Query.
    LOV2 VO query is having the Bind Variable, for that Bind variable will be getting the value from the one of the AM method based on the user logged in.
    Also I need to display LOV2 dropdown in the page when user selects LOV1 as a 'SCM', for others it should be in hidden state.
    As per requirement I have to display LOV2 only for LOV1 value as 'SCM'. So I dont want to use valueChangeListner() for this.
    Instead I want populate LOV2 value before page rendering(because in that time i will be having all the parameter to populate ) by executing LOV2 VO Query.
    Once in search page user selects LOV1 as 'SCM', I should display 'LOV2' values in the dropdown.
    If i execute LOV2 VO in the AMImpl method say A() before page rendering ,then if user select LOV1 as 'SCM', will same data available in the dropdown (LOV2 dropdown is based on the LOV2VO)??
    Can u pls suggest me how can i render ,LOV2 when LOV1 as 'SCM' by using 'rendered' property without having valueChangeListner??
    pls suggest me the right approach as per my use case..
    waiting for reply,,
    Thanks
    Santosh

  • How do you invoke an Action prior to an initial page?

    Is there a mechanism in JSF that allows action code to run prior to the first page?
    Basically I want to do some processing in the context of JSF before displaying the initial application page.
    In Struts I was able to do this by defining an action-mappings action that referenced an action class, and from that action I could forward to another action-mappings action that was a JSP.

    This seems rather complicated and is not straight-forward. I need something similar: Before the first Render Response phase of a view I'd like my application to process any parameters that were passed via a non-faces GET request and set up my application and the JSF components appropriately. In other words, instead of the initial Restore View -> Render Response I'd like to have the full sequence of Restore View -> Apply Values -> Process Validations -> Update Model Values -> Invoke Application -> Render Response.
    For example, depending on the request parameters I'd like to forward the request to one or the other JSF view. And I cannot do that in the Render Response phase because doing it The Faces Way is only possible in the Invoke Application phase - which is not invoked upon a view's initial use.

  • Backing Bean method not invoked - h:selectOneRadio

    Hi,
    I am trying to invoke a method in the backing bean when a radio button is selected, but for some reasons the method is not getting invoked, any idea why is it so? copying the code for reference.
    I have a command button in this jsp which when clicked is fetching the records(from the backing bean) perfectly and a radio button for each of the record so user can select any one of the records listed.
    example.jsp
    <%@ page language="java" pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
         <base href="<%=basePath%>">
         <title>My Page</title>
         <meta http-equiv="pragma" content="no-cache">
         <meta http-equiv="cache-control" content="no-cache">
         <meta http-equiv="expires" content="0">   
         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
         <meta http-equiv="description" content="sample List">
         <!--
         <link rel="stylesheet" type="text/css" href="style.css">
         <link rel="stylesheet" href="styleNN.css" type="text/css">
         -->
         </head>
    <body>
         <f:view>
              <h:form id="contacts">
              <table width="200" border="0" title="sample List" style="border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-style: solid" bgcolor="#F0F0F0" cellpadding="2" cellspacing="2">
                   <h:outputLabel value="Product List:" style="font-family: Verdana, Arial, Sans-Serif; font-size: 14px; color: Black; font-weight: bold; font-style: normal; width: 198px" styleClass="bigfieldcell"></h:outputLabel>
                          </table>
              <br>
         <div style="height: 400px; overflow: auto">
                   <h:dataTable border="1" value="#{contactsBean.contactsList}" var="contact" bgcolor="#EEEEEE" frame="box" styleClass="orderlabelcell" cellpadding="3">
                   <h:column>
                             <f:facet name="header">
                                  <h:outputText value="Select to Edit"/>
                             </f:facet>
                                  *<h:selectOneRadio valueChangeListener="#{contactsBean.test}">*
                    *               <f:selectItem itemValue="#{contact}" />*
                *               </h:selectOneRadio>*               </h:column>
                        <h:column>
                             <f:facet name="header">
                                  <h:outputText value="Category"/>
                             </f:facet>
                             <h:inputText value="#{contact.category}" style="border-right-style: none; border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-color: #FFFFFF; border-top-color: #FFFFFF"></h:inputText>
                        </h:column>
                        <h:column>
                             <f:facet name="header">
                                  <h:outputText value="Location"/>
                             </f:facet>
                             <h:outputText value="#{contact.location}"></h:outputText>
                        </h:column>
                        <h:column>
                             <f:facet name="header">
                                  <h:outputText value="Problem Type"/>
                             </f:facet>
                             <h:outputText value="#{contact.problemType}"></h:outputText>
                        </h:column>
                        <h:column>
                             <f:facet name="header">
                                  <h:outputText value="Problem Details"/>
                             </f:facet>
                             <h:outputText value="#{contact.problemDetails}"></h:outputText>
                        </h:column>
                        <h:column>
                             <f:facet name="header">
                                  <h:outputText value="Contact"/>
                             </f:facet>
                             <h:outputText value="#{contact.contact}"></h:outputText>
                        </h:column>
                   </h:dataTable>
                   </div>
                   </h:form>
              </f:view>
    </body>
    </html>
    faces-config.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                                  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
    <managed-bean>
      <managed-bean-name>contactsBean</managed-bean-name>
      <managed-bean-class>services.ContactsBean</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <managed-bean>
      <managed-bean-name>contactsDatabaseHandler</managed-bean-name>
      <managed-bean-class>dao.ContactsDatabaseHandler</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    </faces-config>
    ContactsBean.java
    package services;
    import java.util.ArrayList;
    import java.util.Hashtable;
    import java.util.List;
    import javax.faces.context.FacesContext;
    import javax.faces.event.AbortProcessingException;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.model.SelectItem;
    import sun.security.action.GetLongAction;
    import dao.ContactsDatabaseHandler;
    import model.Contact;
    public class ContactsBean {
         private String selectedLocation;
         private List locationList;
         private String selectedProblemType;
         private List problemTypeList;
         private List contactsList;
         private ContactsDatabaseHandler dbHandler;
         private String address;
         private Hashtable region;
         private Contact selectedContact;
         public void test(ValueChangeEvent event)throws AbortProcessingException {
              System.out.println("In Backing Bean : test method.... ");
    }Thanks in Advance

    The valueChangeListener runs at the server side. You need to submit the form to the server side to invoke the valueChangeListener. There is no client side magic like Javascript.
    To submit the parent form on change of the dropdown, just add the following attribute with a piece of Javascript to the h:selectOneMenu:onchange="this.form.submit()"

  • About backing bean method's invokation

    Hi,
    I have a backing bean method binded to a component:
    <af:selectOneChoice value="#{bindings.managerId.inputValue}"
    label="Manager" valign="middle"
    binding="#{backing_searchDocuments.managersList}"
    valuePassThru="true" immediate="false"
    rendered="#{bindings.ListManagersIterator.estimatedRowCount > 1}">
    <f:selectItems value="#{bindings.managerId.items}"/>
    When page refreshes component executes his binding method. But in some cases, actually when I press the commandMenuItem leading to the same page where I am it seems that it doesn't get invoked.. how can I manage the invocation of backing bean's methods? I need it invoked every time any request is made.. How to do that?

    Mario,
    this method is executed when the component re-draws. So anything other than a PPR request makes this binding method being called.
    If PPR is used with your commandMenuItem, them make sure the PPR trigger is set to refresh the component.
    I don't know what code it is that you need to execute each time, but maybe putting this on a action listener is a better idea
    Frank

  • How to realize timeout while invoking a method in remote sesssion bean using my session bean running on wls5.1

    I am using WL5.1 SP11 on a project. I have a stateless session bean inside which
    I will invoke a method defined in another stateless session bean in a remote weblogic
    server 5.1. The performance of the remote server is very low and sometimes when
    I invoke the method through RMI, I got to wait for a long time. So I want to set
    a timeout for my session bean while doing RMI call. The only parameter I could
    find in weblogic-ejb-jar.xml is the "transaction-timeout", but even if I set transaction
    attribute for my session bean, it always block there to wait for the response
    from the remote session bean. The configuation did not work.
    Is there any other solutions to my problem? Please give me some advice if anyone
    has experience on it, Thank you very much.

    I am using WL5.1 SP11 on a project. I have a stateless session bean inside which
    I will invoke a method defined in another stateless session bean in a remote weblogic
    server 5.1. The performance of the remote server is very low and sometimes when
    I invoke the method through RMI, I got to wait for a long time. So I want to set
    a timeout for my session bean while doing RMI call. The only parameter I could
    find in weblogic-ejb-jar.xml is the "transaction-timeout", but even if I set transaction
    attribute for my session bean, it always block there to wait for the response
    from the remote session bean. The configuation did not work.
    Is there any other solutions to my problem? Please give me some advice if anyone
    has experience on it, Thank you very much.

  • JSF Problem invoking backing bean method

    I want a backing bean method to be invoked when the submit button is clicked but for some strange reason the method is not getting invoked any Help in this regards would be great.
    I am able to properly get the values from database and display on the page , after the user types in some more additional information like password , hint question the form has to be submitted when clicked on the submit button..
    Register.jsp
    <body>
         <f:view>
         <h:graphicImage url="/header.jpg"></h:graphicImage>
               <br><h:form id="user">
                        <table>
                        <tr>
                             <td>
                                  <h:outputLabel for="" value="uUser Name:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                                  <h:inputText onblur="JavaScript:doSubmit();" value="#{registerFormBean.userName}" id="userName"></h:inputText>
                             </td>
                        </tr>
                        <tr>     
                             <td>
                             <h:outputLabel for="" value="First Name:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                             <h:inputText value="#{registerFormBean.firstName}" id="firstName"></h:inputText></td>
                        </tr>
                        <tr>     
                             <td><h:outputLabel for="" value="Middle Name:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                             <h:inputText id="middleName" value="#{registerFormBean.middleName}"></h:inputText></td>
                        </tr>
                        <tr>     
                             <td><h:outputLabel for="" value="Last Name:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                             <h:inputText id="lastName" value="#{registerFormBean.lastName}"></h:inputText></td>
                        </tr>
                        <tr>
                             <td>
                                  <h:outputLabel for="" value="Password:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                                  <h:inputText id="password" value="#{registerFormBean.password}"></h:inputText>
                             </td>
                        </tr>
                        <tr>     
                             <td><h:outputLabel for="" value="Re-type Password:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                             <h:inputText></h:inputText></td>
                        </tr>
                        <tr>     
                             <td><h:outputLabel for="" value="Password Hint Question:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                             <h:inputTextarea id="hintQuestion" value="#{registerFormBean.hintQuestion}"></h:inputTextarea></td>
                        </tr>
                        <tr>     
                             <td><h:outputLabel for="" value="Password Hint Answer:" styleClass="orderlabelcell"></h:outputLabel></td><td>
                             <h:inputTextarea id="hintAnswer" value="#{registerFormBean.hintAnswer}"></h:inputTextarea></td>
                        </tr>
                        <tr>     
                             <td>
                                  <h:commandButton id="submit" value="Submit" type="submit" action="#{registerFormBean.saveUser}"/>
                                  <h:commandButton id="Reset" value="Reset" type="reset"/>
                                  </td>
                        </tr>
                        </table>
                   </h:form>
         </f:view>
    </body> 
    RegisterFormBean.java
      package services;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import dao.DatabaseHandler;
    import model.User;
    public class RegisterFormBean {
    User selectedUser;
    String userName;
    String firstName;
    String middleName;
    String lastName;
    String password;
    String hintQuestion;
    String hintAnswer;
    String errMsg;
    private DatabaseHandler dbHandle;
    public RegisterFormBean() {
         javax.faces.context.FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();
         javax.faces.application.Application app = context.getApplication();
         dbHandle = (DatabaseHandler)app.createValueBinding("#{databaseHandler}").getValue(context);
    public void setUserDetails() {
         try{
              System.out.println("gettting Details for user: "+userName);
              selectedUser = (User)dbHandle.getUser(userName);
         catch (SQLException e) {
              errMsg = "Problem gettting records";
    public String getUserName() {
         if(null!=userName){
              setUserDetails();
         if(null!=selectedUser)
              return selectedUser.getLoginName();
         else
         return "";
    public void setUserName(String userName){
         this.userName = userName;
    public String getFirstName() {
         if(null!=selectedUser)
              return selectedUser.getFirstName();
         else
         return "";
    public void setFirstName(String firstName) {
         System.out.println("in setFirst name");
         this.firstName = firstName;
    public String getMiddleName() {
         if(null!=selectedUser)
              return selectedUser.getMiddleName();
         else
         return "";
    public void setMiddleName(String middleName) {
         System.out.println("in set middle name...");
         this.middleName = middleName;
    public String getLastName() {
         if(null!=selectedUser)
              return selectedUser.getLastName();
         else
         return "";
    public void setLastName(String lastName) {
         System.out.println("in set last name....");
         this.lastName = lastName;
    public String getPassword() {
         return password;
    public void setPassword(String password) {
         if(null!=password){
              System.out.println("$$$$$$$$$$$$ setting password.."+password);
              selectedUser.setPassword(password);
    public String getHintQuestion() {
         return hintQuestion;
    public void setHintQuestion(String hintQuestion) {
         if(null!=hintQuestion){
              System.out.println("#########  Hint Question "+hintQuestion);
              selectedUser.setHintQuestion(hintQuestion);
    public String getHintAnswer() {
         return hintAnswer;
    public void setHintAnswer(String hintAnswer) {
         if(null!=hintAnswer){
              System.out.println("@@@@@@@  Hint Answer"+hintAnswer);
              selectedUser.setHintQuestion(hintAnswer);
    public String saveUser(){
         String flag = "";
         System.out.println("IN registerUser Method....");
         try{
              if(null!=selectedUser){
                   flag = dbHandle.registerUser(setUserDefaults(selectedUser));
         catch(SQLException se){
         flag="fail";
         System.out.println("FAILED DUE TO THE EXCEPTION :- "+se.getMessage());
         errMsg = "Unable to Register the User...";
         return flag;
    public User setUserDefaults(User user){
         System.out.println("SETTING USER DEFAULTS.....");
         user.setActive(true);
         user.setLoginType("False");
         user.setCreatedUserName("SOMEUSERNAME");
         user.setSecIdFunctionGroup(17);
         user.setChallangeWord("CHANGE IT");
         user.setTrusted(false);
         user.setUserTypeIdTypeOf(1);
         user.setChangePwdNextLogin("False");
         user.setLoginIsDisabled(false);
         user.setPasswordNeverExpires(false);
         user.setThinWorkOrder(false);
         user.setCurrencyTypeId(2);
         return user;
    I am able to fetch the details from Database and display on the page so DAO is working properly hence not copying here
    faces-config.xml
      <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                                  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
    <managed-bean>
      <managed-bean-name>databaseHandler</managed-bean-name>
      <managed-bean-class>dao.DatabaseHandler</managed-bean-class>
      <managed-bean-scope>application</managed-bean-scope>
    </managed-bean>
    <managed-bean>
      <managed-bean-name>registerFormBean</managed-bean-name>
      <managed-bean-class>services.RegisterFormBean</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
      <from-view-id>/Register.jsp</from-view-id>
      <navigation-case>
       <from-outcome>success</from-outcome>
       <to-view-id>/Success.jsp</to-view-id>
      </navigation-case>
    </navigation-rule>
    </faces-config>

    A conversion or validation error may have been occurred. Add <h:messages/> to the page to note them all. If you're using at least Sun Mojarra 1.2, then you should be able to note them all in the application server logs.

  • ValueChangeListener not invoking backing bean method

    Hi Everybody
    I am using a valueChangeListener attribute with <h:selectOneListbox>. As i am using onChange, the form is getting submitted but the associated backing bean method is not getting invoked.
    My JSP code:
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <html>
       <head>
          <title>Song Detail</title>
       </head>
       <body>
          <f:view>   
               <h:form id="songForm">
                       <H4>Select a song to view detail.</H4>
                </Br>
                       <h:selectOneListbox id="songList" value="#{songBean.selectedSong}"
    valueChangeListener="#{songBean.songInformation}" immediate="true" onchange="submit();">
                              <f:selectItems value="#{songBean.songList}"/>
                     </h:selectOneListbox>
                <p>
                 <h:outputText id="result" value="#{songBean.songDetail}"/>
             </p>   
         </h:form>                  
       </f:view>
      </body>
    </html> My Backing bean method:
    public void songInformation(ValueChangeEvent vce) throws AbortProcessingException
              System.out.println("Method invoked");
           } This songInformation() method is not getting invoked.
    Please help.

    I never say to put every bean in session scope.
    I recommend that the following beans are in session scope:
    (1) the value property of h:dataTable
    (2) the value property of f:selectItems
    (3) the rendered property
    They are evaluated before Update Model Values phase.

Maybe you are looking for