Announcement Announcement Module
Collapse
No announcement yet.
Submitting empty field on form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • strbuf
    started a topic Submitting empty field on form

    Submitting empty field on form

    How would I allow some empty field on form submission? What do I need to add on my controller? Because the form would only insert data if all fields weren't empty.

    Thanks in advance

  • katentim
    replied
    Date fields can not be empty.
    Did you specify allowEmpty=true when redistering CustomDateEditor(DateFormat dateFormat, boolean allowEmpty)

    Leave a comment:


  • strbuf
    replied
    Now I know what the problem is. Date fields can not be empty.

    I get this message:
    Code:
    Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'tanggalLahir'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: ""
    Would there be any way to let null value date be inserted?

    Leave a comment:


  • katentim
    replied
    Using spring:bind won't allow me to have empty fields on form submission
    This should work. You might have to post the relevant code to get this sorted out.

    Can I suggest first looking at the sample applications in the Spring distribution, and try submitting empty fields yourself.

    Leave a comment:


  • Colin Yates
    replied
    Why? What exception do you get?

    assume:
    Code:
      class MyForm {
        private String address;
        private String name;
    
        //accessors hidden.
      }
    you can certainly bind on the properties of that form regardless of whether they are null

    Leave a comment:


  • strbuf
    replied
    Say I have two input fields.

    input type="text" name="name"
    and
    input type="text" name="address"

    I want the form still submitted/insert the data eventhough the address field is not filled in/empty. Using spring:bind won't allow me to have empty fields on form submission.

    Leave a comment:


  • Colin Yates
    replied
    yes, I did mean in browsers

    strbuf; I am not sure I get your problem, are you asking whether a form can be partially populated, i.e. only with parameters that are sent?

    For the intellectually challenged amongst us (i.e. me ) can you explain the problem, and the solution you want.

    Leave a comment:


  • katentim
    replied
    So it would be better to get the value with request.getParameter() rather than binding it?
    Probably not if it is an object. I guess your other option is to set the allowFields property accordingly, and do the binding yourself - a bit messy though.

    Leave a comment:


  • katentim
    replied
    Code:
    To get around the horrific flaw in checkbox handling
    I'm sure yatesco means horrific handling by browsers

    This is a problem for all server side handling of checkboxes. You can also override onBindAndValidate:
    Code:
        protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws java.lang.Exception {
            MyObject myObject = (MyObject) command;
            myObject.setLikesSpring(request.getParameter("likesSpringCheckBox") != null);
        }

    Leave a comment:


  • Colin Yates
    replied
    All HTML input types *except for checkboxes* will return an empty string. Is this what you mean?

    To get around the horrific flaw in checkbox handling, you can have a hidden element with "_propertyName" in your form. When spring binds it will intialise to the default values *including primitives* any properties which have a corresponding "_propertyName" parameter.

    HTH.

    Leave a comment:


  • strbuf
    replied
    So it would be better to get the value with request.getParameter() rather than binding it?

    Leave a comment:


  • katentim
    replied
    How would I allow some empty field on form submission?
    Depends what the field is. AFAIK, if it's a primitive you can't if your binding to it. Otherwise you can define it in your property editor. For example, CustomDateEditor has the signature:
    Code:
    CustomDateEditor(DateFormat dateFormat, boolean allowEmpty)

    Leave a comment:

Working...
X