Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC - How to display blank textbox when integer value is zero

Im using spring, hibernate, java, and jsp. My problem is that when the integer value is zero it displays 0 in my textbox. I want to display only empty string but Idk how to do it. Please help.

In my jsp:

<form:form method="POST" commandName="division">
...
...
    <form:input path="number"/>
</form:form>

In my domain:

/**
 * Get the number of the division.
 * @return The number.
 */
@Column(name = "NUMBER")
public int getNumber() {
    return number;
}

/**
 * Set the number of the division.
 * @param number The division number.
 */
public void setNumber(int number) {
    this.number = number;
}
like image 250
NinjaBoy Avatar asked Jan 15 '13 06:01

NinjaBoy


1 Answers

You will have to use spring:bind for that.

Also, you will have to use JSTL. Import it with:

<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core"%>

In order to get the value for number:

<spring:bind path="number">

The result of the spring:bind is returned in a variable called status, in its value field. Check if it is 0 and print nothing, else print the number:

<core:if test="${status.value != 0}">
    ${status.value}    
</core:if>

For more information, take a look at the spring:bind documentation.

like image 195
Raul Rene Avatar answered Nov 15 '22 08:11

Raul Rene