Geek
Geek

Reputation: 3329

JSTL in Struts tag

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?

Upvotes: 1

Views: 2624

Answers (2)

GriffeyDog
GriffeyDog

Reputation: 8386

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>

Upvotes: 1

Jonathan
Jonathan

Reputation: 20385

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

Upvotes: 1

Related Questions