Monday, 21 September 2009

Generics and getResultList()

So, this is a common problem with a dirty workaround.

If you try

public List<YourClass> getAllResults()
{
  return entityManager.createNamedQuery("YourClass.findAll").getResultList();
}

You get this:

found   : java.util.List
required: java.util.List<YourClass>
    return (List<YourClass>) entityManager.createNamedQuery("YourClass.findAll").getResultList();

or if you haven't compiled with -Xlint:unchecked, this Note: YourClass.java uses unchecked or unsafe operations.

The issue is described here

Saturday, 19 September 2009

Detecting Errors From Request Processing in JSF Pages

Recently I came across a little problem — display a portion of JSF only if the request was successful, i.e. no validation errors and if the request has actually been sent to the server (no request, no errors). Here is what I did:
<h:outputText
  rendered="#{empty facesContext.maximumSeverity && !empty Enquirer.name}"
  value="Thank you. You message has been sent."/>
The source that pointed me in the right direction.

JSF + Managed Beans + Managed Properties

I have stumbled upon this article (by Chris Schalk)while trying to remember what <managed-property> meant  in faces-config.xml.

Very interesting and useful when you're developing JSF backed by EJB3.0.