当我点击页面下方的命令按钮时,导航失败。 (单击按钮刷新页面,删除URL参数并显示所需的错误消息,而不是导航到索引页面)
但是,如果我删除了所需的属性,或者我删除了f:ajax标记,导航工作正常。
使用com.sun.faces JSF 2.1.13和primefaces 3.4。
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head></h:head>
<f:metadata>
<f:viewParam name="product"
required="true" requiredMessage="Bad request. Please use a link from within the system."/>
</f:metadata>
<body>
<h:form id="form">
<h:selectBooleanCheckbox>
<f:ajax update="form" />
</h:selectBooleanCheckbox>
<h:commandButton value="buy" action="/index.xhtml?faces-redirect=true" />
</h:form>
</body>
</html>
答案 0 :(得分:13)
我会假设update="form"
是粗略的过度简化,你实际上是想使用render="@form"
并将其与PrimeFaces混淆。
回到具体问题,这是由执行非ajax回发引起的,这也会触发视图参数的处理。
要么仅在非回发时使它成为必需(确保bean是视图作用域),
<f:viewParam ... required="#{not facesContext.postback}" />
或者也可以在回发时传递
<h:commandButton ...>
<f:param name="product" value="#{bean.product}" />
</h:commandButton>
如果您已经在使用视图范围的bean,请使用或使用OmniFaces <o:viewParam>
。它不会处理回发上的view参数。
<... xmlns:o="http://omnifaces.org/ui">
...
<o:viewParam ... />