JSP: request parameters and XML using EL tags

Discussion in 'Java' started by James Willmore, Dec 14, 2004.

  1. If this isn't the right newsgroup, please be kind when letting me know :)

    I have the following in an XML file:

    ....
    <section name="1">
    <question name="1" required="true">
    Describe what the Nominee did to be considered for an award
    </question>
    </section>
    ....

    And have tried the following in a JSP page

    <%@ page contentType="text/html" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
    ....
    <!-- Section 1 Questions (/form/section[@name='1']) -->
    <table border="0" summary="Section 1">
    <x:forEach select="$doc//*/section[@name='1']/question">
    <x:set var="currentXML" select="string(@name)" />
    <c:set var="current" value="Section ${currentXML}" />
    <tr>
    <td class="onlyCell"><x:eek:ut select="@name" />. (<c:eek:ut value="${current}" />)
    <x:eek:ut select="." />
    </td>
    </tr>
    <tr>
    <td class="onlyCell">
    <textarea cols="78" rows="10" name="<c:eek:ut value="${current}" />"><c:eek:ut value="${param[${current}]}" /></textarea>
    </td>
    </tr>
    </x:forEach>
    </table>
    ....

    The above code doesn't work because it's an invalid EL expression. I want
    to be able to give the value entered back to the user if this required
    section isn't filled in. The idea is this ... if the XML file changes, I
    don't want to go and recode the JSP based upon the changes.

    Is this possible using taglibs or do I need to examine a different way of
    doing this?

    Hopefully, this post makes sense :)

    Jim
    James Willmore, Dec 14, 2004
    #1
    1. Advertising

  2. James Willmore

    Chris Smith Guest

    James Willmore <> wrote:
    > <c:eek:ut value="${param[${current}]}" />


    > The above code doesn't work because it's an invalid EL expression.


    Indeed. You should wrap entire EL expressions in ${...}, but not their
    subexpressions. Hence:

    <c:eek:ut value="${param[current]}" />

    Note that if you're using JSP 2.0, then c:eek:ut is obsolete. You should
    migrate toward just including the EL expression with no tag.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Dec 14, 2004
    #2
    1. Advertising

  3. James Willmore

    Jim Guest

    Works great!

    Can you give a JSP 2.0 example of the code provided -or- direct me to
    where I can find the answer myself ... please.

    Thanks again,

    Jim
    Jim, Dec 15, 2004
    #3
  4. James Willmore

    Jim Guest

    Works great! Thanks.

    Can you show a JSP 2.0 example -or- direct me to a document about
    migrating to JSP 2.0 ... please?

    Jim
    Jim, Dec 15, 2004
    #4
  5. James Willmore

    Chris Smith Guest

    Jim <> wrote:
    > Can you give a JSP 2.0 example of the code provided -or- direct me to
    > where I can find the answer myself ... please.


    Sure. Replace:

    <c:eek:ut value="${param[current]}" />

    with:

    ${param[current]}

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Dec 15, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Nietz
    Replies:
    1
    Views:
    3,436
    VisionSet
    Nov 12, 2003
  2. Kai Grossjohann
    Replies:
    2
    Views:
    789
    Anton Spaans
    Dec 8, 2003
  3. Mike
    Replies:
    3
    Views:
    862
    Michael Borgwardt
    Jan 9, 2004
  4. koslows
    Replies:
    0
    Views:
    523
    koslows
    May 12, 2005
  5. Dave
    Replies:
    0
    Views:
    444
Loading...

Share This Page