Bug in snippet dispatch?

19 views
Skip to first unread message

Kim Stebel

unread,
Dec 3, 2010, 11:03:38 AM12/3/10
to lif...@googlegroups.com
Hello group,

In my Lift 2.1 application I have a snippet class that used to look like this:

class CourseSnippet {
def listCourses(in:NodeSeq):NodeSeq = { ... }
...
}

It used to work just fine. Now I wanted to refactor it like so:

abstract class AbstractCourseSnippet {
def listCourses(in:NodeSeq):NodeSeq = { ... }
...
}

class CourseSnippet extends AbstractCourseSnippet

But now I get the following error message when I try to access a page
that contains the snippet:

Error processing snippet courseSnippet.listCourses.Reason:Method Not Found
There are possible matching methods (listCourses), but none has
the required signature:

def listCourses(in: NodeSeq): NodeSeq

XML causing this error:

<lift:courseSnippet.listCourses>
<h3><smlt:name></smlt:name></h3>
<smlt:description></smlt:description>
</lift:courseSnippet.listCourses>

It gets weirder... If I change the CourseSnippet class like this it works again:

class CourseSnippet extends AbstractCourseSnippet {
override def listCourses(in:NodeSeq):NodeSeq = super.listCourses(in)
}

So is this a bug or am I doing something wrong?

Donald McLean

unread,
Dec 3, 2010, 11:08:25 AM12/3/10
to lif...@googlegroups.com
I'm new to Lift, so maybe I'm saying something stupid here, however
the class name is "CourseSnippet" and the XML refers to
"courseSnippet" (different capitalization).

Donald

Kim Stebel

unread,
Dec 3, 2010, 11:12:34 AM12/3/10
to lif...@googlegroups.com
The capitalization is fixed automatically by lift. Also, that doesn't
explain the error message or why the third version works.

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
>
>

Daniel Hobi

unread,
Dec 3, 2010, 11:26:34 AM12/3/10
to Lift
just out of curiosity: does it behave the same way if you declare it
as a trait instead of abstract class?


On 3 Dez., 17:12, Kim Stebel <kim.ste...@googlemail.com> wrote:
> The capitalization is fixed automatically by lift. Also, that doesn't
> explain the error message or why the third version works.
>
>
>
> On Fri, Dec 3, 2010 at 5:08 PM, Donald McLean <dmclea...@gmail.com> wrote:
> > I'm new to Lift, so maybe I'm saying something stupid here, however
> > the class name is "CourseSnippet" and the XML refers to
> > "courseSnippet" (different capitalization).
>
> > Donald
>

David Pollak

unread,
Dec 3, 2010, 11:30:56 AM12/3/10
to lif...@googlegroups.com
This is not a bug, but a design decision.

Lift will only dispatch methods by convention (reflection) if the method was declared on the snippet class itself.  I made this decision early in Lift's life because of security concerns around accidentally dispatching to methods.  Some folks, including @HarryH, have disagreed with the decision, but nobody has cared about it enough to actually open a ticket to make this behavior a flag in LiftRules.

You can use DispatchSnippet to give you finer grained control over dispatching.

You'll also note that traits (rather than superclasses) will have their methods dispatched.  This is an artifact of Scala's implementation of traits.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Kim Stebel

unread,
Dec 3, 2010, 11:33:39 AM12/3/10
to lif...@googlegroups.com
Just tried it. If I make it a trait it works. Thanks

Kim Stebel

unread,
Dec 3, 2010, 11:39:15 AM12/3/10
to lif...@googlegroups.com
Thank you for the explanation. I will just use a trait. If I opened a
ticket, it would be for a more helpful error message.
Reply all
Reply to author
Forward
0 new messages