0

我正在尝试禁用文本字段:

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

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

但是文本字段没有被禁用..有什么想法吗?

4

1 回答 1

1

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%>" />
于 2011-02-11T20:43:40.613 回答