失去查看页面参数 [英] lose view page parameter

查看:115
本文介绍了失去查看页面参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有页面my.xhtml:

i have page my.xhtml:

<f:metadata>
  <f:viewParam name="id"/>
</f:metadata>
...
<h:form>
  Current id is: "#{id}"

  <h:commandButton action="#{bean.doSomething}" value="Do some logic..">
     <f:param name="id" value="#{id}"/>
  </h:commandButton>
</h:form>

和Bean.java:

and Bean.java:

@ManagedBean
@ViewScoped
public class Bean {
   ....
   public void doSomething(){
     //do some logick, don't use id parameter
   }
}

当我第一次进入id = 10的页面时,可以在页面Current id is: "10".上看到. 当我单击按钮时,页面将重新加载,并且可以再次在页面Current id is: "10".上看到.

When I get to page first time with id=10 I can see on page Current id is: "10".. When I click on button page is reload and I can see on page Current id is: "10". again.

但是当我第三次单击按钮时,我可以在页面Current id is: "".上看到,我丢失了id参数,我不明白为什么?

But when I click on button third time I can see on page Current id is: ""., i lose id parameter and I don't understand why?

我知道我可以通过在bean中保存参数值来做到这一点 (通过添加到f:viewParam:

I know I can do this with save parameter value in bean (by add to f:viewParam:

<f:metadata>
  <f:viewParam name="id" value="#{bean.value}/>
</f:metadata>

),但是我可以在不将参数值保存到bean中的情况下执行此操作吗?

), but can I do this without save parameter value in bean?

推荐答案

h:button适用于f:param,但h:commandButton无效.在这种情况下,最好的方法是在解释最后一个参数时将view参数绑定到bean属性.只要调用void动作方法,@ViewScoped bean就会保留其状态.

h:button works with f:param but h:commandButton does not. In this case, your best is to bind the view parameter to a bean property as you explain the last. The @ViewScoped bean will retain its state as long as you call void action methods.

您也可以将它作为参数传递给action方法(有多种方法可以执行此操作),但这对于与该值无关的方法没有意义.

You could also pass it as a parameter to the action method (there are several ways to do that), but this doesn't make sense for a method which has nothing to do with that value.

另请参见:

  • Passing parameters to action methods in JSF
  • Communication in JSF

这篇关于失去查看页面参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