Struts2 评估属性是否存在或其长度
我有这个 JSP,我将属性中的一些值放入 JavaScript 数组...它看起来像这样:
<s:iterator value="parts" status="status">
parts[<s:property value="category.categoryId" />][<s:property value="piezaId" />] = ['<s:property value="descripcion" />', '<s:property value="disponible" />'];
</s:iterator>
但有时,当没有为该部分设置类别时,它看起来
parts[1][460] = ['Vidrio Delantero RH', '1'];
parts[1][463] = ['Vidrio trasero LH', '1'];
parts[1][465] = ['Vidrio Trasero principal', '1'];
parts[1][462] = ['Vidrio trasero RH', '1'];
parts[][512] = ['Volanta', '1'];
parts[10][599] = ['Z de guía', '1'];
parts[1][692] = ['Farol de bumper delantero LH', '1'];
会破坏 JavaScript,在该部分中看起来像 parts[][512]
在 Struts1 中,我有函数 logic:present
,我正在寻找 struts2 中等效/相似的东西...尝试过 < ;s:if test="#category.categoryId.length() > 0">
但它永远不会实现...
任何帮助将不胜感激...
I have this JSP where I'm putting some values from a property to an JavaScript array... it looks just like this:
<s:iterator value="parts" status="status">
parts[<s:property value="category.categoryId" />][<s:property value="piezaId" />] = ['<s:property value="descripcion" />', '<s:property value="disponible" />'];
</s:iterator>
But sometimes when no category is setted for that part it looks like
parts[1][460] = ['Vidrio Delantero RH', '1'];
parts[1][463] = ['Vidrio trasero LH', '1'];
parts[1][465] = ['Vidrio Trasero principal', '1'];
parts[1][462] = ['Vidrio trasero RH', '1'];
parts[][512] = ['Volanta', '1'];
parts[10][599] = ['Z de guía', '1'];
parts[1][692] = ['Farol de bumper delantero LH', '1'];
and that broke the JavaScript, in the part that looks like parts[][512]
In Struts1, I have the function logic:present
, im looking for something equivalent/similar in struts2... Tried <s:if test="#category.categoryId.length() > 0">
but it never comes to true...
Any help will be appreciated...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的空值对应于一个空字符串的
category.categoryId
?还是空值?如果是第一个,那么我会尝试
或在您的category
中添加布尔方法 类
。我宁愿尝试避免使用 struts 标签的复杂逻辑,并将其委托给操作。例如,我会考虑使用一个额外的方法(例如
partsWithId()
替代getParts()
) 来过滤掉类别 ID 为空的部分,然后调用Your empty value corresponds to a
category.categoryId
that is a empty string ? Or a null value? If the first, then I'd try<s:if test="category.categoryId.length() != 0">
or add a boolean method in yourcategory
class<s:if test="category.categoryIdNonEmpty">
.I rather try to avoid complex logic with struts tags, and delegate that to the action. For example, I'd consider an additional method (say,
partsWithId()
alternative togetParts()
) that filters out the parts with empty categoryId, and then call<s:iterator value="partsWithId">
我对 struts2 不太了解,但经过简短的浏览后,我认为您可能需要做更多类似这样的事情:
您有类别 0 吗?如果没有,这里还有另一个选择...这绝对是一个 hack,但它应该可以防止 js 代码被破坏。未分类的内容最终将归入类别 0。
I don't know much about struts2 but after a brief look around I think you might need to do something more like this:
<s:if test="%{#category.categoryId.length() > 0}">
Do you have a category 0? If not, here's another option... It's definitely a hack, but it should keep the js code from breaking. Uncategorized stuff will end up in category 0.