JSP: request parameters and XML using EL tags

J

James Willmore

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
 
C

Chris Smith

James Willmore said:
<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
 
J

Jim

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
 
J

Jim

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
 
C

Chris Smith

Jim said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top