Snippet inside of a Snippet

10 views
Skip to first unread message

José María

unread,
Sep 2, 2009, 12:16:59 PM9/2/09
to Lift
Hi.

I've a snippet in one of my HTML files and inside of it I put another
snippet like this:

<lift:myClass1.func>
<lift:myClass2.func2>
Hi
</lift:myClass2.func>
</lift:myClass1.func>

If I do that I get the error:

Error processing snippet myClass2:func2. Reason: Exception During
Snippet Instantiation
XML causing this error:

<lift:myClass2.func2>
Hi
</lift:myClass2.func2>

Following doc I put eager_eval="true" in <lift:myClass1.func> but I
got the same error.

What am I doing wrong?

Best regards.

David Pollak

unread,
Sep 2, 2009, 12:36:48 PM9/2/09
to lif...@googlegroups.com
Please post the source for myClass2
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Ross Mellgren

unread,
Sep 2, 2009, 12:41:35 PM9/2/09
to lif...@googlegroups.com
What does your snippet code look like? It sounds like it's not having
trouble with the nested snippet so much as getting at your snippet code.

-Ross

José María

unread,
Sep 2, 2009, 12:47:52 PM9/2/09
to Lift
I think that I don't understand the flow, maybe the error appears
because PaginaMarca can't
instantiate some value (for example "val id").

Well myClass2 is an invented name, I'll post the real code, but not
all (yes I suppose that the
problem will be in the no-pasted zone :p ):

class PaginaMarca extends BindHelpers {

val id = S.param("id").openOr("-1").toLong


def pagina : Int = try {
S.param("numero").openOr("no es un numero").toInt
} catch {
case nfe : NumberFormatException => 1
}



/*
* Estas son las marcas que queremos mostrar en los banners
*/
def listaMarcas (xhtml : NodeSeq) : NodeSeq = {
var marcas = (162, "giantmicrobes") ::
(178, "thumbthing") ::
(177, "invicta") ::
(181, "leatherman") ::
(149, "hotworks") ::
(179, "surefire") ::
(146, "techtionary") ::
(268, "no_starch_press") ::
Nil

marcas.flatMap( marca => bind("marca",xhtml,
"html" --> <li>
<a href={"/marca/"+ marca._1} title=
{"Buscar productos de " + marca._2}>
<img src={"http://
static.simpleoption.com/imagenes/marcas/nombres/"+marca._2+".png"} alt=
{"Logo de "+marca._2}/>
</a>
</li>))

}

}









On 2 sep, 16:36, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> Please post the source for myClass2
>
>
>
> On Wed, Sep 2, 2009 at 9:16 AM, José María <josemariar...@gmail.com> wrote:
>
> > Hi.
>
> > I've a snippet in one of  my HTML files and inside of it I put another
> > snippet like this:
>
> > <lift:myClass1.func>
> > <lift:myClass2.func2>
> > Hi
> > </lift:myClass2.func>
> > </lift:myClass1.func>
>
> > If I do that I get the error:
>
> > Error processing snippet myClass2:func2.  Reason: Exception During
> > Snippet Instantiation
> >          XML causing this error:
>
> >            <lift:myClass2.func2>
> >           Hi
> >            </lift:myClass2.func2>
>
> > Following doc I put eager_eval="true" in <lift:myClass1.func> but I
> > got the same error.
>
> > What am I doing wrong?
>
> > Best regards.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

José María

unread,
Sep 2, 2009, 12:58:08 PM9/2/09
to Lift
SOLVED

I'd a value that was computed using the val "id", I've turned it to
def and all works
now. As "id" can't be retrieved from URL parameters this val generated
an exception.

I think that the error message is a bit misleading :-/

Thanks!

David Pollak

unread,
Sep 2, 2009, 1:27:43 PM9/2/09
to lif...@googlegroups.com
On Wed, Sep 2, 2009 at 9:47 AM, José María <josema...@gmail.com> wrote:

I think that I don't understand the flow, maybe the error appears
because PaginaMarca can't
instantiate some value (for example "val id").

Yep.  An exception during instantiation of a snippet will result in: Reason: Exception During Snippet Instantiation
 

Well myClass2 is an invented name, I'll post the real code, but not
all (yes I suppose that the
problem will be in the no-pasted zone :p ):

class PaginaMarca extends BindHelpers {

It's a suboptimal thing to extends BindHelpers... a much better construct is:

class PaginaMarca {
  import Helpers._
 

 val id = S.param("id").openOr("-1").toLong

Try:

lazy val id = S.param("id").flatMap(Helpers.asLong) openOr -1L
 


