1

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>
ZheFrench
  • 1,065
  • 2
  • 19
  • 41

2 Answers2

1

Yes, you have to store the parameter somewhere in the URL to retrieve it later. You can do this with either a path parameter or a query parameter. Typically you bind the parameter to bean property with your mapping. This way you can retrieve the value in the page using standard EL expressions which are referring to your bean properties.

chkal
  • 5,532
  • 18
  • 26
1

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.

Xtreme Biker
  • 28,480
  • 12
  • 120
  • 195
  • Ok.So it makes me think that there is a security problem. The user can pass every string in the URL and it will be treated as a parameter so i need to control in the backing bean the parameter. How do you handle this ? That was at the beginning the reason why i'd like to hide parameters in browser url .Another idea, is this really a bad way to mix JSF navigation with PrettyFaces. I explain my point. If you pass paremeters with your url in then could you use prettyfaces to rewrite URL using this parameter to something "agnostic". – ZheFrench Oct 22 '13 at 07:31
  • Prettyfaces converts in some way from pretty urls to normal ones. You can define your view to be `/Participant/New/#{param}` and then the user will be able to introduce `/Participant/New/myParam`, to be redirected to `/addParticipant.xhtml?param=myParam`. That also allows the user to introduce the last url directly, to be redirected to the same page. Security problem? There's no problem while you handle your param validation properly. Remember that GET requests shouldn't change DB state, they are only performed to retrieve data. Using good validation and preventing sql injection is enough. – Xtreme Biker Oct 22 '13 at 07:51