来自CommandButton的JSF ViewParam [英] JSF ViewParam from CommandButton

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

问题描述

我正在使用JSF和Primefaces,我的问题是:

I'm using JSF and Primefaces and my question is:

我有一个页面(page1.jsf),该页面使用字符串列表(以空格分隔)获取视图参数:

I have a page (page1.jsf) that recive a view param with a list of strings (space delimited):

<f:metadata>
 <f:viewParam name="list" value="#{bean1.list}" converter="listConverter"/>
</f:metadata>

listConverter将字符串转换为单个单词的列表. 如果我通过url访问该页面(例如:page1.jsf?list = word1 word2 word3),则一切正常!

The listConverter convert the string into a list of individual words. If I access the page through url (eg: page1.jsf?list=word1 word2 word3") everything works just fine!

但是现在我正尝试使用另一个页面(page2.jsf)创建该术语列表. 我使用的是Primeface DataTable,其示例如下: http://www.primefaces.org /showcase/ui/datatableRowSelectionRadioCheckbox.jsf

But now I'm trying to use another page (page2.jsf) to create that list of terms. I'm using a Primeface DataTable, following this example: http://www.primefaces.org/showcase/ui/datatableRowSelectionRadioCheckbox.jsf

我希望用户可以选择多行(复选框Primeface示例),然后按下一个按钮,该按钮将重定向到page1.jsf并还将所选项目的列表作为参数传递(例如,使用Primeface展示示例,通过所选汽车型号的列表.

I want tomake possible to the user to select multiple rows (checkbox Primeface example) and then press a button that will redirect to page1.jsf and also passes the list of selected items as parameter (eg. using the Primeface showcase example, pass a list of the selected car models).

我正在尝试这样做:

<p:commandButton action="page1?faces-redirect=true&amp;includeViewParams=true" >
 <f:attribute name="list" value="#{bean2.convertSelectedItemsToString()}" />
</p:commandButton>

或者这个:

<p:commandButton action="page1?faces-redirect=true&amp;includeViewParams=true" >
 <f:param name="list" value="#{bean2.convertSelectedItemsToString()}" />
</p:commandButton>

其中bean2具有一个selectedItems [],其中对象被选中.

where bean2 has a selectedItems[] with the objects selected.

不用说...那是行不通的.

Needless to say... It's not working.

有帮助吗? 预先感谢.

Any help? Thanks in advance.

推荐答案

命令按钮不使用属性或参数来构造重定向发生的URL.

A command button does not use an attribute or parameter to construct the URL to which redirection happens.

为此,您通常使用h:commandLink或可选地使用h:outputLink,但是您需要注意,这些参数将呈现请求页面时的参数.如果用户此后对选择进行了更改,则这些更改将不会反映在链接中.

For this you normally use the h:commandLink or optionally the h:outputLink, but you need to be aware that these will render the parameters as they were at the time the page was requested. If the user makes changes to the selection after that, those won't be reflected in the link.

为您提供最新选择的另一种方法是使用一种操作方法,并在那里构造重定向URL.

An alternative that would give you the latest selection, is using an action method and construct the redirect URL there.

例如

<p:commandButton action="#{bean2.navigateWithSelection}" />

然后在您的bean中:

And then in your bean:

public String navigateWithSelection() {
    return "page1?faces-redirect=true&" + convertSelectedItemsToString();
}

根据注释,如果bean2是不了解页面的通用bean,则可以将目标页面作为参数传递:

As per the comments, if bean2 is a generic bean that has no knowledge about the page, you can pass in the target page as a parameter:

<p:commandButton action="#{bean2.navigateWithSelection('page1')}" />

然后再次在您的bean中:

And then in your bean again:

public String navigateWithSelection(String target) {
    return target + "?faces-redirect=true&" + convertSelectedItemsToString();
}

这篇关于来自CommandButton的JSF ViewParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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