 def pagina : Int =   try {
                   S.param("numero").openOr("no es un numero").toInt
                 } catch {
                   case nfe : NumberFormatException  => 1
                 }

lazy val S.param("numero").flatMap(Helpers.asInt) openOr 1



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890

José María

unread,
Sep 2, 2009, 3:57:54 PM9/2/09
to Lift


On 2 sep, 17:27, David Pollak <feeder.of.the.be...@gmail.com> wrote:
>
> Try:
>
> lazy val id = S.param("id").flatMap(Helpers.asLong) openOr -1L

I get:

Exception occured while processing /marca/162

Message: java.lang.IncompatibleClassChangeError
net.liftweb.util.Full.flatMap(Box.scala:332)
demo.helloworld.snippet.MarcaInfo$$M$1be0ea1b.id(MarcaInfo.scala:23)
demo.helloworld.snippet.MarcaInfo$$A$1be0ea1b.id(<generated>)
demo.helloworld.snippet.MarcaInfo.id(Marca.scala)
demo.helloworld.snippet.MarcaInfo$$M$1be0ea1b.marca(MarcaInfo.scala:
29)
demo.helloworld.snippet.MarcaInfo$$A$1be0ea1b.marca(<generated>)
demo.helloworld.snippet.MarcaInfo.marca(Marca.scala)
demo.helloworld.snippet.MarcaInfo$$M$1be0ea1b.datos(MarcaInfo.scala:
94)
demo.helloworld.snippet.MarcaInfo$$A$1be0ea1b.datos(<generated>)
demo.helloworld.snippet.MarcaInfo.datos(Marca.scala)

Timothy Perrett

unread,
Sep 2, 2009, 4:58:20 PM9/2/09
to lif...@googlegroups.com
Are you using JavaRebel? Try doing a clean before jetty:run

Cheers, Tim

José María

unread,
Sep 2, 2009, 6:55:45 PM9/2/09
to Lift
SOLVED

lazy val id = S.param("id").flatMap(Helpers.asLong) openOr -1L

I changed it to:

lazy val pagina = S.param("numero").openOr("1").toInt

Yes, I'm using JavaRebel

David Pollak

unread,
Sep 2, 2009, 11:16:41 PM9/2/09
to lif...@googlegroups.com
On Wed, Sep 2, 2009 at 3:55 PM, José María <josema...@gmail.com> wrote:

SOLVED

lazy val id = S.param("id").flatMap(Helpers.asLong) openOr -1L

I changed it to:

lazy val pagina = S.param("numero").openOr("1").toInt

This is a bad pattern.  It will lead to an exception is the parameter "numero" cannot be parsed as an Int.  Exceptions should only be encouraged in places where there is an unexpected situation (e.g., your database goes down), not in a situation where you have input that cannot logically be turned into a number.

The reason, as Tim pointed out, that you got the exception was the class changed in a way that JavaRebel couldn't handle.  Just stop JavaRebel, do a "mvn clean install" and restart JavaRebel.
 

Yes, I'm using JavaRebel


On 2 sep, 20:58, Timothy Perrett <timo...@getintheloop.eu> wrote:
> Are you using JavaRebel? Try doing a clean before jetty:run
>
> Cheers, Tim
>
> On 2 Sep 2009, at 20:57, José María wrote:
>
>
>
> > On 2 sep, 17:27, David Pollak <feeder.of.the.be...@gmail.com> wrote:
>
> >> Try:
>
> >> lazy val id = S.param("id").flatMap(Helpers.asLong) openOr -1L
>
> > I get:
>
> > Exception occured while processing /marca/162
>
> > Message: java.lang.IncompatibleClassChangeError
> >    net.liftweb.util.Full.flatMap(Box.scala:332)
> >    demo.helloworld.snippet.MarcaInfo$$M$1be0ea1b.id(MarcaInfo.scala:23)
> >    demo.helloworld.snippet.MarcaInfo$$A$1be0ea1b.id(<generated>)
> >    demo.helloworld.snippet.MarcaInfo.id(Marca.scala)
> >    demo.helloworld.snippet.MarcaInfo$$M$1be0ea1b.marca(MarcaInfo.scala:
> > 29)
> >    demo.helloworld.snippet.MarcaInfo$$A$1be0ea1b.marca(<generated>)
> >    demo.helloworld.snippet.MarcaInfo.marca(Marca.scala)
> >    demo.helloworld.snippet.MarcaInfo$$M$1be0ea1b.datos(MarcaInfo.scala:
> > 94)
> >    demo.helloworld.snippet.MarcaInfo$$A$1be0ea1b.datos(<generated>)
> >    demo.helloworld.snippet.MarcaInfo.datos(Marca.scala)

José María

unread,
Sep 3, 2009, 3:02:45 AM9/3/09
to Lift
Ok, I've run "mvn clean jetty:run" and it works now.

Thanks.

On 3 sep, 03:16, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> Beginning Scalahttp://www.apress.com/book/view/1430219890
Reply all
Reply to author
Forward
0 new messages