簡體   English   中英

jsf commandButton導航javax.el.MethodNotFoundException

[英]jsf commandButton navigation javax.el.MethodNotFoundException

嗨,我正在嘗試測試jsf的導航規則。

我的人豆:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class Person {
    private int id;
    private String name;
    private int age;

    public Person(){
        id = 1;
        name = "No name!";
        age = 0;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String validate(){
        if(this.name.equals("Evgeny")){
            return "success";
        }else{
            return "failure";
        }
    }
}

我的faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">

    <navigation-rule>
        <from-view-id>/view.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/destination.xhtml</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>failure</from-outcome>
            <to-view-id>/view.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

</faces-config>

那就是我的形式:

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

<h:body>
    <h:form>
        <h:outputText>Some Text!</h:outputText>
        Name:   <h:inputText value="#{person.name}" id="inName"></h:inputText>
            <br></br>
        Age:    <h:inputText value="#{person.age}" id="inAge"></h:inputText> 
            <br></br>
        <h:commandButton value="OK" action="#{person.validate}"></h:commandButton>
    </h:form>
</h:body>
</html>

當我嘗試調用person.validate時,出現javax.el.MethodNotFoundException為什么會發生? 我正在使用MyFaces2.0.4和Tomcat 7

保存所有文件,重建項目,重新部署Webapp並重新啟動服務器。

換句話說,一切看起來都很好。 您只是沒有運行您認為正在運行的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM