没有匹配的导航案例

时间:2015-11-23 04:36:06

标签: jsf action commandbutton

我在尝试运行下面的代码时不断收到此消息。它应该从要上载的文档中显示测试。这是一个Java Server Faces程序。为什么我收到此消息:无法找到与from-view-id' /upload.xhtml'匹配的导航案例;行动' vidClass2.upload'结果' vidClass2.upload'

<?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:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body >
        <h:form id="form" enctype="multipart/form-data" prependId="false">
            <p><h:inputFile id="file" value="#{vidClass2.vidData}"> 
                </h:inputFile>
            </p>
            <br/>
            <h:commandButton id="button" value ="upload" action ="vidClass2.upload">

            </h:commandButton>
            <p id="textOutput">Text: #{vidClass2.vidName}</p>
        </h:form>

    </h:body>
</html>


import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import javax.servlet.http.Part;

/**
 *
 * @author David Jennings
 */
@ManagedBean(name = "vidClass2")
@RequestScoped
public class VidClass {

    private String userName;
    private String vidName;
    private Part vidData;

    /**
     * Creates a new instance of VidClass
     */
    public VidClass() {
    }

    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @param userName the userName to set
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * @return the vidName
     */
    public String getVidName() {
        return vidName;
    }

    /**
     * @param vidName the vidName to set
     */
    public void setVidName(String vidName) {
        this.vidName = vidName;
    }

    /**
     * @return the vidData
     */
    public Part getVidData() {
        return vidData;
    }

    /**
     * @param vidData the vidData to set
     */
    public void setVidData(Part vidData) {
        this.vidData = vidData;
    }

    public void upload() {

        if (null != vidData) {
            try {
                InputStream is = vidData.getInputStream();
                vidName = new Scanner(is).useDelimiter("\\A").next();
            } catch (IOException ex) {
            }
        }
    }

}

How to Write an Action Listeners

1 个答案:

答案 0 :(得分:1)

如果您在自己的页面上使用JavaBeans组件,则应该使用表达式#{bean.method}。

<h:commandButton id="button" value ="upload" action ="#{vidClass2.upload}"/>