• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

input tag에 타임리프로 chekced를 넣는 방법

23.01.06 14:26 작성 조회수 1.84k

0


[질문 내용]
안녕하세요 강사님! 강의 잘 듣고 있습니다. 다름이 아니라 타임리프에서 chekced를 표기하는 방법을 알고 싶습니다!

 

html 소스보기 사진

<div class="form-check form-check-inline"> 
<input type="radio" value="ETC" class="form-check-input" id="itemType3" name="itemType" /> 

<label for="itemType3" class="form-check-label" checked="checked" >기타</label> 

</div>

 

소스코드

 <!-- radio button -->
        <div>
            <div>상품 종류</div>
            <div th:each="type : ${itemTypes}" class="form-check form-check-inline">
                <input type="radio" th:field="*{itemType}" th:value="${type.name()}" class="form-check-input"
                       th:checked="${(type.description == '기타')? 'true':'false'}" />
                <label th:for="${#ids.prev('itemType')}" th:text="${type.description}" class="form-check-label" th:checked="${(type.description == '기타')? 'true':'false'}" >
                    BOOK
                </label>
            </div>
        </div>

위처럼 표시했는데 label 태그에는 나오고 input태그에는 나오지가 않습니다 ㅠ 이유가 무엇일까요? 또 thymeleaf로 표기하려면 어떻게 해야할까요?

 

그리고 formController에서 초기값을 설정하는 방법은 직접 해봤습니다! 타임리프에서 조건을 줘서 checked를 주는 방식이 궁금합니다! 감사합니다 ㅎㅎ

답변 1

답변을 작성해보세요.

0

안녕하세요. yj Ryu님

구글에서 thymeleaf checked if true로 검색하시면 원하시는 답을 바로 찾으실 수 있을거에요.

감사합니다.