我有一个 JSF 页面并有一个与其关联的 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 页面中给出的。但我现在得到的值是 null。
我尝试使用
<p:commandButton name ='email' action="#{emailManagedBean.sendEmailForErrorPage()}">
<f:param name="exception" value="aaa" />
</p:commandButton>
结果仍然为空。
有人可以帮我解决这个问题吗?
最佳答案
我已经找到解决这个问题的方法了。我没有将其作为参数传递,而是将其作为参数传递给该方法。效果很好。我能够获得异常值。
<f:event type="preRenderView" listener="#{emailManagedBean.sendEmailForErrorPage('aaa')}" />
关于java - 未在 @RequestScoped ManagedBean 中获取请求参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45081985/