You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by James Hazel <jh...@tscnet.com> on 2002/04/01 23:45:43 UTC

jstl sql dataSource configuration help

Hi.

I am a student taking a class in JSP's and my current project is to use the
jstl in a web-app tied into a database.  I believe the problem I am having
derives from getting a datasource.

my jsp code is:
<sql:query var="stuff" dataSource="${dataSource}"
            >SELECT * FROM articles</sql:query>

<c:out value="Query completed.  Rows returned are: " />
<c:out value="$stuff.getSize()" />

I configured the dataSource as a class implementing the javax.sql.DataSource
interface and use it in other places to create the database, but the above
query always returns as if the 'stuff' variable is not initialized: "Query
completed.  Rows returned are:$stuff.getSize()"

I create the dataSource during filter initialization and bind it to the
context using the name "dataSource".  I have been to the tutorial and read
through all the documentation, but apparently missed the answer.

Any help or advice - including where to look - would be greatly appreciated.

TIA,

Jim.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[OFF-TOPIC] Re: jstl sql dataSource configuration help

Posted by Dave Newton <da...@solaraccess.com>.
On Monday 01 April 2002 04:45 pm, James Hazel wrote:
> I am a student taking a class in JSP's and my current project is to use the
> jstl in a web-app tied into a database.  I believe the problem I am having
> derives from getting a datasource.

When I was a kid I took Fortran (and Prime assembly!) and our database was a 
text file and we got our email over a uucp connection.

Hrmmm. Wow.

> <sql:query var="stuff" dataSource="${dataSource}"
>  SELECT * FROM articles</sql:query>
> <c:out value="Query completed.  Rows returned are: " />
> <c:out value="$stuff.getSize()" />

I would have sworn that my code was longer than this, too.

I am occasionally amazed (and somewhat disturbed ;) at all that has happened 
since them thar days of old. Now I'm mostly struggling to keep up with all 
the new APIs, unit testing frameworks, and eXtreme programming tools and 
slowly deciding that I should just paint pictures or play guitar or something.

Oh, everybody kindly send Intel an email reminding them that it's bad karma 
to take Yoga Inside (they teach yoga to incarcerated juvenile delinquents) to 
court claiming trademark dilution.

Dave "Feeling slightly melancholy" Newton

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Question on processing forms with dynamic field names using taglibs

Posted by Lev Pelekh <pe...@digitalroot.com>.
Hello everyone,

I am new, so the usual preemptive apologies are in order. I am attempting to
process a form in which I am constructing field names at runtime. I can't
seem to be able to do that with any of Jakarta Taglibs without resorting to
scriplets. Request taglib seems to have no capability for dynamic parameter
names. JSTL has dynamic parameter names, but the expression language lacks
any kind of string manipulation, including concatenation, thus rendering it
useless for my application.

The answer may be that determining field names at runtime is bad design.
Consider the following example:

A form allows the user to choose from a list of sandwiches. Multiple can be
chosen. For each, the user can check options like lettuce and tomato (man,
sounds good :) ). Thus there's a list with "Select", "Lettuce" and "Tomato"
checkboxes next to each.

The simplest way to process such form, it seems, is to name all "Select"
boxes the same, e.g. "sandIDs", and assign the actual sandID as values.
Lettuce and tomato is named "letuce"+sandID and "tomato"+sandID accordingly.

Thus when processing the form, we can iterate over the values of the field
"sandIDs" to determine which sandwiches were selected, and retrieve
properties of each sandwich via concatenation of the current sandID and
proper suffix (e.g. "tomato").

Pseudocode just in case:

for each foo in parameter "sandID"
	retrieve value of parameter named ("sandID"+foo);

As I have mentioned, I was unable to express pseudocode above neither via
Request Taglib nor JSTL. Any help is highly appreciated.

Lev.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: jstl sql dataSource configuration help

Posted by James Hazel <jh...@tscnet.com>.
Thanks Shawn,

That is apparently not it.  I now get a null pointer exception in the call
to doStartTag().  There is a call just above that ".setParent(null)" so that
may be an indication that my configuration is not quite right.  The last
call recorded in my log is 'getConnection()' so that seems to be completing
(the exceptions are not logged).  I was hoping that there was a more
complete example somewhere which includes the context setup part, but I
guess I need to just keep looking.

Your book should be a valuable resource.  I am looking forward to it.

Jim.

-----Original Message-----
From: Shawn Bayern [mailto:bayern@essentially.net]
Sent: Monday, April 01, 2002 2:07 PM
To: Tag Libraries Users List
Subject: Re: jstl sql dataSource configuration help


On Mon, 1 Apr 2002, James Hazel wrote:

> my jsp code is:
> <sql:query var="stuff" dataSource="${dataSource}"
>             >SELECT * FROM articles</sql:query>
>
> <c:out value="Query completed.  Rows returned are: " />
> <c:out value="$stuff.getSize()" />
>
> I configured the dataSource as a class implementing the
javax.sql.DataSource
> interface and use it in other places to create the database, but the above
> query always returns as if the 'stuff' variable is not initialized: "Query
> completed.  Rows returned are:$stuff.getSize()"

I think you're just using the expression incorrectly.  You want to write

  <c:out value="${stuff.size}" />

instead.

--
Shawn Bayern
Author, "JSP Standard Tag Library"  http://www.jstlbook.com
(coming this summer from Manning Publications)


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jstl sql dataSource configuration help

Posted by Shawn Bayern <ba...@essentially.net>.
On Mon, 1 Apr 2002, James Hazel wrote:

> my jsp code is:
> <sql:query var="stuff" dataSource="${dataSource}"
>             >SELECT * FROM articles</sql:query>
> 
> <c:out value="Query completed.  Rows returned are: " />
> <c:out value="$stuff.getSize()" />
> 
> I configured the dataSource as a class implementing the javax.sql.DataSource
> interface and use it in other places to create the database, but the above
> query always returns as if the 'stuff' variable is not initialized: "Query
> completed.  Rows returned are:$stuff.getSize()"

I think you're just using the expression incorrectly.  You want to write

  <c:out value="${stuff.size}" />

instead.

-- 
Shawn Bayern
Author, "JSP Standard Tag Library"  http://www.jstlbook.com
(coming this summer from Manning Publications)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>