Pencils Down

This weblog is about my experiences in software development

Browsing Posts tagged IceFaces

As you may already know icefaces since it’s wrapping faces wrapping jsp wrapping html there is some loss of information, especially when things don’t go well.

In my case I was chasing down why a button click would sometimes work and other times do nothing at all.

After looking at various logging spam you can generate, I started looking into debugging tools in faces.  Desperation sometimes works!  Turns out there is a tag, h:messages, in faces that allows you to dump whatever faces exceptions are currently in the queue.  You just plunk the tag in the same div as the suspected culprit and voila, you get a nice message dump right next to the component.  For example,


<ice:panelGroup>
<ice:panelGroup styleClass="x">
<ice:commandButton id="okButton" type="submit" value="OK"
actionListener="#{z.popupOkButtonAction}" />
</ice:panelGroup>
<h:messages layout="table" showDetail="true" />
</ice:panelGroup>

BTW, in my case I got a list of class cast exception errors.  I had the getter/setter of the selected value of a selectOneItem typed as a SelectItem instead of a String.  Once I saw the errors the fixes were very clear.

I have a screen with a series of commandButton’s. They all should call various action methods back in the controller. Some of the command buttons used images – they worked. Others just had values for the buttons – they did not work.

Adding onclick showed the buttons were working, they just were not calling the actions.

Several misguided google’d references mentioned changing the behavior of the ui callback setting in web.xml. I tried that and it made no difference.

Finally I noticed that I was missing the id attribute on the buttons. Adding different id’s for each of the buttons fixed the problem – the buttons now invoke the methods as expected.

I had thought that icefaces added default id’s where necessary, but there may be a glitch when you have an assortment of fields of the same type.

If you want to have a button to download a file in icefaces you create a button like:

<ice:outputResource id=”printButton”
    resource=”#{controller.print}”
    attachment=”true” label=”Print…” type=”button”
    fileName=”report.pdf” mimeType=”application/pdf” />

and have the backing bean look like:

public Resource getPrint() {
    //assume we have created the PDF and read into a byte stream oStream
    return new ByteArrayResource(oStream.toByteArray());
}

The side-effect is that the backing bean is evaluated constantly which means you keep building the PDF file.

The other problem is if you don’t have anything to download, what do you do.  It turns out to be pretty simple: just return a null.  In that case the button will not even be displayed on the screen!

    if (data.size()==0) return null;

This lovely, intuitive message from icefaces means you are doing something interesting on the page in question.  In our case it was a simple redirect to another page based on state.

The solution is to use the push server from icefaces 1.8.  The servlet changes the mechanism used for communicating with the backend and indirectly fixes the above ‘error’.

The column referenced in the jspx file,

<f:facet name="header">
<ice:commandSortHeader
columnName="DEF"
arrow="true" >
<ice:outputLabel value="D-E-F" />
</ice:commandSortHeader>
</f:facet>

must much the column name in the backing bean,

xtable = new CheckBoxTable();
...
xtable.setColumnNames(new String[] { "ABC", "DEF"});

You must specify a column width for this to work:

... style="width:20px; text-align:center"...

IceFaces Rocks!

No comments

IceFaces is a Java AJAX framework (http://icefaces.org).  Open-source.  Through it’s live connectivity to the DOM on the client ALL interactions are performed in sequence to a back-end supporting beans.

IceFaces has all the built-ins you would expect to be able to build a RIA app.  The best part is it works and even better: the tutorials on the site work!  There are so many open source frameworks out there with very little documentation.  More typically the x.org site supporting your open source framework has limited, theoretical documentation – think of Hibernate or Spring – both excellent frameworks, but very sparse documentation on how to do regular, everyday things.  So, you end up poking around on the network and typically find several leads that are just wrong.

Such a pleasure to use a tool that you don’t have to waste time on redeveloping the wheel every day.