如果代码是这样的话,我无法重定向到另一个页面:
<h:commandButton type="button" value="Enter" action="index?faces-redirect=true" >
Run Code Online (Sandbox Code Playgroud)
但是,如果代码是:
<h:commandButton type="button" value="Enter" action="index?faces-redirect=true" >
<f:ajax />
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
有人能解释一下吗?谢谢!
- - - - - - - - - - - -编辑 - - - - - - - - - - - -
整个xhtml代码供您参考:
<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">
<h:head>
</h:head>
<h:body>
<h:form id="form">
<h:commandButton id="enterModelButton" type="button" value="Enter" action="index?faces-redirect=true" >
<f:ajax />
</h:commandButton>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
Bal*_*usC 46
该<h:commandButton type="button">
不会产生一个提交按钮.它只是生成一个没有任何效果的"死"按钮,纯粹用于自定义onclick="..."
脚本等.这有点像黑暗的JSF 1.0/1.1时代的遗留问题,因为在JSF中使用普通的vanilla HTML这种事情是不可能的.
在<f:ajax>
执行与阿贾克斯的权力通过JSF生成的提交onclick
.它不关心按钮type
.
从本质上讲,删除type="button"
和依赖其默认值type="submit"
应该可以解决您的问题.
<h:commandButton value="Enter" action="index?faces-redirect=true" />
Run Code Online (Sandbox Code Playgroud)
但是,总而言之,如果这是真正的代码并且您实际上并不打算调用bean操作,那么您将完全朝着错误的方向前进,以实现通过按钮导航到不同页面的功能要求.你应该使用<h:button>
而不是.
<h:button value="Enter" outcome="index" />
Run Code Online (Sandbox Code Playgroud)