Announcement Announcement Module
Collapse
No announcement yet.
JSTL question: expression in expression? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSTL question: expression in expression?

    Hi,

    how can I make an expression in an expression?

    I've got something like this:

    Code:
    ...
    <c&#58;set var="CURGEGENSTANDLEHRER" value="LEHRERPRE" />
    <%@ include file="/selectLehrer.jsp" %>
    ...
    selectLehrer.jsp:
    Code:
    <c&#58;forEach var="lehrer" items="$&#123;CURGEGENSTANDLEHRER&#125;" varStatus="status">
    <c&#58;out value="$&#123;lehrer.vorname&#125;" /><c&#58;out value="$&#123;lehrer.
    </c&#58;forEach>
    which gives me an exception that no 'vorname' property is found in object of type String. Actually, the forEach loop is only run through once, because the items are filled only with the String 'LEHRERPRE'. Actually, I want it to be filled with an Collection LEHRERPRE which is in request scope. Therefore, I'd need something like

    items="${${CURGEGENSTAND}}" in order to make it being expressed as
    items="${LEHRERPRE}"

    I appreciate any suggestions and ideas.

    Thanks in advance and kind regards,
    Simon

  • #2
    Unfortunately this is not possible using JSTL .

    You could use JSP fragments/tagfiles and pass those parameters, but you're still stuck with multiple files AFAIK.

    regards,
    Alef Arendsen

    Comment


    • #3
      Ok, thank you. Do you have any ideas for a workaround?

      Thanks,
      Simon

      Comment


      • #4
        You could extend javax.servlet.jsp.jstl.core.LoopTagSupport and make your own tag.

        Comment


        • #5
          I think I am a bit confused. A variable named 'LEHRERPRE' is in request scope and you wish to iterate through this collection? Or do you wish to have the variables 'CURGEGENSTANDLEHRER' and 'LEHRERPRE" share the same reference?


          Keller

          Comment


          • #6
            I wanted to iterate through my LEHRERPRE array, yes.
            However, I left the additional file selectLehrer.jsp now and simply c&p'ed the part from this file.

            Thanks.

            Kind regards,
            Simon

            Comment


            • #7
              And this doesn't work either (using ${} in the value attribute):

              <c:set var="CURGEGENSTANDLEHRER" value="${LEHRERPRE}" />

              Assuming LEHRERPRE is a request attribute.

              If you are doing this:

              <c:set var="CURGEGENSTANDLEHRER" value="LEHRERPRE" />

              What you're experiencing is correct, you are setting CURGEGENSTANDLEHRER to be a string with a value of "LEHRERPRE" since you are not using ${} to signify a variable named LEHRERPRE.

              You can set references in JSTL using the example from above. I'm still not exacly clear on what you are trying to accomplish so I hope this helps alittle.


              Keller

              Comment

              Working...
              X