漂亮的脸蛋JSF 2:我们是否总是需要将参数传递给URL来检索它们? [英] PrettyFaces & JSF 2 : Do we always need to pass parameters to the URL to retrieve them?

查看:117
本文介绍了漂亮的脸蛋JSF 2:我们是否总是需要将参数传递给URL来检索它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是否总是需要将参数传递给URL来检索它们?

在我的示例中,我无法检索名为"study"的参数; 我该怎么办?

XHTML文件发送器:

 <h:commandButton  value="Send" type="button" action="pretty:participant">
    <f:param  name="study"  value ="test"  />
</h:commandButton> 
 

XHTML文件接收器:

 <h:outputFormat value="Print : {0} ">
   <f:param value="#{study}" />      
</h:outputFormat>
 

Pretty Config XML:

 <url-mapping id="participant">
    <pattern value="/Participant/New/" />
    <view-id value="/addParticipant.xhtml" />
</url-mapping>
 

解决方案

如果要使用prettyfaces进行操作,是的,必须这样做,因为它是url改写工具,因此参数必须包含在url中.为了使代码正常工作,在接收器页面上使用f:viewParam标签之前,应先使用f:viewParam标签:

 <f:metadata>
    <f:viewParam name="study" value="#{destinationBean.study}" />
</f:metadata>

<h:outputFormat value="Print : {0} ">
   <f:param value="#{destinationBean.study}" />      
</h:outputFormat>
 

但是,如果要摆脱通过url发送参数的麻烦,可以使用 Flash作用域作为替代.但是,这涉及到JSF而不是Prettyfaces.如果您想使用此解决方案,我强烈建议您避免使用Mojarra JSF 2.x的早期版本,因为它们与此有关.

Do we always need to pass parameters to the URL to retrieve them ?

In my example , I can't get to retrieve my param named 'study'; How should i do that ?

XHTML File Sender:

<h:commandButton  value="Send" type="button" action="pretty:participant">
    <f:param  name="study"  value ="test"  />
</h:commandButton> 

XHTML File Recever:

<h:outputFormat value="Print : {0} ">
   <f:param value="#{study}" />      
</h:outputFormat>

Pretty Config XML :

<url-mapping id="participant">
    <pattern value="/Participant/New/" />
    <view-id value="/addParticipant.xhtml" />
</url-mapping>

解决方案

If you want to do it using prettyfaces, yes, you must because it's an url rewritting tool, so the params must go into the url. For your code to work, you should use the f:viewParam tag before using it in your receiver page:

<f:metadata>
    <f:viewParam name="study" value="#{destinationBean.study}" />
</f:metadata>

<h:outputFormat value="Print : {0} ">
   <f:param value="#{destinationBean.study}" />      
</h:outputFormat>

However, if you want to get rid of sending the parameter via url, you have the flash scope as an alternative. That, however, involves JSF and not Prettyfaces. If you want to go with this solution I highly encourage you to avoid early versions of Mojarra JSF 2.x, as they are buggy related to that.

这篇关于漂亮的脸蛋JSF 2:我们是否总是需要将参数传递给URL来检索它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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