Java and JBoss related stuff
RSS icon Home icon
  • Value-to-variable binding “let” tag for JSF, Facelets and Seam

    Posted on April 28th, 2008 Adam Warski 16 comments

    The “let” tag enables you to bind the value of any expression to a variable and later reuse it, without recalculating the value. The concept comes of course from functional programming. It is especially useful with Seam’s extended EL.

    The usage is really simple:

    
    <mamut:let var="result" value="#{anyElExpression}">
       Now you can use #{result} as a normal variable.
    </mamut>
    

    I was looking at other tag libraries but couldn’t find anything similar. Or maybe there is?

    The use case that motivated me to write this comes from the JBoss.ORG feeds application. There, in several places I have code similar to the following one:

    
    <ui:repeat var="group" value="#{groupsService.all}">
       <s:fragment rendered=
          "#{groupsService.accFeeds(group).size() > 0}">
          (some header)
          <ui:repeat var="feed"
             value="#{groupsService.accFeeds(group)}">
             (...)
          </ui:repeat>
       </s:fragment>
    <ui:repeat>
    

    Of course calling groupsService.acceptedFeeds(group) twice is unnecessarily inefficient. I could move this call to a backing bean, but doing so would only cause me to write some really simple code many times. The version using the let tag calls the method only once:

    
    <ui:repeat var="group" value="#{groupsService.all}">
       <mamut:let var="acceptedFeeds"
          value="#{groupsService.accFeeds(group)">
          <s:fragment rendered="#{accFeeds.size() > 0}">
             (some header)
             <ui:repeat var="feed" value="#{accFeeds}">
                (...)
             </ui:repeat>
          </s:fragment>
       </mamut:let>
    <ui:repeat>
    

    If somebody finds this useful, I’ve put the jar here. To use it, just bundle the jar with your application. The namespace for the tag is the following:

    
    xmlns:mamut="http://mamut.net.pl/jsf"
    

    Adam

  • Envers preview 2: versioning relations

    Posted on April 22nd, 2008 Adam Warski No comments

    You can now download a second preview version of the Envers library!

    As a quick reminder, the library enables you to easily version your JPA entities, by simply annotating their properties with @Versioned; it works as an extension to Hibernate and Hibernate Entity Manager.

    In this release, in addition to versioning simple properties, like strings, numbers, dates, you can also version the most common type of relations, namely:

    • @OneToOne
    • @OneToOne(mappedBy="...")
    • @ManyToOne
    • @OneToMany(mappedBy="...")

    Envers has now a growing test suite, which already helped to eliminate some bugs. Moreover, here you will find a description on how to generate a database schema of your entities together with the versions tables.

    If you’d like to share your opinion, you can now use the forum. Waiting for your posts there :).

    Adam

  • Introducing Envers: Easy Entity Versioning

    Posted on April 10th, 2008 Adam Warski 2 comments

    Hello,

    Envers is a project which enables you to version your entities, simply by annotating them with @Versioned! It is still very young, and far from a mature project, but some basic functionalities already work.

    The project’s web page can be found here: www.jboss.org/envers. There you can download a preview version, a short console demo as well as find a “quick start” guide.

    I’d really like to know your opinion on this project, if you find it useful, what features would you expect and so on. So please comment! :)

    Adam