0

I've a problem with JSF 1.1 (dinosaur, I know)

So there are two pages - index.jsp and test.jsp I want to be redirected from index.jsp to test.jsp after clicking "Create" button

But nothing happens:/

p.s. and, in general, how do I log the things there, right know there is even no log of the clicking event! it's horrible

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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
tania
  • 1,086
  • 2
  • 12
  • 31

2 Answers2

1

The JSF <h:commandButton> generates a HTML <input type="submit"> element which works only when nested in a HTML <form> element whose JSF equivalent is <h:form>.

However, you don't have a <h:form> anywhere in your view. Add it accordingly:

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

By the way, if all your create method does is returning a fixed outcome, then you can also just specify the outcome directly in the action attribute:

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

By the way #2, using POST for page-to-page navigation is a bad practice, you should prefer output links for this.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
-1

The create method should return a string. This string is the path to the page where you want to redirect. Replace:

return "success";

For:

return "yourpage"