问题描述
我正在使用JSF2,我需要能够通过commandLink将参数从一个JSF页面传递到另一页面.
I am using JSF2, and I need to be able to pass a parameter from one JSF page to another via a commandLink.
我在页面funding.xhtml
(ViewScoped)上,并定义了以下链接:
I am on page funding.xhtml
(ViewScoped) and have the following link defined:
<p:commandLink styleClass="toolbar"
action="/application/customerApplicationManagement.jsf">
<p:graphicImage url="/resources/gfx/search.png" />
<h:outputText value="#{msg.menu_searchApplications}" styleClass="toolbarLink" />
</p:commandLink>
我需要将一个字符串值传递给customerApplicationManagement页面,以指示我来自哪个页面,以便在选择应用程序后可以返回该页面.我已经尝试过一些有关如何传递此值的建议,包括f:param
,f:viewParam
.我什至尝试将其直接添加到url(?fromPage=funding
)等中,但是它们似乎仅在将值传递回当前页面时才起作用,而不是我要导航的新页面.
I need to pass a string value to the customerApplicationManagement page indicating which page I came from so that after selecting an application, I can return to that page. I have tried several suggestions about how to pass this value including f:param
, f:viewParam
. I have even tried just adding it directly to the url (?fromPage=funding
) etc, but they all seem to work only when the value is passed back to the current page, not a new page I am navigating to.
有人可以告诉我如何最好地做到这一点.
Can someone show me how this can best be accomplished.
推荐答案
使用<f:param>
和<f:viewParam>
:
源页面:
<p:commandLink styleClass="toolbar"
action="/application/customerApplicationManagement.jsf">
<p:graphicImage url="/resources/gfx/search.png" />
<h:outputText value="#{msg.menu_searchApplications}" styleClass="toolbarLink" />
<f:param name="fromPage" value="funding.xhtml" />
</p:commandLink>
目标页面(绑定):
<f:metadata>
<f:viewParam name="fromPage" value="#{destinationBacking.fromPage}" />
</f:metadata />
<h:link value="Go back!" outcome="#{destinationBacking.fromPage}" />
目标页面(未绑定):
<f:metadata>
<f:viewParam name="fromPage" />
</f:metadata />
<h:link value="Go back!" outcome="fromPage" />
支持bean(仅当您要绑定参数时):
@ManagedBean
@ViewScoped
public class DestinationBacking{
String fromPage;
public String getFromPage(){
return fromPage;
}
public void setFromPage(String frompage){
fromPage = frompage;
}
}
您的视图路径将从目标支持bean绑定到fromPage
属性,然后您可以使用它返回到原始页面.
Your view path will be binded to fromPage
property from the destination backing bean and after you can use it to return to the original page.
我还要说这种方式对于最终用户来说有点可破解",我的意思是,您正在通过纯url传递原始路径.另请参见实现此目标的其他方法,例如 Flash范围,这在使用@ViewScoped
bean时特别有用.
Also I want to say that this way is a bit 'hackeable' by the end user, I mean, you're passing the original path through pure url. See also other ways to achieve that, as flash scope, which is very useful specially if you're working with @ViewScoped
beans.
这篇关于导航到另一个页面时查看参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!