cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <gree...@hotmail.com>
Subject Re: A strange problem
Date Wed, 15 Nov 2000 19:03:39 GMT
"M. Amin" <amin@imkenberg.net> wrote:
>Hi All,
>While i navigate through the articles in my xml file (shown below), i
>encounterd a very strange
>problem (try with it):
>First, when i use GotoNext() function only, the navigation works perfectly
>but, when i use both GotoNext() and GotoPrevious() functions the navigation
>freezes.
>The "current" variable in my code freezes to zero it can't increment nor
>decrement it.
>  why? this question made me a crazy man.
>Do you have any solution to this problem ?

You're doing it wrong. It only works by luck. I'll explain, but I can't 
really see what's going on because you only provided one xml file, but you 
seem to use TWO URLs (ArtWebshop.xml and ArtWebshop2.xml) for the 
navigation. Plus this file would not even compile (see below).

>
>
>/*  My xml file */
>
>
><?xml version="1.0"?>
><?cocoon-process type="xsp"?>
><?cocoon-process type="xslt"?>
><?cocoon-process type="xslt"?>
><?xml-stylesheet href="ArtWebshop.xsl" type="text/xsl"?>
>
><xsp:page
>   language="java"
>   xmlns:xsp="http://www.apache.org/1999/XSP/Core"
> >
>
><xsp:structure>
><xsp:include>com.imkenberg.xml.XmlRecordset</xsp:include>
><xsp:include>com.imkenberg.xml.xmlRecord</xsp:include>
><xsp:include>com.imkenberg.bo.ArticleCondition</xsp:include>
><xsp:include>com.imkenberg.bo.Article</xsp:include>
></xsp:structure>
>
><xsp:logic>

Firstly these variables (whether static or not, that makes no difference) 
are not being used in a thread-safe way. If multiple browsers access your 
page simultaneously, it might not work properly (even if it was correct for 
one-at-a-time access, which it isn't).

If you don't know anything about thread-safety, don't worry, here is a quick 
fix - put synchronized (this) { ... } around all your xsp logic. That will 
always work in XSP pages.

Also note that most of these variables only need to be per-request so could 
be declared as local variables (inside the page root element) instead of 
"permanent" class level variables (outside the page root element). The only 
thing that needs to be remembered between requests is probably the variable 
"current", which could be saved and restored into a session instead of being 
a class level variable.

>     public static int current = 0;
>     public Long articleno = new Long(0);
>     public String shortdesciption = "New Article";
>     public String longname = "New Article";
>     public Float price = new Float(0);
>     public String currency = "DM";
>     public String category = "Undefined";
>
>     XmlRecordset rs = new XmlRecordset();
>
>     public void GotoFirst(){
>       if (rs.size() >= 1)
>       displayArt((com.imkenberg.bo.Article)rs.get(1));
>      }
>
>     public void displayArt(com.imkenberg.bo.Article a){
>     articleno = a.getArticleno();
>     shortdesciption = a.getShortname();
>     longname = a.getLongname();
>     price = a.getPrice();
>     currency = a.getCurrency();
>     category = a.getCategory();
>     }
>
>     public void GotoNext() {
>
>         if(rs.size() > (current+1)){
>          displayArt((com.imkenberg.bo.Article)rs.get(++current));
>
>         }
>
>     }
>    public void GotoPrevious() {
>     if(current >0){
>       displayArticle((com.imkenberg.bo.Article)rs.get(--current));

There is no such method "displayArticle" ! Do you know what Copy and Paste 
means??


>     }
>   }
>
>
></xsp:logic>
>
>
>  <page>
>   <xsp:logic>
>     if ( current == 0 ){
>     rs.Load("/usr/local/jakarta-tomcat/webapps/ROOT/articles.xml");
>     GotoFirst();
>
>     }
>
>     if (session == null ){
>         session = request.getSession(true);
>        }
>
>
>
>   </xsp:logic>
>
>   <Art_info>
>   <Art_no>
>    <xsp:expr>articleno</xsp:expr>
>   </Art_no>
>   <short_desc>
>    <xsp:expr>shortdesciption</xsp:expr>
>   </short_desc>
>   <longname>
>    <xsp:expr>longname</xsp:expr>
>   </longname>
>   <price>
>    <xsp:expr>price</xsp:expr>
>   </price>
>   <currency>
>    <xsp:expr>currency</xsp:expr>
>   </currency>
>   <category>
>    <xsp:expr>category</xsp:expr>
>   </category>
>  </Art_info>
>
>  <Next_Art>
>    <xsp:logic>
>     String next_ref = response.encodeUrl("ArtWebshop.xml");
>
>     <xsp:element name="link">
>      <xsp:attribute name="href">
>       <xsp:expr>next_ref</xsp:expr>
>     </xsp:attribute>
>       Next
>     </xsp:element>

Here you are executing GotoNext, but then below you execute GotoPrevious, 
which has the reverse effect. What you need to say is "WHEN this is clicked 
on, do this", but that's not what you're saying here. Both the GotoNext and 
the GotoPrevious get executed every single request.

>      GotoNext();
>    </xsp:logic>
>  </Next_Art>
>
>  <Prev_Art>
>    <xsp:logic>
>     String prev_ref = response.encodeUrl("ArtWebshop2.xml");
>
>     <xsp:element name="link">
>      <xsp:attribute name="href">
>       <xsp:expr>prev_ref</xsp:expr>
>     </xsp:attribute>
>       Previous
>     </xsp:element>
>      GotoPrevious();
>    </xsp:logic>
>  </Prev_Art>
>   </page>
></xsp:page>

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.


Mime
View raw message