Archive for the ‘Java’ Category

Error Messages in German :-)

Saturday, August 7th, 2010

Something for the german speaking people:

javax.faces.event.MethodExpressionActionListener processAction

SCHWERWIEGEND: Beim Aufrufen des Aktionszielgeräts 'java.lang.NullPointerException'
für Komponente '#{reportingBean.createPdfReport}' wurde 'j_id84' erhalten.

Isn’t it wonderfull to read error messages in your mother tongue? But who does understand what this means??

Besonders schön finde ich das Aktionszielgerät NullPointerException und dass eine ID erhalten wird. Super!

Want to log SQL statements from Hibernate WITH values?

Thursday, August 5th, 2010

If you are fed up with Hibernate’s ? ? ?s, try this:

(needs mysql 5.1)

1) execute

        SET GLOBAL general_log = 'ON';

2) execute

        SET GLOBAL log_output = 'TABLE';

3) take a look at the table mysql.general_log

In general_log you find all processed queries on you database, there with values and not like hibernate prints them to the console.

Import and export MySQL dbs and care about encoding

Thursday, August 5th, 2010

What you have to do is described here: http://www.devcha.com/2008/03/convert-existing-mysql-database-from.html

h:commandButton to cancel sending a form (without validation)

Monday, February 8th, 2010

Sometimes the problem with validators is that you can’t send a cancel button from within a form, because the validator stops processing it. In this case it is usefull to set the button on immediate=”true”, but then the problem might be that the view ist not correctly cleared. To force clearing the view, it is important to navigate with an outcome other than null (”").

    <h:commandButton immediate="true"
        actionListener="#{bean.discardEditing}"
        value="#{msg.action_cancel}" />

In the example “bean.discardEditing” does some cleanup and returns a navigation outcome to navigate to the same screen again, e.g. “revertToEdit”.

See also:

jsf: general error message (e.g. on top of a form)

Monday, February 8th, 2010

To put a general error message on screen, that is shown only if errors occurred (but is not h:messages) use:

facesContext.maximumSeverity

An example:

    <h:panelGroup rendered="#{! empty facesContext.maximumSeverity}">
        <h:outputText styleClass="error" value="Some errors occurred." />
        ...
    </h:panelGroup>

a4j:commandLink and a4j:support problem

Wednesday, January 27th, 2010

Avoid to mix those two up. Do NOT nest them to trigger rerendering, like this:

    <a4j:commandLink ajaxSingle="true" actionListener="#{...}">
        <a4j:support event="onclick" reRender="..." />
    </a4j:commandLink>

It will lead to funky behaviour, sometimes sending the link, sometimes not. If you use a4j:commandLink you do not need a4j:support. Do trigger rerendering from within the commandLink.

    <a4j:commandLink ajaxSingle="true" actionListener="#{...}" reRender="..." />

Using Eclispe behind a proxy

Thursday, November 19th, 2009

this link might be helpful: wiki.eclispe.org

by the way: you don’t need to store your username and password as plain text info in the ini file! For security reasons I think you should leave it out, because Eclipse will ask you for it later.

h:outputText in facelets

Wednesday, August 19th, 2009

With facelets you can omit the h:outputText tags. Instead of

    <h:outputText value="#{msg.editEmployee_name}" />

you can just write

    value="#{msg.editEmployee_name}"

JSF and Enums

Tuesday, July 28th, 2009

Reading on the web, I found a lot of approaches to use Enums with JSF. But to be honest, I found most of them quite overdone. People are working a lot with own converters, et cetera.

But on my try, it went all without that. What I did:

- just refer to the Enum type property in the bean/object

	<h:outputText value="Art des Projekts" />
	<h:selectOneMenu value="#{projectsBean.selectedObject.type}"
		styleClass="inputfield">
		<f:selectItem itemLabel="-- not assigned --" />
		<f:selectItem itemLabel="------------" />
		<f:selectItems	value="#{optionProvider.typeOptions}" />
	</h:selectOneMenu>

- and provide al list of Enum values

	public final List getTypeOptions() {
		List typeOptions = new ArrayList();
		for (ProjectType pt : ProjectType.values()) {
			typeOptions.add(new SelectItem(pt, pt.toString().toLowerCase()));
		}
		return typeOptions;
	}

That’s it – working without any problem.

But now I am wondering, what the reason is, why all the other people make so much effort? Did I miss something? Or is my case just to trivial?

message-bundles with facelets

Thursday, July 23rd, 2009

When using message bundles with facelets first, the texts did not show.

The problem is, that you need to bring the

<f:loadBundle basename="de.your.package.messageBundle.MessageResources" var="msg" />

into the right place.

If you use it inside your .jsp, you must place it inside ><ui:define>. Or you could place it into the template file. (I prefer to place it in the template.)