Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid default long value of 0 to display in h:inputText

Tags:

jsf

jsf-1.2

I have a <h:inputText> which accepts a long value like this

<h:inputText value="#{ServiceTable.ID}" />

The property is declared like this

public class ServiceTable {

    private long ID;

    // Getter and setter for ID.
}

When I open the page, I always see 0 in the textbox. How can I avoid it? I just need an empty textbox. I am using JSF 1.2.

like image 698
Sreeram Avatar asked Sep 20 '11 14:09

Sreeram


2 Answers

Use Long instead of long. It defaults to null.

private Long ID;

And, if you're running Tomcat 6.0.16 or newer or a fork of it, then you need to add the following VM argument to server startup arguments as well to disable EL coercion of primitives and their wrappers:

-Dorg.apache.el.parser.COERCE_TO_ZERO=false
like image 66
BalusC Avatar answered Nov 20 '22 17:11

BalusC


awful! many developers do not have access to the actual server, and sometimes you just cant go to the client and tell him :" stop your server and restart everything with this start up options".

How come people in the apache team never thought about that?

If you are in such situation - like myself - another solution is to get the field as a String and parse it manually in your backing bean.

like image 1
demonz demonz Avatar answered Nov 20 '22 18:11

demonz demonz