Boa Tarde pessoal estou com um erro no struts que infelizmente não estou conseguindo seleciona-lo por gentileza, se alguem já se encontrou nesta situação e puder me ajudar agradeço!!!
[color=red]ERRO[/color]
exception
javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(Unknown Source)
java.util.ArrayList.get(Unknown Source)
org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:433)
org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:340)
org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:664)
org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:884)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
[color=red]Meu Form[/color]
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import org.apache.struts.util.LabelValueBean;
import org.apache.struts.validator.ValidatorForm;
import br.com.eve.util.ActivityViewMap;
public class ImportActivityForm extends ValidatorForm {
private static final long serialVersionUID = 1L;
private String event;
private String[] act;
private String selected;
private Collection<ActivityForm> activities = new ArrayList<ActivityForm>();
private Collection<LabelValueBean> eventsOpt = new ArrayList<LabelValueBean>();
private LinkedHashMap <String, ActivityForm> map = new ActivityViewMap();
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public Collection<LabelValueBean> getEventsOpt() {
return eventsOpt;
}
public void setEventsOpt(Collection<LabelValueBean> eventsOpt) {
this.eventsOpt = eventsOpt;
}
public Collection<ActivityForm> getActivities() {
return activities;
}
public void setActivities(Collection<ActivityForm> activities) {
this.activities = activities;
}
public String[] getAct() {
return act;
}
public void setAct(String[] act) {
this.act = act;
}
public LinkedHashMap<String, ActivityForm> getMap() {
return map;
}
public void setMap(LinkedHashMap<String, ActivityForm> map) {
this.map = map;
}
public String getSelected() {
return selected;
}
public void setSelected(String selected) {
this.selected = selected;
}
}
[color=red]Meu Action[/color]
public ActionForward getActivities(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
ActivityService service = getActivityService();
ImportActivityForm impForm = (ImportActivityForm) form;
Collection<ActivityForm> activities = new ArrayList<ActivityForm>();
try {
activities = service.getAllActivities(Integer.parseInt(impForm.getEvent()));
if (!activities.isEmpty()) {
for (ActivityForm view : activities) {
impForm.getMap().put(String.valueOf(view.getActivityId()), view);
}
return loadImport(mapping, form, request, response);
} else {
return loadImport(mapping, form, request, response);
}
} catch (NumberFormatException e) {
log.error(e);
e.printStackTrace();
} catch (ServiceOperationException e) {
log.error(e);
e.printStackTrace();
} catch (ConnectionRefusedException e) {
log.error(e);
e.printStackTrace();
} catch (NoEventsFoundException e) {
log.error(e);
e.printStackTrace();
} catch (Exception e) {
log.error(e);
e.printStackTrace();
}
return mapping.findForward(this.FAIL);
}
public ActionForward importActivities(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NoEventInThisSessionException {
event = (Event) request.getSession().getAttribute(this.EVENT_ATTRIBUTE);
ImportActivityForm impActForm = (ImportActivityForm) form;
ActionMessages messages = new ActionMessages();
try {
this.getActivityService().importActivities(impActForm.getAct(), event);
messages.add("success", new ActionMessage("activityForm.imported"));
return mapping.findForward("success");
} catch (ServiceOperationException e) {
log.error(e);
messages.add(this.ERRORS, new ActionMessage("activityForm.register.message.methodException"));
return mapping.findForward(this.FAIL);
} catch (NoEventInThisSessionException e) {
log.error(e);
messages.add(this.ERRORS, new ActionMessage("activityForm.noEvent"));
return mapping.findForward(this.FAIL);
} catch (ConnectionRefusedException e) {
log.error(e);
messages.add(this.ERRORS, new ActionMessage("activityForm.connection.error"));
return mapping.findForward(this.FAIL);
} catch (NoEventsFoundException e) {
log.error(e);
messages.add(this.ERRORS, new ActionMessage("activityForm.noEvent"));
return mapping.findForward(this.FAIL);
} catch (ActivityNameAlreadyUsedException e) {
log.error(e);
messages.add(this.ERRORS, new ActionMessage("activityForm.already.registered"));
return mapping.findForward(this.FAIL);
} catch (Exception e) {
log.error(e.getMessage());
messages = new ActionMessages();
messages.add(this.ERRORS, new ActionMessage("activityForm.register.message.methodException"));
return mapping.findForward(this.FAIL);
} finally {
if (messages != null)
saveMessages(request, messages);
}
}
public ActionForward loadImport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
event = (Event) request.getSession().getAttribute(this.EVENT_ATTRIBUTE);
ImportActivityForm impForm = (ImportActivityForm) form;
Collection<EventForm> events = this.getEventService().getAllEvents();
events = this.getEventService().getAllEvents();
List<LabelValueBean> eveBean = new ArrayList<LabelValueBean>();
for (EventForm eve : events) {
LabelValueBean label = new LabelValueBean(eve.getName(), String.valueOf(eve.getId()));
if (!(eve.getId() == event.getId())) {
eveBean.add(label);
}
}
impForm.setEventsOpt(eveBean);
return mapping.findForward("import");
}
[color=red]Struts-config[/color]
<form-bean type="br.com.eve.form.ImportActivityForm" name="importActivityForm"/>
<action path="/activity/importActivities"
type="br.com.eve.controller.activity.ActivityAction"
name="importActivityForm"
parameter="default=loadImport, filter=getActivities, import=importActivities"
scope="request"
validate="false">
<forward name="success" path="msgLayout"/>
<forward name="fail" path="msgLayout"/>
<forward name="samePage" path="activityLayout"/>
<forward name="import" path="importLayout"/>
<forward name="errors" path="msgLayout"/>
</action>