1

I have Struts 2 application.

I have a jsp file which looks like below

<s:form method="post" action="%{#attr.actionType}">

    <c:forEach items="${nvpList2}" var="item">
        <s:textfield label="%{#attr.item.displayName}" 
                     value="%{#attr.item.value}" 
                      name="%{#attr.item.getName()}" 
                        id="%{#attr.item.getName()}"/>
    </c:forEach>

    <s:submit type="button"   cssClass="btn btn-primary" 
               key="button.save" theme="simple" >
        <i class="icon-ok icon-white"></i>
    </s:submit>

</s:form>

As it can be seen that all the elements starting from action name to field names are created dynamically

Problem occurs when I do a validation check on fields. On validation check, the errors are shown but none of the textfields appear in the page.

How do I solve this problem.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Soumya
  • 1,833
  • 5
  • 34
  • 45
  • Errors are shown when you return input result, so before the result listener can repopulate the list. – Roman C Oct 05 '14 at 21:41

1 Answers1

2

Read the detailed workflow of what happens when a validation or conversion error occours;

Once you get what is happening, read How do we repopulate controls when validation fails (prepare() method and other ways);

Then, take a look at which kind of notation (and structures, in complex cases) you need to build to send Lists or Maps from JSP to Action, no matter if static (JSP or HTML) or dynamic (JSP or Javascript);

Finally, I'm not sure why you are using JSTL instead of a Struts Iterator, nor I know the data structure you are sending data to, but pay attention to the need of putting an index in the name (with IteratorStatus.index).

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243