在@RequestScoped中没有获取请求参数ManagedBean
问题描述:
我有一个JSF页面并且有一个与之关联的Managedbean。在@RequestScoped中没有获取请求参数ManagedBean
我的XHTML页面看起来是这样的:
<h:head>
</h:head>
<h:body id="configuratorWrapper">
<h:form method="post" id="form" name ="name" prependId="false">
<f:view>
<div class="container">
<input type="hidden" name="exception" id="exception" value="aaa" />
</div>
<h:input type="hidden" name="email" id="email" value="#{emailManagedBean.sendEmailForErrorPage()}" />
</f:view>
</h:form>
<h:outputScript library="resources/bower_components/boostrap-sass/assets/javascripts" name="bootstrap.js"></h:outputScript>
</h:body>
emailManagedBean是相关Managedbean这是一个@RequestScoped ManagedBean。
在EmailManagebean的方法sendEmailForErrorPage()看起来像:
public Boolean sendEmailForErrorPage() {
this.exception = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("exception");
}
我需要得到的异常值,为 “AAA”,这是我在XHTML页面了。但现在我的价值为零。
我尝试使用
<p:commandButton name ='email' action="#{emailManagedBean.sendEmailForErrorPage()}">
<f:param name="exception" value="aaa" />
</p:commandButton>
不过结果却是零。
有人可以帮我解决这个问题。
答
我找到了解决这个问题的方法。我将它作为参数传递给该方法,而不是将其作为参数传递。它很好地工作。我能够得到例外的价值。
<f:event type="preRenderView" listener="#{emailManagedBean.sendEmailForErrorPage('aaa')}" />
难道你不应该在f:view中放置h:form来正确构建组件树吗? – OTM