2013-10-08 1 views
3

Мне нужно установить переключатель в соответствии с значением, присутствующим в запросе. Ниже приведен код, который я использовал в моем JSPавтоматическая проверка переключателя радиоприемника на основе условия с использованием jstl

<input type="radio" name="status" id="status" value="Active" checked="<c:if test="${posting.postingStatus eq 'Active'}">checked</c:if>"> 
       Active&nbsp; 
<input type="radio" name="status" id="status" value="Closed" checked="<c:if test="${posting.postingStatus eq 'Closed'}">checked</c:if>"> 
       Closed 

Я получаю радиокнопку вместе с текстом «проверено /> Активный» и другая кнопка радио с текстом «проверить /> Closed»

я попытался с помощью другой набор кода

<c:choose> 
    <c:when test="${posting.postingStatus eq 'Active'}"> 
    <input type="radio" name="status" id="status" value="Active" checked="checked"/> 
    Active&nbsp; 
    <input type="radio" name="status" id="status" value="Closed"/> 
    Closed 
    </c:when> 
    <c:otherwise> 
    <input type="radio" name="status" id="status" value="Active" /> 
    Active&nbsp; 
    <input type="radio" name="status" id="status" value="Closed" checked="checked"/> 
    Closed 
    </c:otherwise> 

я получаю двойной раз с неправильным результатом.

Может ли кто-нибудь помочь мне с этим?

ответ

13

Попробуйте так:

<input type="radio" name="status" id="status" 
    value="Active" ${posting.postingStatus=='Active'?'checked':''}> 
+0

спасибо много он работал для меня :) –

+0

+1 для немедленного ответа –

Смежные вопросы