Sreeram
Sreeram

Reputation: 3258

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

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.

Upvotes: 5

Views: 4643

Answers (2)

demonz demonz
demonz demonz

Reputation: 649

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.

Upvotes: 1

BalusC
BalusC

Reputation: 1108912

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

Upvotes: 8

Related Questions