cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Ball <>
Subject Re: News site with XSP and SQL. (fwd)
Date Tue, 09 Jan 2001 18:14:07 GMT

---------- Forwarded message ----------
Date: Tue, 9 Jan 2001 00:29:24 -0500 (EST)
From: Donald Ball <>
To: Cocoon-Users <>,
Subject: Re: News site with XSP and SQL.

On Sun, 7 Jan 2001, Christian Parpart wrote:

> Hi,
> my final goal is to create a site where
> people can read news and can give comments.
> The first step is done. You can read the news.
> To create them and display it to the client
> I am using MySQL.
> Now my next step is to modify it in that way,
> that the clients user can add a comment to a
> news entry or add a comment to a taken comment
> from a news entry. Here you're creating a tree
> in SQL. That's not the problem, I think.
> My problem is, to let them working fine with
> XSP a.s.o.
> My database record looks like this:
> table news (
> 	ID		bigint unsigned auto imcrement primary key not null,
> 	ParentID	bigint unsigned not null,
> 	Date		timestamp not null,
> 	Author	varchar(40) not null,
> 	AuthorEMail	varchar(40) not null,
> 	Title		varchar(80) not null,
> 	texttype	tinyint not null,
> 	text		text not null
> );
> ID is the unique identification number of a
> record(news entry or a comment). ParentID is
> either zero, that means it is a news entry,
> otherwise it has the ID from its parent,
> mayby a news entry or a comment.
> This works fine.
> To display all news I can use a simple esql query.
> But how can I use that to display its comments and
> to display the comments of the comments and so on?

as a matter of fact, i think you've stumbled on one of esql's shortcomings
- i don't think you can do recursive queries to an arbitrary depth. that
is to say, you could manually recurse to a fixed depth, but it would be a
pain and look ugly to boot. the real problem is that when doing flow
control using xsp logicsheets, you don't have access to request-time

if you could put xsp elements inside functions, this would be possible,
since then you could make request-time decisions about invoking blocks of
xsp code - but doing that makes you have to pass the local xsp java
variables into the function, which is sort of a headache - and i think,
actually, impossible to do thoroughly since you don't know what variables
other logicsheets will be defining that expressions you must evaluate
depend on. hmm, is there a way to get an array of the variables currently
declared at the current function level in java? i know it's pretty easy to
get at in perl... anyway, here's the idea:

<xsl:template match="xsp:page">
    void showComments(Integer id, Integer parent) throws Exception {
        <xsp:logic>if (id != null) {
          <esql:query><xsp:expr>"select id,title from news where id = "+id</xsp:expr></esql:query>
        } else if (parent != null) {
          <esql:query><xsp:expr>"select id,title from news where parentid = "+parent</xsp:expr></esql:query>
              <id><esql:get-string column="1"/></id>
              <title><esql:get-string column="2"/></title>
              <xsp:logic>showComments(null,new Integer(<esql:get-int column="1"/>));</xsp:logic>
  <xsl:apply-templates select="*|@*"/>


<xsl:template name="news:comments">
  <xsl:variable name="id"><xsl:call-template name="get-nested-string"><xsl:with-param
name="content" select="news:id"/></xsl:call-template></xsl:variable>
  <xsp:logic>showComments(new Integer(<xsl:value-of select="$id"/>));</xsp:logic>

but it's not going to work as is, because the showComments function will
need access to xspCurrentNode, et. al., or their equivalents in c2, not to
mention the esql local variables. any suggestions?

- donald

View raw message