0

Can anyone tel me why command button/link is not getting fired. This welcomePage() should be invoked on button press. I checked the managed property "value" is displaying on the execution, but button or link is not getting invoked.

My loginBean:

import java.io.IOException;
import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;


import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

@ManagedBean(name = "loginBean", eager = true)
@RequestScoped

public class loginBean implements Serializable {

    private String value = "This text shows, bean is working ";

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @ManagedProperty(value="#{name}")
    public static String name;
    public String getName() {  
        return name;  
    }  

    public void setName(String name) {  
        this.name = name;  
    }

    @ManagedProperty(value="#{password}")
    public static String password;

     public String getPassword() {  
            return password;  
        }  

        public void setPassword(String password) {  
            this.password = password;  
        }


     public String welcomePage()
        {
            System.out.println("welcome user according to user name");

                 return "customerGreeting.xhtml";
        }



}

My index.xhtml:

<?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:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">


    <f:view contentType="text/html">
        <h:head>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <title>Facelet Title</title>
        </h:head>
        <h:body>
        <ui:composition>

       <div align ="center">  


       <h:form id="form" align="center"> 
        <h:panelGrid id="panel" columns="2" >

      <f:facet name="header">
         <h:outputText value="Login here:"/>
      </f:facet>

      <h:outputLabel value="Username" />
      <p:inputText id="name" value="#{loginBean.name}" />

      <h:outputLabel value="Password" />
      <p:password id="password" value="#{loginBean.password}" />

      <f:facet name="footer">
         <h:panelGroup style="display:block; text-align:center">


           <p:commandButton id="submit1" value="Submit1" actionListener="#{loginBean.welcomePage}" />

           <p:commandLink actionListener="#{loginBean.welcomePage}">
                <h:outputText id= "submit2" value="Submit2" />
            </p:commandLink>


         </h:panelGroup>
      </f:facet>
</h:panelGrid>

       #{loginBean.value}
  </h:form>

  </div>
  </ui:composition>
        </h:body>
    </f:view>
</html>

Any help ??

Manuel
  • 3,828
  • 6
  • 33
  • 48
user2746713
  • 3
  • 1
  • 6
  • #{loginBean.value} is appearing on the login page, so managed bean working for that, but for welcomePage it is not getting fired. Why?? – user2746713 Nov 05 '13 at 10:39
  • `password` and `name` should not be `static` in your bean imho. Try `ViewScoped` instead of `RequestScoped`. Check out 'bean naming conventions'. – Manuel Nov 05 '13 at 11:01
  • 2
    You should use action instead of actionListener if you want to handle navigaton – Emil Kaminski Nov 05 '13 at 11:18
  • Ok going to check this. But its strange as I am following primefaces_userguide _4.0, and they have used action listener. copying example from page 102 – user2746713 Nov 05 '13 at 13:31
  • By your last comment, I would recommend stop using PrimeFaces and take some time to learn JSF first. Then, move on to use third party libraries like PrimeFaces and/or OmniFaces. – Luiggi Mendoza Nov 05 '13 at 15:02
  • 1
    Also, refer to http://stackoverflow.com/q/2118656/1065197 and http://stackoverflow.com/q/3909267/1065197 – Luiggi Mendoza Nov 05 '13 at 15:04

1 Answers1

0

you should use action instead of actionListener, because action needs to return a string for navigation rules

MitoCode
  • 319
  • 2
  • 10
  • 25