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…
Your empty value corresponds to a
category.categoryIdthat 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 yourcategoryclass<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">