【发布时间】:2013-01-07 10:57:03
【问题描述】:
我想我遇到了@ViewScoped 和a4j:commandButton 的错误。
我有一个非常复杂的表单,其中所有操作都使用 a4j,除了那些需要上传数据的操作。 根据命令的顺序,viewParam 的验证会中断。
这是工作代码:
<?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:a4j="http://richfaces.org/a4j" >
<f:metadata>
<f:viewParam id="viewParam" name="viewParam" value="#{bean.viewParam}" required="true" />
</f:metadata>
<h:head>
<title>Test View Param</title>
</h:head>
<h:body>
<h:message for="viewParam" />
<hr/>
<h:form>
#{bean.viewParam}<br/>
<h:commandButton value="cmdButton" />
<a4j:commandButton value="a4jBtn" execute="@this" render="@form" />
</h:form>
</h:body>
</html>
只需单击a4jBtn,然后单击cmdButton 即可查看问题。
你会看到参数还在!但验证失败。
<t:saveState> 没有帮助,
<rich:message> 也不是更好,但是
<h:commandButton value="ajaxBtn" ><f:ajax execute="@this" render="@form" /></h:commandButton>
而不是
<a4j:commandButton value="a4jBtn" execute="@this" render="@form" />
工作正常!
在 Tomcat 6.0.18 和 jboss-el 2.0.0.GA 上使用 myFaces 2.0.15 和 richFaces 4.2.3.Final。
我可以通过使用f:ajax 而不是a4j:commandButton 来解决我的问题,但也许您有更好的主意,或者您可以向我解释发生了什么问题?
【问题讨论】:
-
已通过使用 omnifaces 和
-
不客气。我已经看到了这个问题并且已经知道
<o:form includeViewParams="true" >会这样做。我不知道为什么我懒得回答。也许是因为我不想把“另一个库”推到喉咙里 :) 如果您在以后的问题中提到您也在使用 OmniFaces,这可能会有所帮助。 -
@BalusC:好的,对。我以后会提到 OmniFaces。但现在请写一个答案!
-
@BalusC:我在
@ViewScoped上遇到了更多问题,但现在只要使用<o:form>就可以正常工作,遗憾的是,核心中没有解决这个问题。顺便说一句,我开始使用 OmniFaces 的原因是 stackoverflow.com/questions/10449862/…。 -
您可能需要花时间浏览展示示例以了解 OmniFaces 都提供了什么:showcase-omnifaces.rhcloud.com 通常,它只是解决了 JSF 中的一些缺点。
标签: jsf ajax4jsf commandbutton