2 Replies Latest reply on Jul 8, 2009 2:54 PM by Kamil Burzynski

    Page parameters, actions, rewrites - questions

    Kamil Burzynski Newbie
      Hello,

      I have small application which operates on series of entities. For simplification, lets assume that this is blog application and the only entities it works on are text entries (entry has id, title, body).
      Now, I want to achieve following:

      - friendly urls, like this:  www.example.com/words-from-entry-title
      I can easily do like www.myapp.com/{entryId}, of course. I guess that
      the only and best solution will be to create custom converter?
      Such converter will take hyphenated title and find entry id and return it to entryHome?
      Then, I will be faced with a problem of generating those urls from title, but thats simpler and I'll cope
      with that.

      Is there any better approach?

      2) I would like to get URLs like this:
      www.example.com/recent (displays list of entries in chronological order)
      www.example.com/top (displays list of entries from best to worst rated)
      www.example.com/random (displays list of random entries)
      www.example.com/category/my-category-name (displays list of entries from given category)

      and so on.

      Moreover, most of the above should allow pagination (/top/2 /top/3 for example, to access
      page 2 or page 3 in 'top' order).

      How to achieve that in best way?

      So far I have thought about following:

      Try to create view.xhtml which is able to display series of entries. Then, in pages.xml
      provide section like this:

      <page view-id="/public/view.xhtml">
                <action execute="#{someAction}"/>

                <rewrite pattern="/top/page/{pageNum}"/>
                <rewrite pattern="/top"/>
                <rewrite pattern="/recent/page/{pageNum}"/>
                <rewrite pattern="/recent"/>
                <rewrite pattern="/random"/>
                <rewrite pattern="/category/{categoryName}/page/{pageNum}"/>
                <rewrite pattern="/category/{categoryName}"/>
      </page>

      and in action try to figure out which rewrite was used and populate the list, so view.xhtml
      just displays the list whatever it is. Should work, though I did not checked yet if I
      can figure out original URL. But even if I do, it will clutter my code with URL specific things,
      which I would like to avoid (though I can live with that, if necessary).

      Then, I got another idea - just to make view.xhtml a facelet template and create multiple pages
      like top.xhtml, random.xhtml which will use that template, do not decorate it at all, but
      have custom action to be called. Slightly cleaner, probably more flexible and less code clutter
      (does clutter xhtml files instead, but thats less painful).

      Is there any better approach?

      Is there any way to attach action to rewrite rule?

      If I want to store {pageNum} parameter into simple int, do I have create backing bean
      and set pageNum to its property? Can I create just pageNum to be seam components itself,
      of a type java.lang.Long, for example?

      PS. Seam will decorate my urls with conversationId, I guess there is no recommended way to get rid of that? :)