Gianfranco Gianfranco - 4 months ago 22
Java Question

Select tag error Struts 2

Well, I'm blocked with this, I have a .jsp with 2 forms, one of them is to look for pets according to an id of the customer, and the other is to register a service for one of those pets, so the problem is that when I look for the pets with the following form, which is linked to a PetsAction:

<s:form action="searchPets">
<div class="col-xs-3">
<input type="text" name="customer.id" class="form-ontrol">
</div>
<s:submit/>
</s:form>


I have a problem with a Select Tag, that is loaded by first time with data from the Prepare method of the ServiceAction, when the data from the form "searchPets" come to the .jsp

<s:select list="employees"
name="GrooService.employee.IdEmp"
listKey="IdEmp"
listValue="nameEmp"
cssClass="form-control"
id="GrooList"
/>


This is the error that I get
tag 'select', field 'list', name 'GrooService.employee.IdEmp': The requested list key 'employees' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

So, what should I modify? Is correct if I load the data of the Select Tag from the
PetsAction
too? Should I have just one action for both forms?

Answer

As far as both actions return the same result JSP which contains a select tag and different action classes hold the action method you have to write prepare() in both classes. Otherwise you can use one action class for both actions/methods. The exception is thrown because the list attribute of the s:select tag couldn't be null. You should properly initialize the variable used for the tag before returning a result that has references to that variable.

Comments