2

I have been tasked with improving the form validation on a page.

The site uses .jsp/bean/struts etc. Currently there is a loop at the top of the page to print errors to the screen:

<nested:iterate id="currentError" property="wizard.errors" type="java.lang.String" indexId="counter">
    <tr>
        <td valign="top" class="wizardErrorText" width="2%">
            &gt;
        </td>
        <td class="wizardErrorText">
            <span errorId="">
                <bean:write name="currentError"/>  
            </span>
        </td>
    </tr>
</nested:iterate>

Now when validation fails I have changed the existing method slightly to indicate the id of the field that has failed validation as well as the error message. I have then set up a similar loop to print the id's of the fields that have failed validation to an area which is read by JavaScript and highlights the fields accordingly.

Rather than having another loop I would like to use the indexId to look up the value in the array and include it in the errorId.

Could anybody advise how to do this please?

I have tried jsp.getProperty and a few other methods but with no luck.

Thanks Gary

Gary
  • 747
  • 3
  • 10
  • 24
  • In *the* array or in *an* array? It doesn't look like currentError is a HashMap, so are the ids in a separate parallel array? – Joseph Erickson Aug 05 '11 at 19:44
  • Yes the ideas are in a parallel array, I was hoping to use the iteration counter from the first array to pick out the corresponding entry in the other table unfortunately wizard.erroredInputs[counter] did not seem to work or any other method I tried. – Gary Aug 08 '11 at 06:36

1 Answers1

1

You should be able to something like this:

<bean:write name="wizard" property="erroredInputs[counter]" />

Or, full example:

<nested:iterate id="currentError" property="wizard.errors" type="java.lang.String" indexId="counter">
    <tr>
        <td valign="top" class="wizardErrorText" width="2%">
            &gt;
        </td>
        <td class="wizardErrorText">
            <span errorId="<bean:write name="wizard" property="erroredInputs[counter]" />">
                <bean:write name="currentError"/>  
            </span>
        </td>
    </tr>
</nested:iterate>

More information can be found here: https://struts.apache.org/1.x/struts-taglib/indexedprops.html

Joseph Erickson
  • 2,304
  • 20
  • 29