tags:

views:

32

answers:

2

Hello,

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&iacute;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...

+1  A: 

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>
no
Thanks, after your good suggestion the array was undefined when accessing it... as it's purpose was to fill another multiselect I took the good way doing it with an extra ajax call..
Garis Suero
A: 

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">

leonbloy
I was trying to avoid the new method... anyhow, i gived up and did it with ajax....
Garis Suero
Anyhow, I was looking for a equivalent method in struts to evaluate if any property is present and it has a value...
Garis Suero