Monthly Archives: October 2011

logging in java

since the last time i developed java(like 3 or 4 years ago) logging didn’t change very much… in my opinion… out project is using log4j… or thats what i thougth… there is a xml config file, which tells the logger where to put which level how… and actually we still use log4j… but its different… its slf4j, which a generic framework, that uses loggers… so whatever we use… we always talk with slf4j and configuration defines the effectiv log… chaning the logging framework is easy and has no impact to the code… on an other project we use logback… which i first didn’t realize… which is, in my opinion a really good thing…

so logging did change, but for me as a developer, it actually didnt… it still feels like the same… and thats not because slf4j, log4j and logback is from the same developer team…

JSF AlertBox

So once again i m working on a frontend… my main goal was not to work on frontends again… not that i dont want to do these kind of work, but creating customer facing stuff is demanding (which is a good thing) and a pain, because of the Business… a good idea is death, when the Business thinks they have a good idea aswell… so frontend pixel moving is really not my enjoyable work… but as i said… im doing it again… 

this time with JSF (JavaServer Faces)… in general, i like JSF ans its concepts… but there are still some really confusing things, including communication frontend to backend. But this might be a ajax problem… 

and now to the topic related stuff. I needed to implement an AlertBox. We use PrimeFaces, therefore i tried to do it as a dialog. But dialogs cant be updated, so its inside an outputPanel… 

xhtml

<p:outputPanel id=”alertBoxPanel”>
  <p:dialog header=”#{alertBoxBean.header}” widgetVar=”alertBoxDialog” visible=”#{alertBoxBean.show}”>
    <h:form>
      <table cellpadding=”0″ cellspacing=”0″ border=”0″>
      <tr>
        <td align=”center”><h:outputText value=”#{alertBoxBean.text}” escape=”false” /></td>
       </tr>
      <tr>
        <td align=”center”><p:commandButton value=”Ok” oncomplete=”alertBoxDialog.hide();” actionListener=”#{alertBoxBean.handleClose}” /></td>
     </tr>
    </table>
  </h:form>
</p:dialog>
</p:outputPanel>

java

Mainly there is the bean and its handles.

jpa type safe entityManager calls

testing our jpa daos always worked successful… but i think this was mainly, because we filled during test the data on the database and got the data and tested it in the same transaction. therefore the data might be still stored in cache and never an actuall db call was made… this needs to be analysed and tested in near future… but thats a different blog entry… hopefully…

this blog entry is about the problem, which occures, when the db actuall is called 🙂

We have a GenericDao and all find all calls worked… and we have object based daos… following example, with an random object… lets take Person:

    public List<Person> getPersonByName(final String name) {
        @SuppressWarnings(“unchecked”)
        final List<Person> list = (List<Person>) entityManager
                .createNamedQuery(Person.GET_PERSON_BY_NAME)
                .setParameter(“name”, name)
                .getResultList();
        return list;
    }

This resulted in an exception… dont have the Exception here, but was something with an Object[] missmatch… and something about an non initialitzed EntityManager… the problem was the @SuppressWarnings(“unchecked”): or the warrning, which we just ignored… getResultList() returns a List… and casting List to List<Person> just doesnt work… whats the solution? Simple… just tell the named query, that kind of type it is… so it returns an List<Person> instead of the List…

 .createNamedQuery(Person.GET_PERSON_BY_NAME, Person.class)

and the @SuppressWarnings(“unchecked”) isnt used anymore 🙂