Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unterminated C:out Tag on Ternary Operator

I have set a session scope object in my session and I want to add a disabled attribute in one of my button using JSTL Ternary operator.

The getPermission is a map of privileges for the currently login user but I am not sure why I am encountering the error unterminated c:out tag in my JSP when it goes to this JSP.

<button type="button"  id="addButton" 
    <c:out value="${empty sessionScope.voUserInfo.getPermission.ADD_ITEM ? "disabled='disabled'" : ''}"/> >
    ADD
</button>
like image 284
Mark Estrada Avatar asked Feb 27 '23 11:02

Mark Estrada


1 Answers

The first doublequote inside the value is breaking the value too early. You should use singlequotes only to denote strings in EL, not doublequotes. You should use doublequotes only to denote HTML attribute values.

<button id="add" <c:out value="${empty var ? 'disabled="disabled"' : ''}"/>>

(please don't pay attention to the Stackoverflow code syntax highlighter, it doesn't recognize taglibs/EL correctly, the above is legitimately valid)

Or, when you're on JSP 2.0 or newer, you can even just leave that c:out away as long as there's no risk for XSS (which is not the case here since you're printing a server-controlled value).

<button id="add" ${empty var ? 'disabled="disabled"' : ''}>
like image 161
BalusC Avatar answered Mar 07 '23 22:03

BalusC