JSF ViewParam必需+ AJAX打破页JSF、ViewParam、AJAX

由网友(一切,都乱了)分享简介:当我点击页面上的命令按钮下方的导航失败。 (点击该按钮刷新页面,删除URL参数,并显示而不是导航到该索引页所需的错误消息)但是,如果我删除所需要的属性或删除我在F:AJAX标签导航正常工作使用com.sun.faces JSF 2.1.13和primefaces 3.4。<!DOCTYPE HTML PUBLIC...

当我点击页面上的命令按钮下方的导航失败。 (点击该按钮刷新页面,删除URL参数,并显示而不是导航到该索引页所需的错误消息)

但是,如果我删除所需要的属性或删除我在F:AJAX标签导航正常工作

使用com.sun.faces JSF 2.1.13和primefaces 3.4。

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-transitional.dtd>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
    的xmlns:F =htt​​p://java.sun.com/jsf/core
    的xmlns:H =htt​​p://java.sun.com/jsf/html
    的xmlns:UI =htt​​p://java.sun.com/jsf/facelets>

< H:头>< / H:头>

 < F:元数据>
        < F:viewParam名=产品
            所需=真requiredMessage =错误的请求,请使用一个链接,从体制内。/>
    < / F:元数据>

<身体GT;

    < H:格式ID =形式>
        &所述; H:selectBooleanCheckbox>
            < F:AJAX更新=形式/>
        < / H:selectBooleanCheckbox>
        < H:的commandButton值=买入行动=/?的index.xhtml面临重定向=真正的/>
    < /小时:形式GT;

< /身体GT;
< / HTML>
 

解决方案

我会假设更新=形式是一个不小心过于简单和你实际的意思使用渲染=@表和PrimeFaces左右糊涂了。

让我们回到具体的问题,这是造成执行非Ajax回发来触发的视图参数的处理也是如此。

要么让它要求非回发只(请确保bean是视图范围虽然),

 < F:viewParam ...所需=#{不facesContext.postback}/>
 
JSF2Ajax.pdf

,或把它传递回传以及

 < H:的commandButton ...>
    < F:参数名称=产品的价值=#{bean.product}/>
< / H:的commandButton>
 

或使用 OmniFaces <○:viewParam> 代替如果你已经在使用的视图作用域bean。它不会处理上回发视图参数。

 < ...的xmlns:O =htt​​p://omnifaces.org/ui>
...
<○:viewParam ... />
 

When I click the command button on the page below navigations fails. (Clicking on the button refreshes the page, removes the URL parameter and displays the required error message instead of navigating to the index page)

However if I remove the required attribute OR I remove the f:ajax tag the navigation works fine.

Using com.sun.faces JSF 2.1.13 and 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>

解决方案

I'll assume that the update="form" is a careless oversimplification and that you actually meant to use render="@form" and confused it with PrimeFaces or so.

Coming back to the concrete problem, that's caused by performing a non-ajax postback which triggers the processing of view parameters as well.

Either make it required on non-postback only (make sure that the bean is view scoped though),

<f:viewParam ... required="#{not facesContext.postback}" />

or pass it on postback as well

<h:commandButton ...>
    <f:param name="product" value="#{bean.product}" />
</h:commandButton>

or use OmniFaces <o:viewParam> instead if you're already using a view scoped bean. It won't process the view parameter on postbacks.

<... xmlns:o="http://omnifaces.org/ui">
...
<o:viewParam ... />

阅读全文

相关推荐

最新文章