【发布时间】:2013-12-27 22:07:29
【问题描述】:
我有带有链接的 AAA.jsf 页面:
<h:link value="To BBB" outcome="BBB">
<f:param name="id" value="10"/>
</h:link>
BBB.jsf:
<html>
<h:body>
<f:metadata>
<f:viewParam name="id"/>
</f:metadata>
<h:form>
<h:outputText value="#{bean.id}"/>
<h:commandButton value="Make some logic.." action="bean.doSomething"/>
</h:form>
</h:body>
</html>
Bean.class:
@ManagedBean
@ViewScoped
class Bean{
public String getId(){
Map<String,String> param = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
return param.get("id");
}
public void doSomething(){
//do some logic....
//I don't use id parameter
}
}
在我从 AAA 页面转到 BBB 页面并单击“Make some logic..”按钮后,doSomething() 方法中的所有代码都将运行。当这个方法结束并且我从返回时我得到 NullPointerException 因为我必须在getId() 方法中获取id 参数。这意味着我失去了 viewParam id。为什么?
编辑
相关问题: lose view page parameter
【问题讨论】:
-
你在doSomething方法中使用参数吗?
-
不,我不在那里使用它
标签: jsf jsf-2 parameters navigation nullpointerexception