7

i m accessing an element in an arraylist. the problem arises as the index of the required element is a variable. can anyone plz help me?

eg <td><c:out value="${PARENT_MODULE[module.moduleId]}"> </c:out></td>

here module.moduleId is a variable.

i have already tried

<c:out value="${PARENT_MODULE[${module.moduleId}]}">

however this gives an error.

org.apache.jasper.JasperException: /WEB-INF/jsp/showModules.jsp(40,20) "${PARENT_MODULE[${module.moduleId}]}" contains invalid expression(s): javax.el.ELException: Error Parsing: ${PARENT_MODULE[${module.moduleId}]}

thanks

2
  • 1
    You don't need to use ${} around module.moduleId, <c:out value="${PARENT_MODULE[module.moduleId]}"> should work. Commented Feb 27, 2013 at 9:11
  • thank you so much! i never tried that.. as i thought that was highly unlikely.. Commented Feb 27, 2013 at 9:26

2 Answers 2

6

As module.moduleId is inside an EL expression, it will be evaluated. So you don't need to enclose it in an additional ${}.

<c:out value="${PARENT_MODULE[module.moduleId]}"> will work.

Sign up to request clarification or add additional context in comments.

Comments

2

Assuming PARENT_MODULE is the alias you gave the array of modules Assuming module is the object and moduleId is an attribute in the module object

try this:

< c:out value="${PARENT_MODULE[num].moduleId}"/>

where num is a number. PARENT_MODULE[num] would return the object module at the "num" position in the array. and after that all you have to do is access the moduleId attribute.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.