1

I have to check a condition in struts tag and enable or disable the field as follows:

<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>

When I compile I get the following error:

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

If i use the same in an HTML input field it works fine. What is the other option? any inputs?

Jonathan
  • 20,053
  • 6
  • 63
  • 70
Geek
  • 3,187
  • 15
  • 70
  • 115

2 Answers2

1

You can't just place the <c:if> tag within the <html:text> tag declaration. It only supports attributes such as defined here.

That's why there's an error complaining about the <c:if attribute not being valid. It's treating it as if it were another attribute, which doesn't exist. So I think what you're trying in your code is just not possible.

As you mentioned, including the <c:if> in HTML would work fine. I'd expect it would look something like this:

...
<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> 
/>  
...
Jonathan
  • 20,053
  • 6
  • 63
  • 70
1

Move the <c:if> outside the <html:text> like this:

<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>
GriffeyDog
  • 8,186
  • 3
  • 22
  • 34