问题描述
我编写了一个jsf应用程序,该应用程序将数据插入mysql数据库,并在另一页中显示一些插入的详细信息.
我已成功将值插入数据库,但是即使编写了导航规则也无法重定向到另一页.
我的操作代码
<div align="center"><p:commandButton label="Submit" action="#{userData.add}" align="center" ajax="false" /></div>
导航规则
<managed-bean>
<managed-bean-name>UserData</managed-bean-name>
<managed-bean-class>userData.UserData</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>home.xhtml</display-name>
<from-view-id>/home.xhtml</from-view-id>
<navigation-case>
<to-view-id>/badge.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
如果我将face-redirect写入true,则显示错误,或者如果将操作写入另一页,则它未将值插入数据库.
停止读取JSF 1.x资源,并摆脱faces-config.xml
中所有JSF 1.x样式的<managed-bean>
和<navigation-rule>
条目. /p>
用于action="#{userData.add}"
的正确的JSF 2.x方法如下:
@ManagedBean
@ViewScoped
public class UserData {
public String add() {
// ...
return "/badge.xhtml?faces-redirect=true";
}
}
不需要其他XML混乱.也没有动作侦听器.
可以在我们的JSF Wiki页面中找到JSF 2.x教程/书籍的链接.
另请参见:
I wrote a jsf application, this app inserts the data into mysql database and shows some of the inserted details in another page.
I am successful in inserting the values into database, but unable to redirect to the other page even after writing the navigation rule.
My action code
<div align="center"><p:commandButton label="Submit" action="#{userData.add}" align="center" ajax="false" /></div>
Navigation rule
<managed-bean>
<managed-bean-name>UserData</managed-bean-name>
<managed-bean-class>userData.UserData</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>home.xhtml</display-name>
<from-view-id>/home.xhtml</from-view-id>
<navigation-case>
<to-view-id>/badge.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
If i write the face-redirect true then its showning an error, or if i write the action to the other page then its not inserting the values to database.
Stop reading JSF 1.x resources and get rid of all that JSF 1.x-style <managed-bean>
and <navigation-rule>
entries in faces-config.xml
.
The proper JSF 2.x approach for your action="#{userData.add}"
is as below:
@ManagedBean
@ViewScoped
public class UserData {
public String add() {
// ...
return "/badge.xhtml?faces-redirect=true";
}
}
No additional XML mess needed. Also no action listeners.
Links to JSF 2.x tutorials/books can be found in our JSF wiki page.
See also:
- How to choose the right bean scope?
- How to navigate in JSF? How to make URL reflect current page (and not previous one)
- Differences between action and actionListener
这篇关于导航到另一个页面JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!