カスタムタグを作成するためにjstlを使用しています。location.tag の内容は次のとおりです。
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ attribute name="id" required="true" %>
<%@ attribute name="locationType" required="false" %>
<br/>
<c:out value="${param.id}" /> <---THIS ALWAYS PRINTS NOTHING! WHY?
<br/>
<c:out value="${param.locationType}" /> <---THIS ALWAYS PRINTS NOTHING! WHY?
<br/>
<c:if test="${empty param.locationType}" >
<select id="<c:out value="${param.id}" />_locationTypeSelect">
<option value="ADDRESS">כתובת</option>
<option value="INSTITUTE">מוסד</option>
</select>
<script type="text/javascript">
$(document).ready(function() {
$('<c:out value="${param.id}" />_locationTypeSelect').change(function() {
switch($(this).val()) {
case 'ADDRESS':
$('<c:out value="${param.id}" />_addressCitySelect').show();
$('<c:out value="${param.id}" />_addressStreetSelect').show();
$('<c:out value="${param.id}" />_addressHouseNumberInput').show();
$('<c:out value="${param.id}" />_instituteNameSelect').hide();
$('<c:out value="${param.id}" />_instituteBranchSelect').hide();
break;
case 'INSTITUTE':
$('<c:out value="${param.id}" />_addressCitySelect').hide();
$('<c:out value="${param.id}" />_addressStreetSelect').hide();
$('<c:out value="${param.id}" />_addressHouseNumberInput').hide();
$('<c:out value="${param.id}" />_instituteNameSelect').show();
$('<c:out value="${param.id}" />_instituteBranchSelect').show();
break;
}
});
});
</script>
</c:if>
<c:if test="${empty param.locationType or param.locationType == 'ADDRESS'}" >
<select id="<c:out value="${param.id}" />_addressCitySelect"></select>
<select id="<c:out value="${param.id}" />_addressStreetSelect"></select>
<input type="text" id="<c:out value="${param.id}" />_addressHouseNumberInput"/>
</c:if>
<c:if test="${empty param.locationType or param.locationType == 'INSTITUTE'}" >
<select id="<c:out value="${param.id}" />_instituteNameSelect"></select>
<select id="<c:out value="${param.id}" />_instituteBranchSelect"></select>
</c:if>
ここでは location タグを使用しています。
<h:location id="a" locationType="ADDRESS"></h:location>
<h:location id="b"></h:location>
- 何らかの理由で、要素の生成された ID にプレフィックスがありません
<c:out value="${param.id}" />
。たとえば、location.tag に書き<input type="text" id="<c:out value="${param.id}" />_addressHouseNumberInput"/>
ましたが、両方の使用法の結果は:<input type="text" id="_addressHouseNumberInput"/>
(無視されc:out
ます。何が問題なのですか? - どちらの使用法でも、パラメータ locationType を認識しない場合と同様に、html の結果は同じです。何故ですか?
- ここには多くのコードの重複があります。たとえば、すべての id プレフィックス:
<c:out value="${param.id}" />
. コード量を減らす方法はありますか?