Forge app error “No mime type could be found for file favicon.ico”

Apps generated using JBoss Forge get this error showing up in the server log:

JSF1091: No mime type could be found for file favicon.ico.  To resolve this, add a mime-type mapping to the applications web.xml

This is described in this bug: https://issues.jboss.org/browse/FORGE-657

The quick fix is to add this to your web.xml:

<mime-mapping>
   <extension>ico</extension>
   <mime-type>image/x-icon</mime-type>
</mime-mapping>

JSF conditional text output

Use an EL expression in the rendered attribute, for example:

<h:outputText value="some conditional message" rendered="#{! empty someManagedBean.someProperty}" />

Setting the default/welcome page for a JSF app

Since <welcome-file-list> only works with physical files, you cannot use a *.jsf filename here since this resolves to a different physical file (like *.xhtml).

To define a welcome file, use one of the following approaches:

    • add an index.html file, and include a refresh meta tag in the head:

      <head>
      <meta http-equiv="Refresh" content="0; URL=your_welcome_page.jsf">
      </head>

 

  • add an index.jsp file, and redirect to your welcome page:

    <% response.sendRedirect("dropdowns.jsf"); %>

Initializing a JSF ManagedBean

Sometimes things really are easy – the fact that I Googled how to do this now seems pretty silly. The more I use JSF the more I like it 🙂

To initialize the state of the ManagedBean that a JSF page is using (like to preload data, or initialize other displayed values), just call the code from the bean’s constructor. Simple as that.

For example

@ManagedBean
public class ExampleController
{
    private String exampleProperty1;
    private String exampleProperty2;

    public ExampleController()
    {
    //example init code here, e.g. to init property values
    }

    ...

}