0

谁能告诉我为什么命令按钮/链接没有被触发。这个welcomePage() 应该在按钮按下时被调用。我检查了托管属性“值”是否显示在执行中,但没有调用按钮或链接。

我的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";
        }



}

我的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>

有什么帮助吗??

4

1 回答 1

0

你应该使用action而不是actionListener,因为action需要返回一个用于导航规则的字符串

于 2013-11-05T15:27:11.530 回答