You can use spring tablib
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
And use conversion markup
<spring:bind path="account.balance">${status.value}</spring:bind>
or
<spring:bind path="account.balance">
<spring:transform value="${account.balance}"/>
</spring:bind>
or
<spring:bind path="account.balance">
<spring:transform value="${otherCommand.anotherBigDecimalProperty}"/>
</spring:bind>
About the value attribute
The value can be a simple value to convert (a hard-coded String value to a JSP or a JSP expression), or an EL JSP expression to evaluate (converting the result of the expression). Like all Spring JSP tags, this tag is able to independently parse EL expressions in any version of JSP.
Its API
Provides conversion of variables to String using the corresponding custom PropertyEditor from BindTag (can only be used inside BindTag)
MultiActionController, Dummy Command :
public class Command {
public BigDecimal bigDecimal;
public Date date;
}
MultiActionController
public class AccountController extends MultiActionController {
@Autowired
private Repository<Account, Integer> accountRepository;
public AccountController() {
setWebBindingInitializer(new WebBindingInitializer() {
public void initBinder(WebDataBinder dataBinder, WebRequest request) {
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, numberFormat, true));
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true));
}
});
}
public ModelAndView(HttpServletRequest request, HttpServletResponse response) throws Exception {
return new ModelAndView()
.addAllObjects(
createBinder(request, new Command())
.getBindingResult().getModel())
.addObject(accountRepository.findById(Integer.valueOf(request.getParameter("accountId"))));
}
}
JSP
<c:if test="{not empty account}">
<spring:bind path="command.bigDecimal">
<spring:transform value="${account.balance}"/>
</spring:bind>
<spring:bind path="command.date">
<spring:transform value="${account.joinedDate}"/>
</spring:bind>
</c:if>
, PropertyEditor, .