Search code examples
javajspjstljsp-tags

Set id attribute of element to jstl variable


<input type = "radio" name = "skillLevel[${status.index}].skillLevelId" id = "skillLevel[${status.index}].skillLevelId" value = "3"/>

For input name attribute the value skillLevel[${status.index} works fine but for id attribute IDE shows error -

Bad value "skillLevel[   ].skillLevelId" for attribute "id" on element "input": An ID must not contain whitespace.

Syntax of id:
An ID consists of at least one character but must not contain any whitespace.

Is there any way. I just want unique id value for input element as the above statement is within loop. On every iteration I want unique id value.


Solution

  • Solved the problem using jsp:element and jsp:attribute tags. Here is the solution :

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