JSF从页面重定向到页面

时间:2012-08-29 07:20:58

标签: jsf navigation

我遇到了JSF 1.1的问题(恐龙,我知道)

所以有两个页面 - index.jsp和test.jsp 我想在点击"创建"之后从index.jsp重定向到test.jsp。按钮

但没有任何反应:/

P.S。而且,一般来说,我如何记录那里的东西,知道甚至没有点击事件的日志!它太可怕了

的index.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%-- jsf:pagecode language="java" location="/src/pagecode/Index.java" --%><%-- /jsf:pagecode --%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="GENERATOR" content="IBM WebSphere Integration Developer 6.2">
<link rel="stylesheet" type="text/css" title="Style"
    href="theme/stylesheet.css">
</head>
<f:view>
    <body>
    <h:panelGrid columns="1" width="12%" cellpadding="10" rendered="true">

        <h:commandButton value="Create" action="#{Controller.create}" />
    </h:panelGrid>

    </body>
</f:view>
</html>

Controller.java

public class Controller extends PageCodeBase {


    public String create() {
        return "success";
                 }

}

faces-config.xml

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

<!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
    <managed-bean>
        <managed-bean-name>Controller</managed-bean-name>
        <managed-bean-class>pagecode.Controller</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>


    <navigation-rule>
        <display-name>index</display-name>
        <from-view-id>/index.jsp</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/test.jsp</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>
</faces-config>

的web.xml

<welcome-file-list>

        <welcome-file>index.jsp</welcome-file>
        <welcome-file>test.jsp</welcome-file>
</welcome-file-list>

2 个答案:

答案 0 :(得分:1)

JSF <h:commandButton>生成一个HTML <input type="submit">元素,该元素仅在嵌套在JSF等效为<form>的HTML <h:form>元素中时才有效。

但是,您的视图中没有<h:form>。相应地添加它:

<h:form>
    <h:commandButton value="Create" action="#{Controller.create}" />
</h:form>

顺便说一句,如果您的所有create方法都返回固定结果,那么您也可以直接在action属性中指定结果:

<h:form>
    <h:commandButton value="Create" action="success" />
</h:form>

顺便说一句,使用POST进行页面到页面导航是一种不好的做法,你应该更喜欢输出链接。

另见:

答案 1 :(得分:-1)

create方法应该返回一个字符串。此字符串是您要重定向的页面的路径。 替换:

return "success";

有关:

return "yourpage"
相关问题