【问题标题】:Passing a parameter in <p:commandLink>在 <p:commandLink> 中传递参数
【发布时间】:2013-06-25 08:21:05
【问题描述】:

您好,我有一个类似的代码:

<p:commandLink value="#{user.strUserid}" action="test.xhtml?faces-redirect=true"/>

如何将参数传递给 test.xhtml 以获取所述页面中的值? 我尝试使用&lt;f:param&gt; 标签。但是可以在test.xhtml 页面中获取值。 请提出建议。

【问题讨论】:

  • 你能补充更多细节吗?
  • But can get the value in the test.xhtml page ...这是什么意思?

标签: jsf primefaces


【解决方案1】:

&lt;h:link&gt;替换它

<h:link value="#{user.strUserid}" outcome="test.xhtml">
    <f:param name="foo" value="bar" />
</h:link>

并使用&lt;f:viewParam&gt;将其设置为与目标页面关联的bean的属性

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

另见:

【讨论】:

    【解决方案2】:

    那我觉得你需要试试&lt;f:setPropertyActionListener ..

    <h:commandButton action="#{testBean.takeParam}" >
        <f:setPropertyActionListener target="#{testBean.myStringVal}" value="something" />
    </h:commandButton>
    

    然后你可以在你的 bean 类中获取这个值

        @SessionScoped
        public class TestBean{
    
            public String myStringVal;
    
            public void setMyStringVal(String myStringVal) {
                this.myStringVal = myStringVal;
            }
    
        }
    
        public void takeParam{
             System.out.println("String Value: "+myStringVal);
        }
    

    另见Communication in JSF by BalusC

    【讨论】:

    猜你喜欢
    • 2013-12-14
    • 2019-04-18
    • 1970-01-01
    • 2012-01-22
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多