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

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


    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:
        <view-state id="fillRegistrationForm" view="registrationForm.jsp" model="profile">
                <binding property="email" required="true" />
                <binding property="password" required="true" />
                <binding property="confirmPassword" required="true" />
                <binding property="gender" required="true" />
                <evaluate expression="countryDictionary.getContent()" 
                    result="viewScope.countries" />
            <transition on="register" to="displayResults"/>
    and in the appropriate view there is the following code fragment:
                                <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
    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 )?


    • #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:

      	private void addModelBindingMappings(DefaultMapper mapper, Set parameterNames, Object model) {
      		Iterator it = binderConfiguration.getBindings().iterator();
      		while (it.hasNext()) {
      			Binding binding = (Binding);
      			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:
      		DefaultMapping mapping = new DefaultMapping(source, target);
      - so the required flag is passed to the mapping from the binding declaration, but in the method addEmptyValueMapping the code looks like below:

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


      • #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, 01:57 PM.


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