3

In my JSF web-app, I want to create a URL for the user to bookmark or copy. That part is easy enough, like this:

<h:link value="Permanent Link"
        outcome="/showStuff"> 
    <f:param name="recID" value="#{bean.recordID}" />
</h:link>

Although that link has the desired parameter (recID) in it, it also has the windowid parameter generated by the JSF Servlet. Is there any convenient way to generate the URL without the windowid parameter? Or does this make any difference?

(This is with Mojarra)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
AlanObject
  • 9,613
  • 19
  • 86
  • 142
  • JSF/Mojarra doesn't do that. Aren't you confusing with CDI or any CDI extension? E.g. `@WindowScoped` or something? – BalusC Mar 30 '12 at 04:47
  • @BalusC well I am using Apache MyFaces CODI to implement ViewAccessScoped. Is that what is doing it to me? – AlanObject Mar 30 '12 at 14:40
  • Most likely. The standard CDI `@ConversationScoped` does also do that by adding `cid` request parameter. How else should it be able to keep track of multiple views in a single conversation? I think you need to lookup in the CODI docs how to turn off appending the window ID in ``. If in vain, I think your best bet is using plain `` instead. – BalusC Mar 30 '12 at 14:43
  • 2
    You can disable this parameter via CODI configuration. See http://stackoverflow.com/a/14997570/1535995 – Sasa7812 Feb 21 '13 at 11:28

1 Answers1

5

You can remove the WindowId using a URLRewriteFilter framework such as OCPsoft Rewrite URLRewriteFilter

Doing something like this should be fairly straightforward using a single configuration rule. You can obviously fiddle if this rule is either too strict or too general.

.defineRule()
.when(Direction.isOutbound().and(
        URL.matches("{prefix}{windowId}{suffix}")
         .where("windowId").matches("windowId=[^&]+")))
.perform(Substitute.with("{prefix}{suffix}"))

Check out the rewrite site. It's pretty easy to set up. http://ocpsoft.org/rewrite/

Lincoln
  • 3,151
  • 17
  • 22
  • 1
    Can't resist to comment that the writer of this answer is also the author of the framework in question - which I can definitely recommend :-) – Jan Groth Mar 30 '12 at 19:01
  • 1
    Heh. Just because you wrote a framework isn't any reason to hold it against you! This looks interesting but way overkill for my needs. I could just write a method in my bean to generate the URL based on parts pulled from the FacesContext, some constants, and the one variable. Even so I'll play with the Rewrite approach because it looks like it will be useful for more complicated situations later. – AlanObject Mar 30 '12 at 19:17
  • Yeah you could do that too. I guess this kind of approach is useful for when you want to perform this over many pages without changing your application code :) – Lincoln Mar 30 '12 at 21:13
  • 1
    PS. Let me know how it goes! I and the other devs would be glad to help you work through any issues on the forums: http://ocpsoft.org/support/ – Lincoln Mar 30 '12 at 21:14
  • @Sasa7812 gave the proper answer. Using a 2nd framework, because you ignore the config of the first one is nonsense. – Dar Whi Sep 15 '13 at 17:54
  • Depends if you want to disable globally or not. – Lincoln Sep 15 '13 at 22:04