jsp:根据条件设置元素的属性

vcudknz3  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(319)
<jsp:element name="input">
    <jsp:attribute name="type">radio</jsp:attribute>
    <jsp:attribute name="id">${status.index}${loop.index}</jsp:attribute>
    <jsp:attribute name="name">skillLevel[${status.index}].skillLevelId</jsp:attribute>
    <jsp:attribute name="value">${4 - loop.index}</jsp:attribute>
    <c:if test = "${(4 - loop.index) == skillLevel.getSkillLevelId()}">
        <jsp:attribute name="checked">checked</jsp:attribute>
    </c:if>
</jsp:element>

显示错误c:如果标记不能在jsp:element tag. 我只想根据测试条件为“input”元素添加属性“checked”。

0yycz8jy

0yycz8jy1#

你试过这样吗?

<c:if test = "${(4 - loop.index) == skillLevel.getSkillLevelId()}">
<c:set var="isChecked" value="checked"/>
</c:if>

<jsp:element name="input">
    <jsp:attribute name="type">radio</jsp:attribute>
    <jsp:attribute name="id">${status.index}${loop.index}</jsp:attribute>
    <jsp:attribute name="name">skillLevel[${status.index}].skillLevelId</jsp:attribute>
    <jsp:attribute name="value">${4 - loop.index}</jsp:attribute>
    <jsp:attribute name="${isChecked}">${isChecked}</jsp:attribute>
</jsp:element>

相关问题