You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2003/05/13 20:15:34 UTC

DO NOT REPLY [Bug 19901] New: - Validator can't handle null page value in DynaValidatorForm

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19901>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19901

Validator can't handle null page value in DynaValidatorForm

           Summary: Validator can't handle null page value in
                    DynaValidatorForm
           Product: Struts
           Version: Unknown
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Validator Framework
        AssignedTo: struts-dev@jakarta.apache.org
        ReportedBy: lquijano@hotpop.com


If I define a form like this:

<form-bean name="aForm" type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="page" type="java.lang.Integer" />
    ...
</form>

And I define this param in web.xml:
<init-param>
    <param-name>convertNull</param-name>
    <param-value>1</param-value>
</init-param>

The validator throws a NPE while validating the bean. In DynaValidatorForm:

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
        // set the page variable before validating
        Map props = this.getMap();
        if (props.containsKey("page")) {
            this.page = ((Integer) props.get("page")).intValue();
        }
        ...
    }

So, it gets the "page" property from props. If it's null, they it throws an
exception. I know I could set "initial-property" to something else, but the
behavior of validate confuses the user/developer with a misterious NPE. 

So, two possibilities:
1) Treat null as 0. So, it'd be like this:
        if (props.containsKey("page")) {
            Integer pg = (Integer) props.get("page");
            this.page = (pg == null ? 0 : pg.intValue());
        }

2) Throw a validation exception with something like "page property required". Or
use ActionErrors to report this error. 

So, what's the best way? I personally prefer 1) :)

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org