0

I have the following code in my JSP:

<c:set var="myBoolean" value="item.lock${myappli.code.value()}"/>
<c:out value="${myBoolean}"/>
<c:out value="${requestScope[myBoolean]}"/>

In item i have several booleans lockCode1, lockCode2, .... so I use the firs line of code to get the string "item.lockCode1", "item.lockCode2". This expression (item.lock${myappli.code.value()}) works fine. I use it to create my checkboxes:

<form:checkbox  path="item.lock${myappli.code.value()}"  value="item.lock${myappli.code.value()}"                                                       />

Now what i would like is to evaluate the value of "item.lockCode1", "item.lockCode2", .... so that i get the value of the boolean lockCodeX.

When i write

<c:out value="${myBoolean}"/>

it displays: item.lockCodeX

I found the third line on stackoverflow :

<c:out value="${requestScope[myBoolean]}"/>

which i hoped would evaluate "item.lockCodeX" and give me 'true' or 'false', that is its value. But it doesnt work. How could i get my expression "item.lockCodeX" to be evaluated to true/false?

Thanks, E.

PS: My ultimate goal is that I want to (des)activate the checkbox according to the value of the boolean item.lockCodeX. So I thought about something like that:

<c:choose>
    <c:when test="here evaluate my expression to true/false">
        <form:checkbox          path="item.lock${myappli.code.value()}"
value="item.lock${myappli.code.value()}" disabled="false"/>
    </c:when>
    <c:otherwise>
        <form:checkbox          path="item.lock${myappli.code.value()}"
value="item.lock${myappli.code.value()}" disabled="true"/>
    </c:otherwise>
</c:choose>

PS2: I cant use a map, the code is like that, I cant change it.

PS3: I have tried to write:

 <c:when test="item.lock${myappli.code.value()}">

and <c:when test="${item.lock${myappli.code.value()}}"> but it doesnt work.

PS4: Here is the relevant lines of the object item:

public class Lot extends BaseEntite {

...

    private Boolean lockBEL;

    private Boolean lockPAR

    private Boolean lockCIA;

    private Boolean lockAFA;

    private Boolean lockLO;
...

In my Controller I get the object from a webservice and I put it in my ModelAttribute searchForm:

searchMetier.getResultsSearch(context, this.formToDemand(searchForm));
EColi
  • 77
  • 1
  • 10
  • From your code, i don't get what type is variables isLockCode1 and lockCode? Is item a collection which contain objects lockCode1, lockCode2, ..., and these objects have boolean fields isLockCode1 or isLockCode2? – drgPP Jan 23 '15 at 13:40
  • @drgPP Item is an object that contains booleans such as lockCode1, item.lockCode2, etc... – EColi Jan 23 '15 at 14:14
  • Can you post the code how you create item object?, and it's class? – drgPP Jan 23 '15 at 14:20
  • @drgPP I edited my original question to put the info you want at the end of it. – EColi Jan 23 '15 at 14:29

1 Answers1

0

What i see from your code is that the line

<c:set var="myBoolean" value="item.lock${myappli.code.value()}"/> gives to you a String value, so you don't really have access to it's Boolean fields. To do so, you need to retrieve in value item Object itself, so you can get the Boolean value as item.lockBEL.value().

I would try as follows:

<c:set var="myItem" value="${item}">

<c:set var="myBoolean" value="${myItem.lockBEL.value()}"

If you want to get lock+(BEL or PAR or ...) when you should use some techniques that EL provides like concatination, some info here. The problem is i'm not very familiar with EL but as i see nobody replies i decided to give a try.

PS: i see that you set your fields as private, so you should provide some public getters to have access to them, may be something like this would work: {$myItem.getLockBEL().value()}

Community
  • 1
  • 1
drgPP
  • 926
  • 2
  • 7
  • 22