Skip to main content

Welcome to Geoff Hayward's Weblog

Commenting on Java, JavaFX, Java EE, Joomla, and IoT.

Sometimes JSF does not have a component that will produce a particular type of HTML element. That's not a problem but, I always forget the three method deep route to the context path. I always find I have to work through an IDE's code completion tool to find the application's path.

Here it is for next time:

#{facesContext.externalContext.requestContextPath}

A shorter version:

#{request.contextPath}

Just for completeness here is the JSP version:

${pageContext.request.contextPath}

And finaly, the scriptlet version:

<%
    String root = pageContext.getRequest().getServletContext().getContextPath();
%>

If you know any more please do leave a comment.


Tags: JSFJSP

Read

JSF Facelets can store the returned value yielded from a call to an EJB. Doing so will mean the EJB does less work.

Let's say you are implementing a Facelet that will display a message stating something like 'No results' when a collection is empty. If the collection is not empty, the Facelet will call the EJB a second time. First to calculate the size of the collection; second to display the data in the collection etc.

Here is an example:

    [...]

    <ui:fragment rendered="#{pages.all().size() == 0}" >
        <h:outputText value="No pages yet." />
    </ui:fragment>
                
    <ui:fragment rendered="#{pages.all().size() > 0}" >
        <h:dataTable value="#{pages.all()}" var="page">
            [...]
        </h:dataTable>
    </ui:fragment>

    [...]

In the example above the Facelet calls the EJB three times. First to calculate the size of the collection; second to display the elements the data table will occupy; third the data from the collection.

How to Store Values in JSF Facelets

The calling to the EJB can be reduced to just once per page render. Calling the backing bean using the ui:param JSF element will store the returned value in a variable.

<f:metadata>
   <ui:param name="pageSet" value="#{pages.all()}" />
</f:metadata>

Using the ui:param JSF element, here is an improved example:

    [...]

    <f:metadata>
      <ui:param name="pageSet" value="#{pages.all()}" />
    </f:metadata>

    [...]

    <ui:fragment rendered="#{pageSet.size() == 0}" >
        <h:outputText value="No pages yet." />
    </ui:fragment>
                
    <ui:fragment rendered="#{pageSet.size() > 0}" >
        <h:dataTable value="#{pageSet}" var="page">
            [...]
        </h:dataTable>
    </ui:fragment>

    [...]

I hope this helps.



Read

After several weeks of programming a bespoke blogging platform it's finished. Well kind of finished. I will get to that. The blogging platform is for Web Developers, who need the back-end application part of a platform but do not wish to be tied to one language and template engine for their own front-end development work.

Why the need? I decided to create my new website with Java EE 7. I am a huge fan of Java EE 7 and JSF 2.2. The blogging platform is simply a by-product of that wish.

In the next iteration I intend to crate a REST API so that the front-end can be an authenticated REST client. Thus achieving the goal of language and template engine independence. In the meantime I'm road testing the blog platform with my own website. Once the next iteration is ready I will probably commit the platform to a public GitHub repository. You can find more information about the blog platform over at javablogplatform.blogspot.co.uk/.

Why the new website? My blogging goal has changed since creating the old website. I wish to have more of a weblog. The subject area of this new website will be anything Java EE, Software Development, and MSc study related. I have of course imported the content from my older blog.

So here goes



Read

Mailing List


Responsive Media

With the ResponsiveMedia plugin for Joomla it is easy to add 3rd party content from YouTube, Vimeo, and Instagram right in to any Joomla! article.

ResponsiveMedia