Struts2 Evaluate if a property exists or its length
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 lik开发者_如何学Pythone 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...
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 your category
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 to getParts()
) that filters out the parts with empty categoryId, and then call <s:iterator value="partsWithId">
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.
<s:iterator value="parts" status="status">
parts[0<s:property value="category.categoryId" />][<s:property value="piezaId" />] = ['<s:property value="descripcion" />', '<s:property value="disponible" />'];
</s:iterator>
精彩评论