在JSF导航中URL应该更改
我使用ApacheMyFaces2.1(使用JSF1.x)创建了Login.xhtml 当我在login.xhtml上给出了用户名和密码,并且有一个提交按钮时 当我单击“再见”按钮时,该控件转到wsListing.xhtml,但浏览器中的URL保持不变在JSF导航中URL应该更改,jsf,myfaces,Jsf,Myfaces,我使用ApacheMyFaces2.1(使用JSF1.x)创建了Login.xhtml 当我在login.xhtml上给出了用户名和密码,并且有一个提交按钮时 当我单击“再见”按钮时,该控件转到wsListing.xhtml,但浏览器中的URL保持不变 http://hostid:8080/TestClient/faces/login.xhtml 我想把它改成 http://hostid:8080/TestClient/faces/wsListing.xhtml 我已经附上了相同的代码,请向
http://hostid:8080/TestClient/faces/login.xhtml
我想把它改成
http://hostid:8080/TestClient/faces/wsListing.xhtml
我已经附上了相同的代码,请向我推荐一些解决方案,我是JSF新手。
Login.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" xmlns:lang="en">
<f:view>
<head>
<title>Test Client Login</title>
</head>
<h:form id="loginForm">
<table>
<tr>
<h:outputLabel for="username">
<h:outputText id="usernameLabel" value="Enter Username:" />
</h:outputLabel>
<h:inputText id="username" value="#{loginBean.username}"
required="true">
<f:validateLongRange minimum="1" maximum="500" />
</h:inputText>
</tr>
<tr>
<h:outputLabel for="password">
<h:outputText id="passwordLabel" value="Enter Password:" />
</h:outputLabel>
<h:inputText id="password" value="#{loginBean.password}"
required="true">
<f:validateLongRange minimum="1" maximum="500" />
</h:inputText>
</tr>
<tr>
<h:commandButton id="goodbyeCommand" type="submit" value="Goodbye"
action="#{loginBean.goodbye}" immediate="true" />
</tr>
</table>
</h:form>
</f:view>
</html>
<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<description>Login Bean</description>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>com.example.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<description>Navigation from the hello page.</description>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/wsListing.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
faces config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" xmlns:lang="en">
<f:view>
<head>
<title>Test Client Login</title>
</head>
<h:form id="loginForm">
<table>
<tr>
<h:outputLabel for="username">
<h:outputText id="usernameLabel" value="Enter Username:" />
</h:outputLabel>
<h:inputText id="username" value="#{loginBean.username}"
required="true">
<f:validateLongRange minimum="1" maximum="500" />
</h:inputText>
</tr>
<tr>
<h:outputLabel for="password">
<h:outputText id="passwordLabel" value="Enter Password:" />
</h:outputLabel>
<h:inputText id="password" value="#{loginBean.password}"
required="true">
<f:validateLongRange minimum="1" maximum="500" />
</h:inputText>
</tr>
<tr>
<h:commandButton id="goodbyeCommand" type="submit" value="Goodbye"
action="#{loginBean.goodbye}" immediate="true" />
</tr>
</table>
</h:form>
</f:view>
</html>
<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<description>Login Bean</description>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>com.example.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<description>Navigation from the hello page.</description>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/wsListing.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
登录Bean
罗根宾
com.example.LoginBean
一场
从hello页面进行导航。
/login.xhtml
成功
/wsListing.xhtml
您需要发送重定向。将
添加到
中
成功
/wsListing.xhtml
与具体问题无关,MyFaces2.1是一个JSF2.1实现。为什么你要强迫webapp在jsf1.2modus中运行?你错过了很多JSF2.x的优点。啊,好吧。如果您使用的是JSF2.x,那么您只需要使用
,而不需要整个导航案例。请查看它自己的站点。您只是强制它在JSF1.2 MODU中运行,因为您的faces config.xml
是这样声明的。您可以这样做,但这不是必需的。您可以强制JSF2在JSF1.xModus中运行,就像您已经做的那样。请注意,Weblogic 10.0.x本身已经附带了JSF 1.x。@BalusC…是上述问题的通用解决方案吗?我对Saskia de Jong在这个问题中给出的答案感到困惑。@Uppi:重定向创建了一个新的HTTP请求,如果您想在重定向之前为下一页准备一些数据,这需要一些技巧地点。