Rishi
Rishi

Reputation: 15

Encountered illegal body of tag "c:set" tag, given its attributes

Model Class --Cancellation has a set [cancellationDetails]. I want to display the objects of that set in a jsp page.

    public class Cancellation {

    @OneToMany(fetch = FetchType.LAZY, mappedBy="cancellation")
    private Set<cancellationDetails> cancel ;


    public class cancellationDetails {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cancelId", nullable = false)
    private Cancellation cancellation;

Controller

     @RequestMapping(value = "/cancellationRecords", method = RequestMethod.GET)
   public ModelAndView getList() {
    List<Cancellation> cancellationRecords = dataservice.getCancellationRecords();
    return new ModelAndView("master/CancellationRecords_master","cancellationList",cancellationRecords);
}

JSP --> Trying to display the set from the List.

              <c:forEach items="${cancellationList}" var="user">
                    <c:set value ="${cancellationList.cancel}" var="set">

                        <tr>

                            <td><c:out value="${user.cancelId}" /></td>
                            <td><c:out value="${user.merchant.merchant_name}" /></td>
                            <td><c:out value="${user.merchantNBR}" /></td>
                            <td><c:out value="${user.merchant.merchant_status}" /></td>
                            <td><c:out value="${user.merchant.handin_date}" /></td>
                            <td><c:out value="${user.merchant.close_date}" /></td>
                            <td><c:out value="${user.closingReason}" /></td>
            <!--from set--> <td><c:out value="${set.achRejectAmount}"/></td>
                            <td><c:out value="${user.merchant.nsbcagent_id}" /></td>
                            <td><c:out value="${user.merchant.nsbcagent_name}" /></td>
                        </tr>
                        </c:set>
                    </c:forEach>

Error

   Encountered illegal body of tag "c:set" tag, given its attributes.</p><p>181: 

Upvotes: 1

Views: 1965

Answers (2)

DHainzl
DHainzl

Reputation: 1073

The answer of @BalusC is not totally correct. You ARE allowed to have contents in a <c:set>-tag. You are however, not allowed, to have contents in a <c:set>-tag when it already contains the attribute value="". (Which makes sense, as the JSP interpreter does not know what to set when both are present).

This is also the code sample posted by @Rishi: The JSP contains both the value=""-attribute as well as a content in the body of the tag.

I stumbled upon this question because I mixed up var="" and value="" in my JSP:

<c:set value="foo">Hello World</c:set>

It obviously should say var="foo" instead, so be aware of that.

Upvotes: 0

BalusC
BalusC

Reputation: 1108852

Encountered illegal body of tag "c:set" tag, given its attributes.

The error message basically says that the <c:set> tag is not supposed to have a body.

In other words, it's not allowed to have this syntax:

<c:set ...>
    <some />
    <other />
    <tags />
</c:set>

Instead, you need this syntax:

<c:set ... />
<some />
<other />
<tags />

The set variable is just available in later tags in the same scope.

That said, in order to iterate over a collection, you actually need another <c:forEach>. So, instead of <c:out value="${set.achRejectAmount}" /> and that <c:set> you should be doing like this:

<c:forEach items="${user.cancel}" var="cancel">
    <c:out value="${cancel.achRejectAmount}" />
</c:forEach>

Upvotes: 2

Related Questions