0

When I run a JSF application every inputText has a '0', so I can not see the placeholder unless I delete the '0'. That is because the atributes in the ManagedBean are int. The atributes that are String don't cause this problem becuase the are initialized like this strName="";

How could I do to solve the problem and not to see the '0' value those inputText? Is there a better solution than creating those atribues String instead of int and casting to int when neccesary?

XHTML

<h:inputText id="num2" label="num2" required="true" size="5" maxlength="5"
             styleClass="#{component.valid ? '' : 'validation-failed'}"
             value="#{sumaManagedBean.number2}" p:placeholder="Number"
                   requiredMessage="Enter a number">  
     <f:validator validatorId="numberValidator" />
    </h:inputText>
    <h:message for="num2" />

ManagedBean

@ManagedBean
@SessionScoped
public class SumaManagedBean implements Serializable
{

    int number2;

    public SumaManagedBean() {
    }



    //Getters and Setters
    public int getNumber2() {
        return number2;
    }

    public void setNumber2(int number2) {
        this.number2 = number2;
    }
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jose
  • 303
  • 4
  • 17
  • 3
    By the way, initializing strings properties to empty string is a bad practice. Don't do that. Keep them default null. An empty string is technically different from null, not only in Java, but also in e.g. SQL databases. – BalusC Jun 08 '15 at 20:22
  • Alter the type, for Integer, in place int, and don't initialize the attribute. – BrTkCa Jun 08 '15 at 23:34

0 Answers0