user2069471
user2069471

Reputation: 41

Using <c:out> tag to set var in jsp by using the <c:set> tag

Within my jsp in my Struts 1 application I am trying to use the c:set tag to set the variable from my list in the display table.

Each row in the table has a value (100 or 200) that distinguish which user added the entry. I want to display edit/delte only for a certain user(100).

I am trying to set the value and compare it to 100 to determine which rows should have edit/delete.

The problem I am having is that rowUser is not getting assigned a value from my list.

I know the list has values because the table is getting displayed but they are showing all of the rows as if they are not equal to 100.

What I have so far is:

<c:set var="rUser"><c:out value="${myList.rowUser}" /></c:set>
<c:choose>
<c:when test="${rUser == 100}">
<display:column  property="startDate" title="Start Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable"/>
<display:column  property="endDate" title="End Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable" />
<display:column  property="reason" title="Comments" width="17%" sortable="true" headerClass="sortable" />
<display:column media="html" width="17%"><a href="#" onClick="javascript:editEntry('<c:out value="${myList.Id}"/>')">Edit</a></display:column>  
<display:column media="html" width="15%"><a href="#" onClick="javascript:deleteEntry('<c:out value="${myList.Id}"/>')">Delete</a></display:column>
</c:when>

<c:otherwise>
<display:column  property="startDate" title="Start Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable"/>
<display:column  property="endDate" title="End Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable" />
<display:column property="reason" title="Comments" sortable="true"/>
</c:otherwise>
</c:choose>

Any help would be greatly appreciated.

Upvotes: 0

Views: 5689

Answers (1)

JB Nizet
JB Nizet

Reputation: 691805

If you want to assign myList.rowUser to an attribute rUser, simply use

<c:set var="rUser" value="${myList.rowUser}"/>

That said, why use an additional attribute for that, and not directly use myList.rowUser?

<c:when test="${myList.rowUser == 100}">

Finally, the problem is that the display tag computes the columns to display at the first iteration. In the following iterations, it just changes the values displayed in each column. Instead of not displaying the last two columns when the attribute is 200, you should display them but leave them empty. In short, the test should be inside the display:column tag, and not outside:

<display:column ...> if row = 100, display button </display:column>

Upvotes: 1

Related Questions