JSF2中的隐式导航

时间:2014-02-10 05:49:43

标签: jsf jsf-2 webpage

关于JSF 2隐式导航的问题。他只在根目录中寻找页面?因为我在WebContent上的文件夹中分隔我的页面,除了我在WebContent中放入的index.php页面。我的应用程序服务通常会打开包含登录页面按钮的索引页面,登录页面位于WebContent目录中名为“public”的目录中。当我点击索引页面上的按钮显示他找不到登录页面时。

  • 我试图更改ManagedBean方法的结果,该方法将您引导到登录页面,看起来像这样:“public / login.xhtml”,但都没有用。

我感谢任何能帮助我的人。

修改

ManagedBean

package financeiro.web;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import financeiro.usuario.Usuario;
import financeiro.usuario.UsuarioRN;

@ManagedBean(name = "usuarioBean")
@RequestScoped
public class UsuarioBean {

private Usuario usuario;
private String confirmarSenha;

public UsuarioBean() {
}

public String novo() {
    this.usuario = new Usuario();
    this.usuario.setAtivo(true);

    /*
     * Solution according to the Xtreme Biker. Works now. Thanks. 
     * Before: public/usuario 
     * After:  /public/usuario
     */
    return "/publico/usuario";
}

public String salvar() {
    FacesContext context = FacesContext.getCurrentInstance();

    String senha = this.usuario.getSenha();

    if (!senha.equals(this.confirmarSenha)) {
        FacesMessage facesMessage = new FacesMessage(
                "A senha não foi confirmada corretamente.");
        context.addMessage(null, facesMessage);
        return null;
    }

    UsuarioRN usuarioRN = new UsuarioRN();
    usuarioRN.salvar(usuario);

    return "usuarioSucesso";
}

public Usuario getUsuario() {
    return usuario;
}

public void setUsuario(Usuario usuario) {
    this.usuario = usuario;
}

public String getConfirmarSenha() {
    return confirmarSenha;
}

public void setConfirmarSenha(String confirmarSenha) {
    this.confirmarSenha = confirmarSenha;
}
}

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>FinanceiroWeb</display-name>

<servlet>
    <display-name>Faces Servlet</display-name>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

<filter>
    <filter-name>conexaoFilter</filter-name>
    <filter-class>financeiro.web.filter.ConexaoHibernateFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>conexaoFilter</filter-name>
    <url-pattern>*.xhtml</url-pattern>
</filter-mapping>

的index.html

<meta http-equiv="Refresh" content="0;URL=publico/login.xhtml" />

login.xhtml

<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Login</title>
</h:head>
<h:body>
<h1>Login</h1>
<hr />
<h:form>
    <h:commandButton action="#{usuarioBean.novo}" value="Registre-se" />
</h:form>
<hr />
</h:body>
</html>

项目的目录结构

OBS:我使用Maven Project

链接图片:http://postimg.org/image/bm7iwbmxf/

0 个答案:

没有答案