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 aps olute <ap...@yahoo.com> on 2002/10/30 17:26:38 UTC

Still Not Getting switching between EL Expression and JSP scripting

Here is what I have:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<jsp:useBean id="Pets"
             class="sun.jdbc.rowset.CachedRowSet"
             scope="session">
<%
  // load database driver
  Class.forName("org.gjt.mm.mysql.Driver");
  // initialize our CachedRowSet bean
  Pets.setUsername("mysqluser");         // example userid
  Pets.setPassword("user1");     // example password
  Pets.setUrl("jdbc:mysql://192.168.0.1:3306/myowndb");
  Pets.setCommand("SELECT name, owner,species, birth from pet");
  Pets.execute();
%>
</jsp:useBean> 
//above will put a bean in the session right? now how to retrieve those with
// JSTL tags?
<table>
 <c:forEach var="pets" items="${sessionScope.Pets}">
    <tr>
     <c:out value="${pets}"/>
    </tr>
  </c:forEach>
</table>

I can not get the tabular column contents from the Bean via <c:out
value="${pets}"/>   
1. First thing is, using <jsp:useBean> the way I did, puts as "Pets" bean in
session scope right? And this is in the JSP script domain not JSTL ?

2. How then do I get to that session variable "Pets" via JSTL? is the
${sessionScope.Pets} in the c:forEach tag not correct? If not please show
me the proper way.

3. and once its in the JSTL, how to iterate this correctly? 

4. Is session the wrong scope? Meaning if the database contents has changed,
the
RowSet will not get updated since a "Pets" bean currently exist in session and
will got retrieve new data until the session expires? Any elaboration on this
is appreciated. 

__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/

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


Re: Still Not Getting switching between EL Expression and JSP scripting

Posted by Shawn Bayern <ba...@essentially.net>.
On Wed, 30 Oct 2002, aps olute wrote:

> May I bother you with specifically which JSTL class API I should use? 

Sure - it's no bother.

> Is it javax.servlet.jsp.jstl.sql?

Yes - that's the package, and ResultSupport is the class.

> But then am back to scripting or java coding and not really using JSTL
> tags?

Right - but JSTL tags aren't meant, in most cases, to be the *only* code
in an application.  They're just meant to be the presentation code.  In
this case, you'd just be setting up some data (e.g., in a listener,
filter, or servlet) for the purposes of presentation.

> Any equivalent tags I can use?

It's possible that something could be added in a future version of JSTL,
but JSTL doesn't have any support for ResultSet at this point.  One
possibility is to add a function that converts a ResultSet to a Result
object (and perhaps also closes the ResultSet).

> Btw, I was looking at your book yesterday and can not find a sample on
> it. The closest one is using <sql:query> tags and then use
> <c:forEach>, but I already have Bean like CachedRowset, am still lost.

Right - I don't cover it because it's not in JSTL.  :)  See, however,
chapter 14 and appendix B for examples of ResultSupport.

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


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


Re: Still Not Getting switching between EL Expression and JSP scripting

Posted by aps olute <ap...@yahoo.com>.
Thank you for the quick response.

--- Shawn Bayern <ba...@essentially.net> wrote:
> On Wed, 30 Oct 2002, aps olute wrote:
> 

snip snip snip
> 
> > 3. and once its in the JSTL, how to iterate this correctly?
> 
> ... however, you'd can't use <c:forEach> to iterate over a RowSet.  You
> can convert a ResultSet to a JSTL Result -- which is iterable via
> <c:forEach> -- by using the JSTL API classes in support of such
> operations.
> 
May I bother you with specifically which JSTL class API I should use? Is it
javax.servlet.jsp.jstl.sql?  But then am back to scripting or java coding and
not really using JSTL tags? Any equivalent tags I can use? Btw, I was looking
at your book yesterday and can not find a sample on it. The closest one is
using <sql:query> tags and then use <c:forEach>, but I already have Bean like
CachedRowset, am still lost.


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/

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


Re: Still Not Getting switching between EL Expression and JSP scripting

Posted by Shawn Bayern <ba...@essentially.net>.
On Wed, 30 Oct 2002, aps olute wrote:

> 1. First thing is, using <jsp:useBean> the way I did, puts as "Pets"
> bean in session scope right? And this is in the JSP script domain not
> JSTL ?

When <jsp:useBean> creates a scripting variable, the variable is always
backed by a scoped attribute.  In this case, the variable is a local
scripting variable and a session-scoped variable.

> 2. How then do I get to that session variable "Pets" via JSTL? is the
> ${sessionScope.Pets} in the c:forEach tag not correct? If not please
> show me the proper way.

You're doing it correctly; ${sessionScope.Pets} is fine...

> 3. and once its in the JSTL, how to iterate this correctly?

... however, you'd can't use <c:forEach> to iterate over a RowSet.  You
can convert a ResultSet to a JSTL Result -- which is iterable via
<c:forEach> -- by using the JSTL API classes in support of such
operations.

> 4. Is session the wrong scope? Meaning if the database contents has
> changed, the RowSet will not get updated since a "Pets" bean currently
> exist in session and will got retrieve new data until the session
> expires? Any elaboration on this is appreciated.

This is a broader question that's hard to answer based on just what you've
shown.  If <jsp:useBean> finds a variable already existing under the name
and scope that you've provided, it will use that variable instead of
installing a new instance of the class you've provided.  Whether the
variable needs to be synchronized or not, and how you should manage its
lifecycle, are questions dependent on your application's overall design.

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


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