【问题标题】:style attribute inside html:text expression errorhtml中的样式属性:文本表达式错误
【发布时间】:2013-02-28 14:32:47
【问题描述】:

我有以下标签:

<html:text styleClass="span2" property="groupManagerId" styleId="groupManagerId" maxlength="19" size="10" readonly="" />

正常工作。当我添加style 属性时:

<html:text styleClass="span2" style="display:<%=(""+FVConstants.NORMAL).equalsIgnoreCase(groupData.getGroupType())?"none":" "%>;" property="groupManagerId" styleId="groupManagerId" maxlength="19" size="10" readonly="" />

我收到以下错误:

org.apache.jasper.JasperException: /pages/POS0085_group_modify.jsp(95,61) Unterminated &lt;html:text tag

我在labeldiv 标签下具有相同的属性,并且可以正常工作。我改成

 <%String displayValue=(""+FVConstants.NORMAL).equalsIgnoreCase(groupData.getGroupType())?"none":" ";
                                String displayAttr="display:"+displayValue; %>

<html:text styleClass="span2" style="display:<%=displayValue%>" property="groupManagerId" styleId="groupManagerId" maxlength="19" size="10" readonly="" />

它有效。第一次尝试有什么问题?有没有更好的方法来做到这一点?

【问题讨论】:

  • 我上次检查时,&lt;%=(""+FVConstants.NORMAL).equalsIgnoreCase(groupData.getGroupType())?"none":" "%&gt; 不是显示样式的有效 css 值。我认为您的帖子中可能缺少一些背景信息(可能还有标签)。什么处理该代码?
  • 你不能像这样嵌套 scriptlet。更好的方法是设置一个可通过 JSP EL 访问的值,并为 html-el 标签使用最近的容器。
  • @jdwire 正确,但这不是错误所指示的——这是 JSP 标记问题,而不是 CSS 问题。
  • @DaveNewton 我知道这是将在服务器端处理的其他语言,但问题没有提到除 html 之外的任何语言,如果语言是,OP 可能会得到更快的答案在问题和标签之一中说明。感谢您向其他人说明这一点。

标签: java jsp styles struts scriptlet


【解决方案1】:

当初学者尝试使用? 运算符评估字符串时,通常会发生此错误。评估的表达式应该用括号括起来

<html:text styleClass="span2" style="display:<%=((""+FVConstants.NORMAL).equalsIgnoreCase(groupData.getGroupType())?"none":" ")%>;" property="groupManagerId" styleId="groupManagerId" maxlength="19" size="10" readonly="" /> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多