I am using struts2 data model to accept request parameters, if user does not type any value in input element, the corresponding property in model class is set to "", but I want it to be null, not "". here is my code:
class User{
private String userName;
private String userId;
//setter & getter omitted
}
class UserAction extends ActionSupport{
private User user;
//setter & getter omitted
}
in UserAction class, I maybe need do some business validation or something else, I just use statements lik if(user.getUserId() !== null), now this condition returns true even if user doesn't type anything in <input type="text" name="user.userId" />.
maybe I can write like this:if(user.getUserId() != null && !"".equals(user.getUserId())), it is a little tiring and there are many places like this in my code, I want a convenient way to achieve this, does filter can do this? if can is there any exsiting filter or interceptor ?
Thanks.