I am having a problem using expression language and struts tags together in a struts2 project. The following code snippet from a jsp file illustrates my problem. The fruits object is passed by a servlet. I know that the error is not from the servlet because when I comment out the form code, it correctly prints out each fruit.
<c:forEach var="fruit" items="${fruits}">
<c:out value="${fruit}"/>
<s:form>
<s:checkbox label="${fruit}"></s:checkbox>
</s:form>
</c:forEach>
This doesn't work, and the following error is returned: "According to TLD or attribute directive in tag file, attribute label does not accept any expressions".
What I'm wondering is, is there a way to do this in a similar elegant fashion that doesn't require expression language? I really want to use the struts tags for my jsp page. I've also tried with %{fruit} with no luck.
Best Answer
I suggest reading the docs for the Struts tags more carefully.
Your code is failing because the s:checkbox label doesn't accept expressions. It should be just a plain label something like the following
For your example above the s:checkboxlist may work better. See http://struts.apache.org/2.0.6/docs/checkboxlist.html for more information.