using scriptlet tag inside struts tag
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??
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%>" />
精彩评论