validationjspstruts2struts2-interceptorsinterceptorstack

Struts 2 XML form validation breaks when new element that does not need validation is added


I am facing an issue that is really hard to debug. I have a JSP page that has some form elements on it that submit to a Struts2 action. I also have a XML form validation file to perform some validation on the submitted fields. The file has the naming convention 'actionName-validation.xml'

This works fine, but when I add a drop down box, outside of the form, the validation now fails. Instead it redirects to a blank page and my breakpoint in my action class is not hit.

Is there a way to turn on some kind of debugging or logging for the validation? Why would adding a tag outside of a form cause this to happen?

Here is the code on the JSP page:

<s:select id="dataSource" name="selectedDataSource" theme="simple" listValue="top" 
   headerKey="" headerValue="Choose Data" list="dataSources" size="1" />

<div id="forms">
    <s:form method="post" action="MyAction" theme="simple">
      <p>
          <label class="input" for="name"
          <span style="color:red;">*</span>
          <span>Name</span><br>
          <s:textfield theme="simple" name="name" maxlength="11" size="11" />
          <br>
          <s:fielderror theme="plain"><s:param value="'name'" /</s:fielderror></label>

      </p>    
      <s:submit value="Create New" theme="simple" cssStyle="display: block; clear: left;"/>

    </s:form>
</div>

If I remove the <s:select> tag, it works.

Any help would be greatly appreciated it.

EDIT2: I found the problem. I needed a get method for the list that is used to populate the select drop down inside the action that the form submits to.

I had one for the action that initially is called for the page, but when the validation fails and it re-loads that page from the form action class, it tries to re-populate the select drop down and needs a getter there. I feel silly for not finding that sooner. Would be nice if there were some type of logging or messaging of these types of issues.

thanks.


Solution

  • I found the problem. I needed a get method for the list that is used to populate the select drop down inside the action that the form submits to.

    I had one for the action that initially is called for the page, but when the validation fails and it re-loads that page from the form action class, it tries to re-populate the select drop down and needs a getter there. I feel silly for not finding that sooner. Would be nice if there were some type of logging or messaging of these types of issues.