How to reproduce specific Friendly URL ?

Splash Forums PrettyFaces Users How to reproduce specific Friendly URL ?

This topic contains 15 replies, has 2 voices, and was last updated by  Lincoln Baxter III 6 years, 2 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #17883

    LaChamelle
    Participant

    Hello,

    we are trying to refactor an JSP/XSLT application to JSF. We use a CMS for content management. Technologies : JSF 2.0 using Mojarra, PrimeFaces 2.2.1 and Tomcat 6.29 The organisation of the data structure is the following: There are Sites. Sites contain Channels. Channels contain Contents. Sites, channels and content are translated.

    The URLs look like: http://whatever/firstSite http://whatever/firstSite/aChannel http://whatever/firstSite/aChannel/aSubChannel/myGreatContent

    It’s the translated name who is showing to the user. The siteName only appears once, channel can appear many times and the content at maximum once

    For the moment, we use commandLinks. The action call update the context of the application and return the page id.

    Now we want to reproduce the friendly URL and replace the commandlink navigation (POST) with h:link or outpulink (GET).

    I read some stuffs about FURL with JSF and I saw the PrettyFaces’s solution.

    Can i reproduce the FURL with PrettyFaces ? If yes, could you give me some resources to start?

    And with h:link, i don’t see actionListener or action attribute, so how i can update my context?

    #20762

    Short answer, yes, you can do this easily with PrettyFaces.

    I suggest you start by reading the reference guide, which gives clear instructions on how to get started (if not clear, feel free to ask again here!)

    http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/

    http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/Configuration.html

    ~Lincoln

    #20763

    PrettyFaces actions are what you would use to update your content:

    http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/Configuration.html#config.actions

    #20764

    LaChamelle
    Participant

    Hello,

    I read the doc, I made simple case like

    http://whatever/site/siteId

    http://whatever/site/siteId/channel/channelId

    http://whatever/site/siteId/channel/channelId/content/contentId

    But i dont understand how to map http://whatever/firstSite/aChannel/aSubChannel/myGreatContent

    because there is no keyword only ids and they are variables. I should probably get with regex the “firstSite/aChannel/aSubChannel/myGreatContent” and parse by myself ?

    And for the rewrite is it possible to rewrite http://whatever/site/siteId/channel/channelId/content/contentId (generated by pretty:link) to http://whatever/firstSite/aChannel/aSubChannel/myGreatContent? Or should i generate directly in the value (http://whatever/firstSite/aChannel/aSubChannel/myGreatContent) of an h:outputlink ?

    #20765

    What do you mean, “there is no keyword only ids and they are variables”? Could you explain that please.

    You should not need a regex to do any of this. I need more information on what you are trying to do. What is your end goal? What is the problem you are having?

    It sounds like you are having some sort of data-conversion issue. This is something you should convert in the backing bean *before* you pass the data to “pretty:link” or any other output link.

    ~Lincoln

    #20766

    If you want to map the “Name” of the channel instead of the “ID” of the channel, then you need to map this:

    http://whatever/firstSite/aChannel/aSubChannel/myGreatContent

    And translate the Names to IDs in an action method. Do your data loading there.

    http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/Configuration.html#config.actions

    #20767

    LaChamelle
    Participant

    The name of the channels are differents.

    To resume i want to reproduce the breadcrumb in browser URL. So the path is different for every location, i can’t map all the available location of the website.

    I probably need some page-action method who will parse Dynamically URL.

    Now for the rewrite, i don’t want to create the breadcrumb. I prefer to make a

    <h:link outcome=”channel.jsf” value=”#{bean.channel.name}”>

    <f:param name=”chanId” value=”#{bean.channel.id}” />

    </h:link>

    and rewrite like http://whatever/firstSite/aChannel/aSubChannel/myGreatContent, if it’s possible.

    If not, I can write something like

    <h:outputLink value=”#{bean.channel.calculatedUrl}”>#{bean.channel.name}</outputLink>

    Thanks for you reply. I hope I was clearer in the statement of my problem.

    PS: in the documentation at 7.2, it’s missing a closing ” for the value attribute of your examples.

    #20768

    LaChamelle
    Participant

    To handle dynamic number of /, i see the sixth question in the FAQ but the link in the FAQ point to section 3.4 inheritance mapping (http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/Configuration.html#config.mapping.parents)?

    Is it correct ?

    #20769

    There’s no reason you should need to do this based on what you are telling me. I think you are over-thinking this.

    Create three mappings, one for each level of your URL. Use a page-load action to load your data.

    <url-mapping id="root">
    <pattern value="/site/#{siteName:bean.siteName}" />
    <view-id value="/faces/viewSite.jsf" />
    <action>#{bean.loadSite}</action>
    </url-mapping>
    <url-mapping id="channel">
    <pattern value="/site/#{siteName:bean.siteName}/#{channelName:bean.channelName}" />
    <view-id value="/faces/viewChannel.jsf" />
    <action>#{bean.loadChannel}</action>
    </url-mapping>
    <url-mapping id="subChannel">
    <pattern value="/site/#{siteName:bean.siteName}/#{channelName:bean.channelName}/#{subChannel:bean.subChannelName}" />
    <view-id value="/faces/viewSubChannel.jsf" />
    <action>#{bean.loadSubChannel}</action>
    </url-mapping>

    Then use <h:link> with <f:param value=”#{bean.channelName}”> … etc, not the ID. Just like you would normally.

    Note: You MUST do the conversion from Name -> ID, *yourself*, in the <action> methods; that is where you load the data.

    #20770

    If you want to clean up the mappings, use parentId…

    <url-mapping id="root">
    <pattern value="/site/#{siteName:bean.siteName}" />
    <view-id value="/faces/viewSite.jsf" />
    <action>#{bean.loadSite}</action>
    </url-mapping>
    <url-mapping id="channel" parentId="root">
    <pattern value="/#{channelName:bean.channelName}" />
    <view-id value="/faces/viewChannel.jsf" />
    <action>#{bean.loadChannel}</action>
    </url-mapping>
    <url-mapping id="subChannel" parentId="channel">
    <pattern value="/#{subChannel:bean.subChannelName}" />
    <view-id value="/faces/viewSubChannel.jsf" />
    <action>#{bean.loadSubChannel}</action>
    </url-mapping>

    #20771

    LaChamelle
    Participant

    I can have more than two levels. This list is not exhaustive.

    • /site/channel/contentOne
    • /site/channel/channelToto
    • /site/channel/channelTiti/fooChan
    • /site/channel/channelTiti/fooChan/barChan
    • /site/channel/channelTiti/fooChan/barContent
    • /site/channel/channelTiti/fooChan/barChan/tataChan
    • /site/channel/channelTiti/fooChan/barChan/totoContent

    So the following mapping will not match all the previous examples ?

    <url-mapping id="root">
    <pattern value="/site/#{siteName:bean.siteName}" />
    <view-id value="/faces/viewSite.jsf" />
    <action>#{bean.loadSite}</action>
    </url-mapping>
    <url-mapping id="channel" parentId="root">
    <pattern value="/#{channelName:bean.channelName}" />
    <view-id value="/faces/viewChannel.jsf" />
    <action>#{bean.loadChannel}</action>
    </url-mapping>
    <url-mapping id="subChannel" parentId="channel">
    <pattern value="/#{subChannel:bean.subChannelName}" />
    <view-id value="/faces/viewSubChannel.jsf" />
    <action>#{bean.loadSubChannel}</action>
    </url-mapping>

    I appreciate the time you spend to answer me ;)

    #20772

    How many levels can you have? In which case, you probably *do* want the custom URL regex.

    #20773

    LaChamelle
    Participant

    We have not limit. The user create how many levels we want.

    Can you give me an example line of rewrite with processor ?

    Thanks you.

    #20774

    Use a custom path-parameter regex and parse the URL yourself in an action method or in dynaview:

    http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html_single/#config.pathparams.regex

    <url-mapping id="root">
    <pattern value="/site/#{/.*/ customUrl : bean.url}" />
    <view-id value="#{bean.calculateViewId}" />
    </url-mapping>

    #20775

    LaChamelle
    Participant

    Ok.

    Is it possible to access to FacesContext and managed beans from a class which implement Processor ?

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.

Comments are closed.