[英]Xhtml page mapping from ManagedBean
Here Is Managed Bean Class 这是托管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";
}
}
Here Is web.xml file 这是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>
Here id home.xhtml page 这是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>
Here is the code for mapping xhtml page from ManagedBean. 这是从ManagedBean映射xhtml页面的代码。 I just want when the button is clicked then the login page will show....But when the button is clicked there is only home.xhtml page reloading...Login page is not loading....
我只想单击按钮时会显示登录页面....但是单击按钮时只有home.xhtml页面正在重新加载...登录页面未加载....
The selection of the next view depends on the value of the action attribute of the UICommand components. 下一个视图的选择取决于UICommand组件的action属性的值。 If the navigation handler finds a navigation rule for this page with this outcome, the next view will be the element content.
如果导航处理程序为此结果找到了该页面的导航规则,则下一个视图将是元素内容。 If there is no any rule like this it looks for a page with the value (or it appended with ".xhtml" file extension).
如果没有这样的规则,它将查找具有该值的页面(或附加“ .xhtml”文件扩展名的页面)。
The variations: 的变化:
1., Direct view definition: 1.,直接视图定义:
<h:commandButton action="next_page_name"/>
It must be a full qualified name (page names + file name), but the xhtml could be omitted. 它必须是标准名称(页面名称+文件名),但是xhtml可以省略。
2., Indirect view definition: In this case the action value is contains a bean method invocation: 2.间接视图定义:在这种情况下,动作值包含一个bean方法调用:
<h:commandButton action="#{myBean.methodName}"/>
This method should be a function without any parameter and passes back a String value. 此方法应该是不带任何参数的函数,并传回String值。 This result will be the income for the navigation handler.
该结果将成为导航处理程序的收入。 It could return a page name or a navigation rule.
它可以返回页面名称或导航规则。
Now let us see your problem. 现在,让我们看看您的问题。 If the name of your current view is id_home.xhml and you want to navigate to the login.xhtml page (both are in the x package):
如果当前视图的名称是id_home.xhml,并且您要导航到login.xhtml页面(均在x包中):
1., Direct view definition. 1.,直接视图定义。 Return value "x/login" or "x/login.xhtml" from the show() method:
从show()方法返回值“ x / login”或“ x / login.xhtml”:
public String show()
{
//...
return "x/login";
}
2., Indirect view definition. 2.,间接视图定义。 Define a page navigation rule in the faces-config.xml like this:
在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>
In this case myBean.methodName passes back the content of the form-outcome element: 在这种情况下,myBean.methodName传递回form-outcome元素的内容:
public String show()
{
//...
return "go_to_login";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.