TablaModel tablaModel = new TablaModel(); List listaRoles= tablaModel.getElements("st_roles"); request.setAttribute("roles", listaRoles); return mapping.findForward(cmd); } Type inside list, with get set methods
Here's a guess as to what might be happening: If the Action class you showed us is specified in the action attribute of the <html:form> tag in the JSP that is being displayed, The action is not getting called until the form has already been submitted, so it can't possibly populate the list before the JSP gets displayed. Hence, the JSP can't find the list.
In a case like this, you need two actions: one to prepare to display the JSP, and another to process the JSP once it has been submitted. The logic you've shown us should go in the preparatory action, not the processing action. In the case of the preparatory action, you should call the action URI directly (e.g. myAction.do) and have it forward to the JSP you're showing us.
I may be totally wrong in my guess, but since you haven't shown us your struts-config.xml file or the <html:form> tag of your JSP, there's no way for me to tell. However, I do know that this is a very common error made by folks just getting used to Struts. [ May 14, 2007: Message edited by: Merrill Higginson ]
The action is created to load a list to be iterated after in the jsp.
The intention is to as many checkbox as item are in the list, so I think I don't need nay form now, do I?
posted 13 years ago
The rules of HTML are that any time you have an <input> tag, it must be enclosed in a <form> stanza. The answer to your question, then, is yes, you do need a form. You also need a submit button so that the user can submit the values to the server and have them be read by an action class.
If you want to use Struts custom tags, you should use <html:form> instead of <form>.