using scriptlet tag inside struts tag

2.2k views Asked by At

i am trying to disable a text field:

<html:text property="firstName" style="width: 100px;">  
                        <%=isDisabled%>
                        </html:text>

String isDisabled = "";
if (x == null || x.equals("")) {     
     isDisabled = "disabled='true'";

But the text field is not getting disabled.. Any idea??

1

There are 1 answers

0
AudioBubble On

This is quite easy to do. First you determine if the textbox will be disabled or not (this must be a string with true/false value, not disabled='true' as you were trying to do):

String isDisabled = String.valueOf(x == null || "".equals(x));

And then you disable the field:

<html:text property="firstName" style="width: 100px;" disabled="<%=isDisabled%>" />

See here for more documentation.

I don't remember exactly but I think you can also use a boolean directly:

boolean isDisabled = (x == null || "".equals(x));
<html:text property="firstName" style="width: 100px;" disabled="<%=isDisabled%>" />