Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 来自ManagedBean的Xhtml页面映射_Spring_Jsf_Managed Bean - Fatal编程技术网

Spring 来自ManagedBean的Xhtml页面映射

Spring 来自ManagedBean的Xhtml页面映射,spring,jsf,managed-bean,Spring,Jsf,Managed Bean,下面是托管Bean类 package Controller; import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import Model.Employee; @ManagedBean(name="employeeController")

下面是托管Bean类

        package Controller;

        import java.io.Serializable;

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

         @ManagedBean(name="employeeController")
        @SessionScoped
        public class Employeecontroller implements Serializable{

        public String show(){
          System.out.println("hello");

             return "Login";

            }

           }
下面是web.xml文件

                    <?xml version="1.0" encoding="UTF-8"?>
                    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
                      <display-name>Secondproject</display-name>
                      <welcome-file-list>
                        <welcome-file>index.html</welcome-file>
                        <welcome-file>index.htm</welcome-file>
                        <welcome-file>index.jsp</welcome-file>
                        <welcome-file>default.html</welcome-file>
                        <welcome-file>default.htm</welcome-file>
                        <welcome-file>default.jsp</welcome-file>
                      </welcome-file-list>
                      <servlet>
                        <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>/faces/*</url-pattern> 
                        <url-pattern>*.xhtml</url-pattern>
                      </servlet-mapping>
                      <context-param>
                        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
                        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                        <param-value>client</param-value>
                      </context-param>
                      <context-param>
                        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
                        <param-value>resources.application</param-value>
                      </context-param>
                      <listener>
                        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
                      </listener>
                       <welcome-file-list>  
                       <welcome-file>homepage.xhtml</welcome-file>  
                      </welcome-file-list>  
                    </web-app>

第二个项目
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
/面/*
*.xhtml
状态保存方法:“客户端”或“服务器”(=默认值)。参见JSF规范2.5.2
javax.faces.STATE_保存方法
客户
javax.servlet.jsp.jstl.fmt.localizationContext
资源.应用
com.sun.faces.config.ConfigureListener
homepage.xhtml
这里是id home.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:rich="http://richfaces.org/rich"
                        xmlns:ui="http://java.sun.com/jsf/facelets"
                        xmlns:f="http://java.sun.com/jsf/core"
                        xmlns:a4j="http://richfaces.org/a4j"
                        xmlns:h="http://java.sun.com/jsf/html">

                    <h:head></h:head>
                    <body>
                        <rich:panel>
                            <f:facet name="header">
                            Write your own custom rich components with built-in AJAX support
                            </f:facet>
                            <h:outputText value="Panel Body" />
                            <h:form>
                                <h:commandButton action="#{employeeController.show()}" value="Login" />
                            </h:form>

                        </rich:panel>
                    </body>
                    </html>

使用内置的AJAX支持编写自己的自定义富组件
下面是从ManagedBean映射xhtml页面的代码。
我只想当点击按钮时,登录页面将显示…但当点击按钮时,只有home.xhtml页面正在重新加载…登录页面未加载

下一个视图的选择取决于UICommand组件的action属性的值。如果导航处理程序找到具有此结果的此页面的导航规则,则下一个视图将是元素内容。若并没有类似的规则,它将查找具有值(或附加“.xhtml”文件扩展名)的页面

变化:

1.直接视图定义:

<h:commandButton action="next_page_name"/>
2.间接视图定义。在faces-config.xml中定义页面导航规则,如下所示:

<navigation-rule>
  <from-view-id>/x/id_home.xhtml</from-view-id>
    <navigation-case>
      <from-outcome>go_to_login</from-outcome>
      <to-view-id>x/login.xhtml</to-view-id>
  </navigation-case>
</navigation-rule>

如果
NavigationHandler
找不到从操作方法返回的名称为的视图,则重新加载同一页面
show()
正在返回“Login”,因此您应该拥有
Login.xhtml
而不是
Login.xhtml
。如果它对您有效,请接受投票
public String show()
{
  //...
  return "x/login";
}
<navigation-rule>
  <from-view-id>/x/id_home.xhtml</from-view-id>
    <navigation-case>
      <from-outcome>go_to_login</from-outcome>
      <to-view-id>x/login.xhtml</to-view-id>
  </navigation-case>
</navigation-rule>
public String show()
{
  //...
  return "go_to_login";
}