Reputation: 2830
I have a JSP, here the snippet:
<s:set var="tmpIdObj"
value="form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj"/>
<s:set var="c6"
value="form.datiVersioneQuoteAssegnazione[#tmpIdObj].confermata"/>
I would like to write all in one row, avoiding to create the tmpIdObj variable, as following:
<s:set var="c6"
value="form.datiVersioneQuoteAssegnazione[form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj].confermata"/>
i tried to use singlequotes or other struts sintaxes, but i'm not able to arrange it. I'm looking for the working syntax. Thanks
Upvotes: 0
Views: 350
Reputation:
AN EXAMPLE BEFORE GETTING INSANE :
The given code is too complicated, so I created a bean for testing purpose :
package fr.hbonjour.formulaires.actions;
public class PlaceBean {
private String name;
private String adress;
private Long index;
public PlaceBean()
{
this(null, null, null);
}
public PlaceBean(Long id, String name, String adress)
{
this.setName(name);
this.setAdress(adress);
this.setIndex(id);
}
... (getters and setters)
}
Then I tried this :
<s:bean name="fr.hbonjour.formulaires.actions.PlaceBean" var="bean" />
<s:set var="bean.name" value="places[places[0].index].name" />
<!-- Prompt the name from the created bean -->
<td><s:property value="bean.name"/></td>
places[0].index returns a Long value, and places[places[0].index].name a String value. Here are the values of my list :
0 GABRIEL
1 WU
So places[places[0].index].name= places[0].name = GABRIEL. Indeed the <s:property />
tag displays GABRIEL
.
A more tricky example :
<s:bean name="fr.hbonjour.formulaires.actions.PlaceBean" var="bean" />
<s:iterator status="stat" value="places">
<tr>
<s:set var="bean.name" value="places[places[#stat.index].index].name" />
<td><s:property value="bean.name"/></td>
</tr>
</s:iterator>
So... for #stat.index = 0 for example, places[places[#stat.index].index].name = places[places[0].index].name = places[0].name = GABRIEL. This code returns the following values :
GABRIEL
WU
LET'S CHECK!
form.datiVersioneQuoteAssegnazione[form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj].confermata
We saw that if #k.index
was an iterator index and lista[#k.index].idObj
returned a Long value, lista[#k.index].idObj
worked (places[#stat.index].index
worked in our example).
Wa saw that if lista[#k.index].idObj
returned a Long value, datiVersioneQuoteAssegnazione[lista[#k.index].idObj].confermata
worked (places[places[#stat.index].index].name
worked in our example).
SO ?
I suggest you check step by step, as I did in my example, every value of the expression. Because nobody will be able to exactly re-make you test case. Maybe you should especially check the form.dati.assegnazioniAnnualitaAtto[#qid]
part of the expression. I don't doubt you will manage to find the answer that way.
But anyway, it's soooo ugly. Good luck.
Upvotes: 1
Reputation: 50203
Force OGNL evaluation by using %{}
<s:set var="c6"
value="form.datiVersioneQuoteAssegnazione[%{form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj}].confermata"/>
Copy, paste, run and come back here to post the output:
<div style="border: 5px solid red; width: 100%;">
form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj: [
<s:property value="form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj" />]
form.datiVersioneQuoteAssegnazione[%{form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj}].confermata: [
<s:property value="form.datiVersioneQuoteAssegnazione[%{form.dati.assegnazioniAnnualitaAtto[#qid].lista[#k.index].idObj}].confermata" />]
form.datiVersioneQuoteAssegnazione[form.dati.assegnazioniAnnualitaAtto[%{#qid}].lista[%{#k.index}].idObj].confermata: [
<s:property value="form.datiVersioneQuoteAssegnazione[form.dati.assegnazioniAnnualitaAtto[%{#qid}].lista[%{#k.index}].idObj].confermata" />]
</div>
Upvotes: 0