【发布时间】:2011-10-29 04:03:08
【问题描述】:
我一直在处理我的 JSF 项目,但我有一个新的疑问。 我的 xhtml 代码如下所示
<?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:t="http://myfaces.apache.org/tomahawk">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form enctype="multipart/form-data" >
<h:selectOneMenu rendered="#{uploadVerifier.check(userVerifier.username)}" >
<f:selectItems value="#{uploadVerifier.options}" />
</h:selectOneMenu>
<br/>
<t:inputFileUpload required="true" value="#{uploadFile.upFile}" />
<br/>
<h:commandButton value="Validar"
action="#{uploadFile.upload(userVerifier.username)}"/>
</h:form>
</h:body>
</html>
问题是,每次我点击按钮时,它都会向我发送 NullPointerException,因为似乎 userVerifier.username 没有返回值。这个 Bean 值有一个来自以前 xhtml 的参数,而且更奇怪的是因为我在 h:selectOneMenu ...
中使用了它这里缺少什么? 提前致谢!
附: uploadFile.upload(String param) 应该只打印 param 的值。
【问题讨论】:
-
终于有办法了。
h:commandButton value="Validar" action="#{uploadFile.upload}"> <f:param name="truc" value="#{userVerifier.username}" /> </h:commandButton>然后在我的 Bean 中Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); String thing= params.get("truc");做到了……现在显而易见的问题是这是将参数传递给 h:commandButton 的唯一方法吗? -
我正要按照你在看到article 之前所说的那样回答你的问题。我觉得应该还有其他问题
-
您是否将 RequestScope 用于您的 userVerifier 托管 bean?如果是这样,您可以尝试将其设置为 ViewScope 并查看它是否有效?
-
你说的那篇文章是我看过的。我尝试使用 ViewScope(没有 f:param)但没有用。我认为唯一的方法是我在第一条评论上发布的方式。但我仍然认为这应该就像将我的 userVerifier bean 作为另一个 bean 的参数传递一样简单。
标签: jsf button parameters