2012-12-12 147 views
1

我要檢查在Struts標籤的條件,並啓用或禁用字段,如下所示:JSTL在Struts標籤

<c:when test="${multipleCase=='true'}"> 
    <html:text property="${row.dataElementJavaName}" 
       maxlength="${row.dataElementSize}" 
       size="60" 
       value="${row.dataElementValue}" 
       onkeyup="javascript:enableSave()" 
       onkeypress="return letternumber(event,'c')" 
       <c:if test="${model.readonlyStatus=='true'}">disabled</c:if> 
    />   
</c:when> 

我編譯時出現以下錯誤:

Attribute: <c:if is not a valid attribute name 
Encountered end tag </c:if> without corresponding start tag. 

如果我在HTML輸入字段中使用它可以正常工作。另一種選擇是什麼?任何投入?

+0

支柱的哪個版本和您使用該版本的JSTL?你還使用哪個servlet api版本? – nwaltham

+0

你想在某些條件下設置屬性disabled = true? – invariant

回答

1

您不能將<c:if>標籤放在<html:text>標籤聲明中。它只支持定義的here等屬性。

這就是爲什麼抱怨<c:if屬性無效的錯誤原因。它把它看作是另一個不存在的屬性。所以我認爲你在代碼中嘗試的東西是不可能的。

正如您所提到的,在HTML中包括<c:if>會正常工作。我希望它會是這個樣子:

... 
<input type="text" name="${row.dataElementJavaName}" 
      maxlength="${row.dataElementSize}" 
      size="60" 
      value="${row.dataElementValue}" 
      onkeyup="javascript:enableSave()" 
      onkeypress="return letternumber(event,'c')" 
      <c:if test="${model.readonlyStatus=='true'}">disabled</c:if> 
/> 
... 
1

移動<c:if><html:text>這樣外:

<c:when test="${multipleCase=='true'}"> 
    <c:if test="${model.readonlyStatus=='true'}"> 
    <html:text property="${row.dataElementJavaName}" 
       maxlength="${row.dataElementSize}" 
       size="60" 
       value="${row.dataElementValue}" 
       onkeyup="javascript:enableSave()" 
       onkeypress="return letternumber(event,'c')" 
       disabled 
    /> 
    </c:if>  
    <c:if test="${model.readonlyStatus!='true'}"> 
    <html:text property="${row.dataElementJavaName}" 
       maxlength="${row.dataElementSize}" 
       size="60" 
       value="${row.dataElementValue}" 
       onkeyup="javascript:enableSave()" 
       onkeypress="return letternumber(event,'c')" 
    /> 
    </c:if>  
</c:when>