Women in Technology

Hear us Roar



Article:
  JSP 2.0: The New Deal, Part 1
Subject:   Dynamically Build Expressions to Evaluate?
Date:   2004-03-05 11:54:44
From:   sethladd1
Hello,


Thanks for these great articles. Is it possible to evaluate expressions made up of other expressions?


For instance, I have two vars in scope, one bean and one string. The string is the property I want from the bean.


I'd like to do something like this:


${bean.${property}}


Is this possible?


Thanks very much!
Seth

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • Dynamically Build Expressions to Evaluate?
    2004-08-24 10:14:16  amitcbhayani [View]

    Hi Seth,

    I am trying to acchieve what u have said. But I get following error


    /pages/event/causalComponents.jsp(52,12) "${componentRows.${columns}" contains invalid expression(s): javax.servlet.jsp.el.ELException: Encountered "{", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||", "?"]' org.apache.jasper.JasperException: /pages/event/causalComponents.jsp(52,12) "${componentRows.${columns}" contains invalid expression(s): javax.servlet.jsp.el.ELException: Encountered "{", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||", "?"] at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:200) at org.apache.jasper.compiler.JspUtil.validateExpressions(JspUtil.java:596) at


    Any input would be of great help.

    Thanks
    Amit
    • Dynamically Build Expressions to Evaluate?
      2005-06-01 05:22:19  JavaJockey [View]

      Dear All,

      Can anyone answer this for me. I have a similiar problem. I am trying to access form bean properties, e.g. title1, title2 etc by dynamically linking the indexId 'ctr' to the title part. This is having no effect. For instance "report.title1" should return "company" on the screen, instead all I get is "report.title." I have enclosed my code fragment to illustrate. I have based it on various sources including the stuff in this thread, but without sucess. Please help if you can.

      Regards...

      <table width="85%" border="0">
      <tbody>
      <c:set var="style" value="datalightsmall" scope="page" />
      <tr>
      <logic:iterate id="record" property="report" name="reportSearchForm" indexId="ctr" scope ="request">

      <!--c:set var="style" value="datalightsmall" scope="page" /-->
      <c:choose>
      <c:when test= "${(ctr =='1')}">
      <c:set var="value" value="${record.title${[ctr]}}"/>
      <td class="viewcolumntitle" width="20%"> <c:out value="${value}" /></td></c:when>
      <c:otherwise>
      <!-- Do nothing -->
      </c:otherwise></c:choose>
      </logic:iterate>
      </tr>
      </tbody>
      </table>
  • Dynamically Build Expressions to Evaluate?
    2004-04-28 19:26:40  Hans Bergsten | O'Reilly Author [View]

    Sure, you can use the array access operator with variables, similar to JavaScript: ${bean[property]}