Search code examples
javastruts2ognl

In struts, How can I receive null for Boolean?


e.g.

class TestAction
{
    @Getter @Setter
    Boolean enabled;// null for both
}

HTML

<input type='radio' name="enabled" value='true'> enabled
<input type='radio' name="enabled" value='false'> disabled
<input type='radio' name="enabled" value='null'> both
<!-- value=null will convert to false -->

How can I pass null for Boolean ?

UPDATE

Answer is impossible. I use another way below.


Solution

  • My way to around this.

    @Data // Generate all setter and getter.
    public class UserSearchCondition implements ISearchCondition
    {
        private String enabled = null;
    
        public Boolean isEnabled()
        {
            if (Strings.isNullOrEmpty(enabled) || enabled.toLowerCase().equals("null"))
                return null;
            return Boolean.valueOf(enabled);
        }
    }