Announcement Announcement Module
Collapse
No announcement yet.
Binding on missing field - if no parameter passed back the "required" mark ignored? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding on missing field - if no parameter passed back the "required" mark ignored?

    Hello!

    I have simple flow, which shows the registration page to the user and requires the user to provide information about self, which includes gender.

    the view state looks like below:
    Code:
        <view-state id="fillRegistrationForm" view="registrationForm.jsp" model="profile">
            <binder>
                <binding property="email" required="true" />
                <binding property="password" required="true" />
                <binding property="confirmPassword" required="true" />
                <binding property="gender" required="true" />
            </binder>           
            <on-render>
                <evaluate expression="countryDictionary.getContent()" 
                    result="viewScope.countries" />
            </on-render>            
            <transition on="register" to="displayResults"/>
        </view-state>
    and in the appropriate view there is the following code fragment:
    Code:
                                <p><form:label path="gender" cssErrorClass="errorLabel"> Gender <form:errors path="gender" cssClass="errorLabel" />
                                    <form:radiobutton path="gender" value="MALE"/>MALE
                                    <form:radiobutton path="gender" value="FEMALE"/>FEMALE
                                    </form:label>
                                </p>
    what I can see - if none of these radio buttons is chosen , the binding operation is not performed at all for the gender field (I've checked with the debugger and was surprised), looks like the binding is being performed only for fields which were passed in the request - and since if none of radio buttons is selected - the appropriate parameter name does not exist in the request, so the mapping doesn't perform and thus required mark is simply does nothing - which is weird.

    Is it a bug, or I am missing something?

    Thank you!

  • #2
    I found I can get the desired behavior with providing

    <input type="hidden" name="_gender" value=""/>

    however this is not obvious (I still learned this from the debugging )?

    Comment


    • #3
      Okay, I'll continue talking to myself - may be somebody will find my posts useful later

      I researched the problem and found it is raised in the org.springframework.webflow.mvc.view.AbstractMvcVi ew class.

      there is the method:

      Code:
      	private void addModelBindingMappings(DefaultMapper mapper, Set parameterNames, Object model) {
      		Iterator it = binderConfiguration.getBindings().iterator();
      		while (it.hasNext()) {
      			Binding binding = (Binding) it.next();
      			String parameterName = binding.getProperty();
      			if (parameterNames.contains(parameterName)) {
      				addMapping(mapper, binding, model);
      			} else {
      				if (fieldMarkerPrefix != null && parameterNames.contains(fieldMarkerPrefix + parameterName)) {
      					addEmptyValueMapping(mapper, parameterName, model);
      				}
      			}
      		}
      	}
      in this method the argument names are checked against the names of parameters passed in the request, and if no such name is available - the _parameterName parameter is tried, in case if it exists - the addEmptyValueMapping is called.

      In the method addMapping there are the lines of code:
      Code:
      		DefaultMapping mapping = new DefaultMapping(source, target);
      		mapping.setRequired(binding.getRequired());
      - so the required flag is passed to the mapping from the binding declaration, but in the method addEmptyValueMapping the code looks like below:

      Code:
      			DefaultMapping mapping = new DefaultMapping(source, target);
      			if (logger.isDebugEnabled()) {
      				logger.debug("Adding empty value mapping for parameter '" + field + "'");
      			}
      			mapper.addMapping(mapping);
      so the required attribute is not set, which might lead to confusing behavior.

      Comment


      • #4
        First, thanks for the thread. I've found it useful while investigating the same behavior.

        Second, this seems like a bug. As you say, the workaround is confusing and probably fragile, and required should mean required.

        Edit: Oh, and the workaround can be circumvented since it's client-side.
        Last edited by breaux; Jan 15th, 2013, 02:57 PM.

        Comment


        • #5
          Ah, perhaps there is. Perhaps opened by you?

          https://jira.springsource.org/browse/SPR-5354

          Comment

          Working...
          X