【问题标题】:primefaces command button/link not working [duplicate]primefaces命令按钮/链接不起作用[重复]
【发布时间】:2013-11-05 10:36:08
【问题描述】:

谁能告诉我为什么命令按钮/链接没有被触发。这个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>

有什么帮助吗??

【问题讨论】:

  • #{loginBean.value} 出现在登录页面上,因此托管 bean 为此工作,但对于welcomePage 它没有被解雇。为什么??
  • passwordname 在你的 bean 恕我直言中不应该是 static。尝试ViewScoped 而不是RequestScoped。查看“bean 命名约定”。
  • 如果你想处理导航,你应该使用action而不是actionListener
  • 好的,去检查一下。但这很奇怪,因为我正在关注 primefaces_userguide _4.0,并且他们使用了动作侦听器。从第 102 页复制示例

标签: jsf primefaces actionlistener commandlink commandbutton


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 2013-10-11
    • 2018-01-24
    • 2018-03-19
    • 2019-07-14
    相关资源
    最近更新 更多