[Lift] Re: Creating a project

2009-07-03 Thread g-man

I have been working on a project for a while, so I haven't needed to
use it, but I found this in my collection of .bat files:

cd C:\Liftweb
mvn archetype:generate -DarchetypeCatalog=http://scala-tools.org/

... that way, you get a bunch of choices during the creation process,
as I recall.

Yes, Lift is young, and is in more of the 'for programmers' phase than
the 'for everyone' phase as far as books and instructional websites
go, but things are moving fast!

Try it out and see what you can create, then report back with what you
have learned, as many here do...


On Jul 3, 4:00 pm, Douglas Quaid  wrote:
> I heard some good vibes about Lift and then I saw this gem in the
> "Getting Started" documentation for creating a project:
>
>  From a command prompt, type:
>
> mvn archetype:generate -U \
> -DarchetypeGroupId=net.liftweb \
> -DarchetypeArtifactId=lift-archetype-basic \
> -DarchetypeVersion=1.0 \
> -DremoteRepositories=http://scala-tools.org/repo-releases\
> -DgroupId=com.liftworkshop \
> -DartifactId=todo \
> -Dversion=0.1-SNAPSHOT
>
> Perhaps you guys could "innovate" and wrap this crap (rhyme!) in a
> shell script.
>
> Good day!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Some help persisting MetaMapper

2009-07-03 Thread glenn

I'm trying to do something like:

override def afterSave = addAfterSave _ :: Nil

  private def addAfterSave(c: Content) {
 
}
  }

and assume afterSave automatically gets called after saving  a mapper
entity. But it never does.

What could I be missing or doing wrong?





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



[Lift] Creating a project

2009-07-03 Thread Douglas Quaid

I heard some good vibes about Lift and then I saw this gem in the
"Getting Started" documentation for creating a project:

 From a command prompt, type:

mvn archetype:generate -U \
-DarchetypeGroupId=net.liftweb \
-DarchetypeArtifactId=lift-archetype-basic \
-DarchetypeVersion=1.0 \
-DremoteRepositories=http://scala-tools.org/repo-releases \
-DgroupId=com.liftworkshop \
-DartifactId=todo \
-Dversion=0.1-SNAPSHOT

Perhaps you guys could "innovate" and wrap this crap (rhyme!) in a
shell script.

Good day!

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



[Lift] using file-based data storage in Lift app

2009-07-03 Thread glenn

I've searched this group and combed through the lift book for an
answer, but found none - how to use file-based storage for data within
Lift.

For example, how would I call something like:

def xml = XML.loadFile()

without getting a java.io.FileNotFoundException?

I tried storing the files in a directory under webapp, and even
included the directory in the resource path in Boot.scala, like so:

ResourceServer.allow({
  case "contents" :: _ => true

})

But that doesn't work.

Any help would be appreciated.

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



[Lift] Re: Unique constraint

2009-07-03 Thread Naftoli Gugenhem

The console is basically a text box for executing SQL. But how can I tell if my 
IDs are PKs? I inserted some rows exported from MySQL containing ids and ended 
up with a duplicate id of something I already had. So what went wrong? Lift 
generated the tables from my Mapper.

-
Tim Nelson wrote:

H2 has a great console servlet that you can use to connect to any jdbc
compliant database and I just figured out how to configure it to work with
lift.

Assuming you already have H2 as a dependency, just add a mapping to the
servlet in your web.xml. Mine looks like this:



  
LiftFilter
Lift Filter
The Filter that intercepts lift calls
net.liftweb.http.LiftFilter
  

  
LiftFilter
/*
  

  
H2Console
org.h2.server.web.WebServlet
1
  
  
H2Console
/console/*
  



Then you need to add a rule to LiftRules.liftRequest using the following
line in boot:

LiftRules.liftRequest.append({case r if (r.path.partPath match {case
"console" :: _ => true case _ => false}) => false})

That basically allows all requests that start with "console" to be ignored
by lift and passed thru to the servlet.

I am actually using PostgreSQL, but I prefer using this to pgAdmin or other
SQL tools.

Tim


On Fri, Jul 3, 2009 at 3:25 PM, Naftoli Gugenheim wrote:

> Okay. What about two fields in a unique constraint, e.g. first+last?Also,
> my H2 databased generated by schemifying allowed me to insert rows that had
> duplicate primary keys (or at least they're supposed to be primary keys).
> I'm using LongKeyedMapper ... with IdPK. Am I missing something?
> Anyone know how to read constraints in H2, meaning get it to to tell me
> what constraints/indexes exists?
> Thanks!
>
>
> On Thu, Jul 2, 2009 at 9:50 AM, Calen Pennington <
> calen.penning...@gmail.com> wrote:
>
>>
>> I actually had the same question last night. I didn't see the
>> valUnique on mapped string. However, it seems like a better way to do
>> this would be to change the Schemifier::ensureIndexes (line 260 in
>> Schemifier.scala) to do "CREATE UNIQUE INDEX" on request. Is there a
>> known reason why this is hard, or is it just that no one has taken the
>> time to do it yet? If it's the latter (and if I can figure out what's
>> going wrong with my attempts to build lift from source), I hope to
>> take a stab at it in the next day or two.
>>
>> -Cale
>>
>> On Thu, Jul 2, 2009 at 7:21 AM, Joe Wass wrote:
>> >
>> > Yes for MappedString, valUnique .
>> >
>> >
>> http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/MappedString.html
>> >
>> > Joe
>> >
>> >
>> >
>> > On Jul 2, 7:55 am, Naftoli Gugenhem  wrote:
>> >> Does lift have any way to specify a unique constraint on a field, via
>> schemify (or validation)?
>> >> If not, how complex would it be to implement?
>> >
>> > >
>> >
>>
>>
>>
>
> >
>



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



[Lift] Re: Unique constraint

2009-07-03 Thread Tim Nelson
H2 has a great console servlet that you can use to connect to any jdbc
compliant database and I just figured out how to configure it to work with
lift.

Assuming you already have H2 as a dependency, just add a mapping to the
servlet in your web.xml. Mine looks like this:



  
LiftFilter
Lift Filter
The Filter that intercepts lift calls
net.liftweb.http.LiftFilter
  

  
LiftFilter
/*
  

  
H2Console
org.h2.server.web.WebServlet
1
  
  
H2Console
/console/*
  



Then you need to add a rule to LiftRules.liftRequest using the following
line in boot:

LiftRules.liftRequest.append({case r if (r.path.partPath match {case
"console" :: _ => true case _ => false}) => false})

That basically allows all requests that start with "console" to be ignored
by lift and passed thru to the servlet.

I am actually using PostgreSQL, but I prefer using this to pgAdmin or other
SQL tools.

Tim


On Fri, Jul 3, 2009 at 3:25 PM, Naftoli Gugenheim wrote:

> Okay. What about two fields in a unique constraint, e.g. first+last?Also,
> my H2 databased generated by schemifying allowed me to insert rows that had
> duplicate primary keys (or at least they're supposed to be primary keys).
> I'm using LongKeyedMapper ... with IdPK. Am I missing something?
> Anyone know how to read constraints in H2, meaning get it to to tell me
> what constraints/indexes exists?
> Thanks!
>
>
> On Thu, Jul 2, 2009 at 9:50 AM, Calen Pennington <
> calen.penning...@gmail.com> wrote:
>
>>
>> I actually had the same question last night. I didn't see the
>> valUnique on mapped string. However, it seems like a better way to do
>> this would be to change the Schemifier::ensureIndexes (line 260 in
>> Schemifier.scala) to do "CREATE UNIQUE INDEX" on request. Is there a
>> known reason why this is hard, or is it just that no one has taken the
>> time to do it yet? If it's the latter (and if I can figure out what's
>> going wrong with my attempts to build lift from source), I hope to
>> take a stab at it in the next day or two.
>>
>> -Cale
>>
>> On Thu, Jul 2, 2009 at 7:21 AM, Joe Wass wrote:
>> >
>> > Yes for MappedString, valUnique .
>> >
>> >
>> http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/MappedString.html
>> >
>> > Joe
>> >
>> >
>> >
>> > On Jul 2, 7:55 am, Naftoli Gugenhem  wrote:
>> >> Does lift have any way to specify a unique constraint on a field, via
>> schemify (or validation)?
>> >> If not, how complex would it be to implement?
>> >
>> > >
>> >
>>
>>
>>
>
> >
>

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



[Lift] Re: can a Snippet call a Snippet?

2009-07-03 Thread Derek Chen-Becker
Yes, it's available on the APress website. It was omitted due to an issue
with the APress workflow :(

http://www.apress.com/book/view/1430224215

Derek

On Fri, Jul 3, 2009 at 8:22 AM, Alexander Azarov  wrote:

>
> I vote for this! Personally I do not completely understand all the
> possibilities Failure gives and how to achieve these. BTW, I found
> recently the appendix about Boxes disappeared from the printed Lift
> book :(
>
> On Jul 2, 5:55 pm, Timothy Perrett  wrote:
> > We really ought to get around to writing a ³guides for boxes² - its
> easily
> > one of the most confusing concepts in lift (a magnitude less
> confusing
> > than when it was called Can[T])
> >
> > Cheers, Tim
> >
> > On 02/07/2009 14:46, "David Pollak" 
> wrote:
> >
> >
> >
> >
> >
> > > On Wed, Jul 1, 2009 at 10:43 PM, g-man  wrote:
> >
> > >> I'm getting a Null Pointer: 'Trying to open an empty box', from S.attr
> > >> ("todos").open_!
> >
> > > Don't use open_!  It's dangerous.
> >
> > > That's why Boxes exist.  They contain (or don't) something that may or
> may not
> > > exist.  If you use open_! in your code, it is a major mistake (a logic
> error)
> > > unless the line before the open contains "if (thing.isDefined) {"
> >
> > > Thanks,
> >
> > > David
> > >
> >
> > >> Here's my layout:
> >
> > >> todo.html template 
> >
> > >> 
> > >> --- Todo list table stuff ---
> > >> 
> > >> --- Tag list table stuff (where the selection to filter comes from)
> > >> ---
> >
> > >> TD.scala snippet =
> >
> > >> // this arity is for the default 'show all Todos' condition
> > >> def list(html: NodeSeq) = {
> > >> val id = S.attr("todos").open_!
> >
> > >> // this arity is for the 'filter by Tag' case
> > >> def list(filterTag: Long)(html: NodeSeq) = {
> > >> val id = S.attr("todos").open_!
> >
> > >> The two snippet methods could probably be combined with a (param:
> > >> Long*) signature, but Scala does not seem to care right now. The
> > >> default works perfectly, but when a Tag is selected to filter by, the
> > >> 'todos' id Box cannot be seen when attempting to open.
> >
> > >> Is this because it is probably out of scope? I am using an ajaxbutton
> > >> to make the call and pass in the tag.id  , but it is
> hard to
> > >> see how an
> > >> S.attr could exist for one request, then be gone for the next, unless
> > >> I am confusing this with a stateful attribute.
> >
> > >> On Jul 1, 2:42 pm, David Pollak 
> wrote:
> > >>> > On Wed, Jul 1, 2009 at 2:28 PM, g-man  wrote:
> >
> >  > > I will look into the nested snippets.
> >
> >  > > For expediency, I folded all the snippets that interact with my
> >  > > template into one file, so I can concentrate on the business
> logic.
> >
> >  > > For my Todo app enhancement, I need to pass the id of my
> selected Tag
> >  > > (which I have confirmed is correctly gathered from the page
> request)
> >  > > in to the TD.list method, so that the filtered Todos (those
> bearing
> >  > > the required Tag) will be found and rendered.
> >
> >  > > My problem is that if I try to pass an additional argument
> (tagId:
> >  > > Long), the TD.list method is not happy and will not even render
> the
> >  > > template.
> >
> >  > > I have tried both paired (html: NodeSeq, tagId: Long) as well as
> >  > > curried style (html: NodeSeq)(tagId: Long), but neither works.
> >
> > >>> > Try:
> >
> > >>> > list(tagId: Long)(html: NodeSeq): NodeSeq
> >
> > >>> > That way list(44L) _ becomes a NodeSeq => NodeSeq
> >
> >  > > There must be a simple way to accomplish such a common task!
> >
> >  > > Thanks to all the members for commenting...
> >
> >  > > On Jun 29, 11:25 pm, "marius d." 
> wrote:
> > > > > > Or you can use S.locateMappedSnippet ... but first try to see
> if
> > > > > > nested snippet won't do the trick for you ...
> >
> > > > > > On Jun 30, 10:17 am, "marius d." 
> wrote:
> >
> > >> > > > > Can you paste some code?
> >
> > >> > > > > Essentially we support nested snippets so your snippet can
> simply
> > >> > > > > return a markup containing another snippet and it will be
> > >> invoked. If
> > >> > > > > you really want to manually invoke a snippet from another
> snippet
> > and
> > >> > > > > if you are not using StatefulSnippets you can just
> instantiate
> > the
> > >> > > > > class and call your function and pass it the right
> NodeSeq.
> >
> > >> > > > > Br's,
> > >> > > > > Marius
> >
> > >> > > > > On Jun 30, 5:36 am, g-man  wrote:
> >
> > >>> > > > > > I am enhancing the Todo app by adding tags.
> >
> > >>> > > > > > I have retained the TD.scala snippet to manage the
> Todos on my
> > page,
> > >>> > > > > > and added a TG.scala snippet to handle tags on the same
> page,
> > which
> > >>> > > > > > works well for creating new and listing in both cases.
> >
> > >>> > > > > > Now I want to filter my Todos list by a

[Lift] Re: Unique constraint

2009-07-03 Thread Naftoli Gugenheim
Okay. What about two fields in a unique constraint, e.g. first+last?Also, my
H2 databased generated by schemifying allowed me to insert rows that had
duplicate primary keys (or at least they're supposed to be primary keys).
I'm using LongKeyedMapper ... with IdPK. Am I missing something?
Anyone know how to read constraints in H2, meaning get it to to tell me what
constraints/indexes exists?
Thanks!


On Thu, Jul 2, 2009 at 9:50 AM, Calen Pennington  wrote:

>
> I actually had the same question last night. I didn't see the
> valUnique on mapped string. However, it seems like a better way to do
> this would be to change the Schemifier::ensureIndexes (line 260 in
> Schemifier.scala) to do "CREATE UNIQUE INDEX" on request. Is there a
> known reason why this is hard, or is it just that no one has taken the
> time to do it yet? If it's the latter (and if I can figure out what's
> going wrong with my attempts to build lift from source), I hope to
> take a stab at it in the next day or two.
>
> -Cale
>
> On Thu, Jul 2, 2009 at 7:21 AM, Joe Wass wrote:
> >
> > Yes for MappedString, valUnique .
> >
> >
> http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/MappedString.html
> >
> > Joe
> >
> >
> >
> > On Jul 2, 7:55 am, Naftoli Gugenhem  wrote:
> >> Does lift have any way to specify a unique constraint on a field, via
> schemify (or validation)?
> >> If not, how complex would it be to implement?
> >
> > >
> >
>
> >
>

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



[Lift] link to self

2009-07-03 Thread Naftoli Gugenheim
Is there a way to write (statefulSnippet/SHtml) .link( currentPage,
()=>onReloadFunc, ns) ?In other words, link to whatever page the link is
appearing on --- a reload link.

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



[Lift] Re: How to test/TDD lift apps?

2009-07-03 Thread Kris Nuttycombe

Hi, David,

Thanks for taking some time to look at this problem. I'm a little
concerned about the approach, though - should Lift really behave
significantly differently in test mode than it does in production
mode? This seems like it would lend to the possibility of subtle bugs
that don't show up until one is in production.

With respect to unit testing, Lift's singletons depend upon underlying
thread-local variables (via ThreadGlobal) to maintain state. I'm just
musing here, but do you think it might be possible to inject a layer
of indirection between Lift's singletons and the underlying state
mechanism so that the state maintenance layer could be mocked out for
tests?

This brings some other issues I've been wrangling with lately to mind.
Please forgive me for rambling, but I think that the issue of testing
is intimately tied to how Lift deals with state maintenance.

State is sort of becoming a bugbear for me as my Lift app becomes more
complex. I'm not sure whether I'm just doing things wrong or what, but
I'm finding that using RequestVars and StatefulSnippets to maintain
state makes it difficult to build composable editing components. As an
example, I've got a StatefulSnippet that I use to build an object of
type EventTrigger. There are a few possible subclasses of EventTrigger
that can be produced through the workflow managed by the
StatefulSnippet, and switching between the type options and such works
well.

The problem is that an EventTrigger may be associated with some number
of Products, of which there are also a number of subclasses. So, I
also have a similar StatefulSnippet that manages the flow of creating
Products. But how do I pass the state of a newly created (or selected
existing) EventTrigger from one StatefulSnippet to the next? As far as
I can tell, there is no way to hand off control between
StatefulSnippet instances - instead I must populate a RequestVar and
use a redirect in the transition. Both sides of this state transaction
have expectations of the state of the intermediate RequestVar, but
there is no way to enforce that it be populated before the second
snippet attempts to use it. This feels very Model 1 to me. It's the
same case wherever I use RequestVar - some component (say a link) sets
a value, then some other component reads it, and while the ReqestVar
provides type safety for the value type, there is no associated type
safety available for the call, as both links and redirects simply use
strings to define behavior.

This all seems to fall out of the fact that the processing of a
template at a Loc results in reflective invocation of snippet
functions. The template itself, which is outside the type system,
defines the behavior at a Loc. As such, every snippet must be written
to operate correctly in the absence of any piece of the state it
expects. At least in my app, this ends up as an obnoxiously large
amount of boilerplate.

I think that I must be doing something wrong, because the feel of my
app is that it is held together by snot and string, threaded through
RequestVars that I hope will be populated with the correct values at
the correct times and redirects that I hope are pointing to the right
locations. At the same time, I can't figure out how else Lift will
permit me to handle my state. With each new feature I add, I become a
little more dismayed.

Please, how can I handle these problems better?

Thanks,

Kris




On Fri, Jul 3, 2009 at 10:43 AM, David
Pollak wrote:
> Jeppe,
>
> Once I check in some code (in about 20 minutes), if you run Lift in Test
> mode (-Drun.mode=test), forms, etc. will have stable names which makes
> testing easier.
>
> Thanks,
>
> David
>
> On Thu, Jul 2, 2009 at 1:13 PM, Jeppe Nejsum Madsen 
> wrote:
>>
>> Hi,
>>
>> Having taken the first baby steps and gotten a Lift app running, it's
>> time to bring back some of the old engineering practices to make sure
>> things keep running when new features are added at a rapid pace :-)
>>
>> I'm interested in how people are testing their Lift apps, both at the
>> unit test level (ie. specs/scalatest with no container) and at the
>> integration test level (running in servlet container). Also, how are you
>> doing TDD with Lift (if at all).
>>
>> Specifically, I've run into the following issues:
>>
>> 1) Testing model classes. Many require access to S (ie to read
>> resources) or other static Lift constructs. How can you mock these?
>>
>> 2) Testing snippets. Same issue with S, but more related to the actual
>> request, eg. S.param
>>
>> For in-container testing it seems the practice of generating unique
>> names for form fields, makes it difficult to use tools like Selenium to
>> do browser based testing? How do you handle this?
>>
>> Any input is appreciated
>>
>> /Jeppe
>>
>>
>
>
>
> --
> 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
>
> >
>

--~--~

[Lift] Re: Binding based on attributes

2009-07-03 Thread David Pollak
On Thu, Jul 2, 2009 at 6:48 AM, Nolan Darilek wrote:

>
> I'm working on an app that allows users to enter their own form
> templates, which are rendered to HTML forms and filled out. The results
> are then captured and encoded for later rendering. So the user might
> input something like:
>
> Name: 
> Is this your first visit? 
> ..
>
> Is it possible to bind the various snippets, but perform special
> handling on their attribute values? So, for instance, I'd bind an
> S.text() to all , but it'd set a variable based on its name


SHtml.text(defaultValue, func, "class" -> "fruitbat", "style" -> "width:
300px")

>
> attribute, and perform rough validations based on whether required is
> set to true? It isn't immediately obvious how to do this, even when
> digging through the Lift sources.


You might also be thinking of FuncBindParam:

if you're input is 

Then FuncBindParam("bar", n => ...)

n will be  so you can use Scala's XML stuff to extract
the myparam attribute and do something with it.

Thanks,

David


>
>
>
> >
>


-- 
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

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



[Lift] Re: How to test/TDD lift apps?

2009-07-03 Thread David Pollak
Jeppe,

Once I check in some code (in about 20 minutes), if you run Lift in Test
mode (-Drun.mode=test), forms, etc. will have stable names which makes
testing easier.

Thanks,

David

On Thu, Jul 2, 2009 at 1:13 PM, Jeppe Nejsum Madsen wrote:

>
> Hi,
>
> Having taken the first baby steps and gotten a Lift app running, it's
> time to bring back some of the old engineering practices to make sure
> things keep running when new features are added at a rapid pace :-)
>
> I'm interested in how people are testing their Lift apps, both at the
> unit test level (ie. specs/scalatest with no container) and at the
> integration test level (running in servlet container). Also, how are you
> doing TDD with Lift (if at all).
>
> Specifically, I've run into the following issues:
>
> 1) Testing model classes. Many require access to S (ie to read
> resources) or other static Lift constructs. How can you mock these?
>
> 2) Testing snippets. Same issue with S, but more related to the actual
> request, eg. S.param
>
> For in-container testing it seems the practice of generating unique
> names for form fields, makes it difficult to use tools like Selenium to
> do browser based testing? How do you handle this?
>
> Any input is appreciated
>
> /Jeppe
>
> >
>


-- 
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

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



[Lift] Re: howto do simple calculation with MappedInt

2009-07-03 Thread David Pollak
Send me the file and I'll debug it.

On Fri, Jul 3, 2009 at 3:06 AM, Tobias Daub  wrote:

>
> Thanks Dave, but still getting this error:
>
>
> /home/wacky/NetBeansProjects/virtualMarket/src/main/scala/org/tobster/model/Order.scala:51:
> error: value lotValue is not a member of Long
> override def _toForm = Full({Order.this.lots *
> Order.this.marketPlace.lotValue})
>
>
> What is the explanation for this behavior?
>
> thanks
> >
> >
> > On Sun, Jun 21, 2009 at 6:38 AM, Tobias Daub  > > wrote:
> >
> >
> > I'm stucked again with the simple things
> >
> > I've a trait that extends BaseLongKeyedMapper and I wanna add a field
> > (currentCost) that does some calculation. Nothing special. Here's
> > the code:
> >
> > /*
> >  * Order.scala
> >  *
> >  * To change this template, choose Tools | Template Manager
> >  * and open the template in the editor.
> >  */
> >
> > package org.tobster.model
> >
> > import net.liftweb._
> > import mapper._
> > import http._
> > import SHtml._
> > import util._
> > import model._
> >
> > /* Describes a general order.  */
> > trait Order extends BaseLongKeyedMapper{
> >
> >/* The number of lots this order has */
> >object lots extends MappedInt(this.asInstanceOf[MapperType])
> >
> >/* The person who owns the order */
> >object owner extends
> > MappedLongForeignKey(this.asInstanceOf[MapperType], User){
> >
> >// hides this field in the CRUDify list/create forms
> >override def dbDisplay_? = false
> >
> >//set the default value to the current logged in user (at
> > creation time)
> >override def defaultValue = User.currentUser.map(_.id.is
> > ) openOr 0L
> >}
> >
> >/* The market place where the order belongs to  */
> >object marketPlace extends
> > MappedLongForeignKey(this.asInstanceOf[MapperType],
> > MarketPlaceMetaObj){
> >override def _toForm = Full(SHtml.selectObj[MarketPlace](
> >
>  MarketPlaceMetaObj.findAll.map(mp
> > => (mp, mp.name.is )),
> >  obj,
> >  (mp: MarketPlace) => apply(mp)))
> >}
> >
> >/* The basic trade types are: BUY and SELL */
> >object tradeType extends
> > MappedLongForeignKey(this.asInstanceOf[MapperType],
> TradeTypeMetaObj){
> >override def _toForm = Full(SHtml.selectObj[TradeType](
> >TradeTypeMetaObj.findAll.map(t => (t, t.name.is
> > )),
> >obj,
> >(t: TradeType) => apply(t)))
> >}
> >
> >
> >object currentCost extends
> > MappedInt(this.asInstanceOf[MapperType]){
> >override def _toForm = Full({this.lots *
> > this.marketPlace.lotValue})
> >
> >
> >
> > Try:
> > override def _toForm = Full({Order.this.lots *
> > Order.this.marketPlace.lotValue})
> >
> >
> >
> >
> >}
> >
> > }
> >
> > I get the following compiler error:
> >
> > [WARNING]
> >
> /home/wacky/workspace_VirtuelleBoerse/virtualMarket/src/main/scala/org/tobster/model/Order.scala:51:
> > error: value lots is not a member of Int
> > [WARNING] override def _toForm = Full({this.lots *
> > this.marketPlace.lotValue})
> > [WARNING]  ^
> > [WARNING] one error found
> >
> > The field marketPlace.lotValue is of type MappedInt as well as the
> > field
> > lots.
> >
> > I tried things like "this.lots.is " or
> > "this.lots.i_is_!" but without
> > success. I ran out of ideas...
> >
> >
> > thanks.
> >
> >
> >
> >
> >
> > --
> > 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
> >
> > >
>
>
> >
>


-- 
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

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



[Lift] Re: Binding based on attributes

2009-07-03 Thread Derek Chen-Becker
I would take a look at Scala's XML facilities. In particular, I think that
you can use matching on the elements to filter and substitute the input.

Derek

On Thu, Jul 2, 2009 at 7:48 AM, Nolan Darilek wrote:

>
> I'm working on an app that allows users to enter their own form
> templates, which are rendered to HTML forms and filled out. The results
> are then captured and encoded for later rendering. So the user might
> input something like:
>
> Name: 
> Is this your first visit? 
> ..
>
> Is it possible to bind the various snippets, but perform special
> handling on their attribute values? So, for instance, I'd bind an
> S.text() to all , but it'd set a variable based on its name
> attribute, and perform rough validations based on whether required is
> set to true? It isn't immediately obvious how to do this, even when
> digging through the Lift sources.
>
>
> >
>

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



[Lift] Re: Thoughts on file streaming

2009-07-03 Thread Derek Chen-Becker
Awesome! That's a nice way to bypass the issues I was running into. I
suppose that if someone wanted to control it on a per-form basis then they
could do it themselves via their own field mappings.

Derek

On Wed, Jul 1, 2009 at 12:20 PM, David Pollak  wrote:

> Okay... I've checked in new code.
>
> In LiftRules, there's:
>
>   /**
>* The function that converts a fieldName, contentType, fileName and an
> InputStream into
>* a FileParamHolder.  By default, create an in-memory instance.  Use
> OnDiskFileParamHolder
>* to create an on-disk version
>*/
>   var handleMimeFile: (String, String, String, InputStream) =>
> FileParamHolder =
>   (fieldName, contentType, fileName, inputStream) =>
>   new InMemFileParamHolder(fieldName, contentType, fileName,
> Helpers.readWholeStream(inputStream))
>
>
> You can change handleMimeFile to use OnDiskFileParamHolder.  There's a
> companion object that has a helper that'll allow you to create an instance
> out of the parameters.  By default, the OnDiskFileParamHolder deletes the
> temporary file when it is finalized.
>
> If you want to monitor the progress of an upload, use LiftRules:
>   /**
>* The global multipart progress listener:
>* pBytesRead - The total number of bytes, which have been read so
> far.
>*pContentLength - The total number of bytes, which are being read.
> May be -1, if this number is unknown.
>*pItems - The number of the field, which is currently being read. (0
> = no item so far, 1 = first item is being read, ...)
>*/
>   var progessListener: (Long, Long, Int) => Unit = (_, _, _) => ()
>
> By default, it does nothing, but you can put in a function that'll look for
> a session-specific CometActor and send it messages.
>
> If the above does not satisfy all your needs, you can subclass
> FileParamHolder and do whatever you want.
>
> Thanks,
>
> David
>
>
>
> On Wed, Jul 1, 2009 at 10:31 AM, David Pollak <
> feeder.of.the.be...@gmail.com> wrote:
>
>> K... I'll check some code in later today.
>>
>>
>> On Wed, Jul 1, 2009 at 9:05 AM, Andrew Scherpbier 
>> wrote:
>>
>>>
>>> It would also be nice to be able to provide progress feedback.  The page
>>> returned after the form submission can then use comet to display a
>>> progress bar or something like that.  (The media upload at Vimeo comes
>>> to mind as a good example of this!)
>>>
>>> Also, I would suggest some smarts when creating temporary files.  It
>>> might be good to abstract the cache so that small files don't get put on
>>> disk.
>>>
>>> --Andrew
>>>
>>> Vlad Seryakov wrote:
>>> > I am also contemplating to use Lift but lack of big file upload is the
>>> > showstopper. We need to upload images, and big video files and
>>> > currently there i snot way to do it in Lift, i need something else to
>>> > handle that which makes the whole stuff more complex than needed.
>>> >
>>> > Spooling into temp file and doing async upload of multiple files at
>>> > the same time is what needed. Nowadays media uploads is normal and
>>> > those files are getting bigger and bigger.
>>> >
>>> > On Jun 30, 5:58 pm, Timothy Perrett  wrote:
>>> >
>>> >> This has been hurting me for quite a while now (raised it on list
>>> >> about 2 months ago) and could really do with getting it fixed.
>>> >>
>>> >> As derek points out, it's not a small change which is why I've done
>>> >> nothing about it to date - a little too much core hacking to feel
>>> happy
>>> >>
>>> >> If you think your able to do something about it that would be
>>> >> absolutly brilliant!
>>> >>
>>> >> Cheers
>>> >>
>>> >> Tim
>>> >>
>>> >> Sent from my iPhone
>>> >>
>>> >> On 30 Jun 2009, at 22:33, David Pollak >> >
>>> >> wrote:
>>> >>
>>> >>
>>> >>> What kind of priority is this issue?  I think I can abstract things
>>> >>> in such a way that it works correctly, but it'll take a couple of
>>> >>> days.
>>> >>>
>>> >>> On Tue, Jun 30, 2009 at 2:08 PM, Derek Chen-Becker <
>>> dchenbec...@gmail.com
>>> >>>
>>>  wrote:
>>> 
>>> >>> Well, as usual something that seemed simple at first glance is now
>>> >>> looking somewhat complex. I'm thinking of reworking the fileUpload
>>> >>> handling to allow a user to register either a (String, String, Array
>>> >>> [Byte]) => Any or (String, String, InputStream) => Any function,
>>> >>> which would then be executed during request processing. The issue is
>>> >>>  that form field processing (ParamHolders) takes place in Req, befor
>>> >>> e LiftSession has been set up, and the act of parsing the request fo
>>> >>> r form data, particularly for large upload streams (the target of th
>>> >>> ese changes) precludes holding on to any data for later processing (
>>> >>> the servlet container cannot be expected to hold the entire request
>>> >>> in memory). On the other hand, users should reasonably expect that t
>>> >>> heir form handling functions are stateful, so I'm trying to think of
>>> >>>  some way to meet in the middle on form processing. Ideas?
>>> >>>
>>> >>> Derek

[Lift] Re: can a Snippet call a Snippet?

2009-07-03 Thread Alexander Azarov

I vote for this! Personally I do not completely understand all the
possibilities Failure gives and how to achieve these. BTW, I found
recently the appendix about Boxes disappeared from the printed Lift
book :(

On Jul 2, 5:55 pm, Timothy Perrett  wrote:
> We really ought to get around to writing a ³guides for boxes² - its easily
> one of the most confusing concepts in lift (a magnitude less confusing
> than when it was called Can[T])
>
> Cheers, Tim
>
> On 02/07/2009 14:46, "David Pollak"  wrote:
>
>
>
>
>
> > On Wed, Jul 1, 2009 at 10:43 PM, g-man  wrote:
>
> >> I'm getting a Null Pointer: 'Trying to open an empty box', from S.attr
> >> ("todos").open_!
>
> > Don't use open_!  It's dangerous.
>
> > That's why Boxes exist.  They contain (or don't) something that may or may 
> > not
> > exist.  If you use open_! in your code, it is a major mistake (a logic 
> > error)
> > unless the line before the open contains "if (thing.isDefined) {"
>
> > Thanks,
>
> > David
> >  
>
> >> Here's my layout:
>
> >> todo.html template 
>
> >> 
> >> --- Todo list table stuff ---
> >> 
> >> --- Tag list table stuff (where the selection to filter comes from)
> >> ---
>
> >> TD.scala snippet =
>
> >> // this arity is for the default 'show all Todos' condition
> >> def list(html: NodeSeq) = {
> >>     val id = S.attr("todos").open_!
>
> >> // this arity is for the 'filter by Tag' case
> >> def list(filterTag: Long)(html: NodeSeq) = {
> >>     val id = S.attr("todos").open_!
>
> >> The two snippet methods could probably be combined with a (param:
> >> Long*) signature, but Scala does not seem to care right now. The
> >> default works perfectly, but when a Tag is selected to filter by, the
> >> 'todos' id Box cannot be seen when attempting to open.
>
> >> Is this because it is probably out of scope? I am using an ajaxbutton
> >> to make the call and pass in the tag.id  , but it is hard to
> >> see how an
> >> S.attr could exist for one request, then be gone for the next, unless
> >> I am confusing this with a stateful attribute.
>
> >> On Jul 1, 2:42 pm, David Pollak  wrote:
> >>> > On Wed, Jul 1, 2009 at 2:28 PM, g-man  wrote:
>
>  > > I will look into the nested snippets.
>
>  > > For expediency, I folded all the snippets that interact with my
>  > > template into one file, so I can concentrate on the business logic.
>
>  > > For my Todo app enhancement, I need to pass the id of my selected Tag
>  > > (which I have confirmed is correctly gathered from the page request)
>  > > in to the TD.list method, so that the filtered Todos (those bearing
>  > > the required Tag) will be found and rendered.
>
>  > > My problem is that if I try to pass an additional argument (tagId:
>  > > Long), the TD.list method is not happy and will not even render the
>  > > template.
>
>  > > I have tried both paired (html: NodeSeq, tagId: Long) as well as
>  > > curried style (html: NodeSeq)(tagId: Long), but neither works.
>
> >>> > Try:
>
> >>> > list(tagId: Long)(html: NodeSeq): NodeSeq
>
> >>> > That way list(44L) _ becomes a NodeSeq => NodeSeq
>
>  > > There must be a simple way to accomplish such a common task!
>
>  > > Thanks to all the members for commenting...
>
>  > > On Jun 29, 11:25 pm, "marius d."  wrote:
> > > > > Or you can use S.locateMappedSnippet ... but first try to see if
> > > > > nested snippet won't do the trick for you ...
>
> > > > > On Jun 30, 10:17 am, "marius d."  wrote:
>
> >> > > > > Can you paste some code?
>
> >> > > > > Essentially we support nested snippets so your snippet can 
> >> > > > > simply
> >> > > > > return a markup containing another snippet and it will be
> >> invoked. If
> >> > > > > you really want to manually invoke a snippet from another 
> >> > > > > snippet
> and
> >> > > > > if you are not using StatefulSnippets you can just instantiate
> the
> >> > > > > class and call your function and pass it the right NodeSeq.
>
> >> > > > > Br's,
> >> > > > > Marius
>
> >> > > > > On Jun 30, 5:36 am, g-man  wrote:
>
> >>> > > > > > I am enhancing the Todo app by adding tags.
>
> >>> > > > > > I have retained the TD.scala snippet to manage the Todos on 
> >>> > > > > > my
> page,
> >>> > > > > > and added a TG.scala snippet to handle tags on the same 
> >>> > > > > > page,
> which
> >>> > > > > > works well for creating new and listing in both cases.
>
> >>> > > > > > Now I want to filter my Todos list by a Tag instance I 
> >>> > > > > > select
> from my
> >>> > > > > > list, and therefore need to pass the id of the selected tag
> over from
> >>> > > > > > the TG snippet to the TD snippet, where it can be used as a
> filter
> >>> > > > > > argument for a find method.
>
> >>> > > > > > The problem is that scala says it cannot find snippet TD,
> whose
>  > > method
> >>> > > > > > I am call

[Lift] Sitemap, restricted menus and skinning a cat

2009-07-03 Thread Ewan

I wonder if anyone would care to advise of the most appropriate
solution for not rendering sitemap menu items with additional redirect
to a login page.  I have read a couple of solutions in this list but
here is what I have done cobbled together from the liftbook.

I have an If LocParam for testing if a user is logged in which is
added to a menu:

  val loggedInLocParam = If(() => User.loggedIn_?,
() => RedirectWithState("/user_mgt/login",
RedirectState(Empty, ("You must login", NoticeType.Notice

this seems to achieve the effect I am looking for in that the menuitem
is not rendered and if the url was bookmarked and the user tries a GET
then they are redirected to login and a notice is added and rendered
at the top of the page accordingly.

Is this a good solution or can this cat be skinned better?  I have
read something about Loc.EarlyResponse and was hoping for an
explanation.

--Ewan

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



[Lift] Re: howto do simple calculation with MappedInt

2009-07-03 Thread Tobias Daub

Thanks Dave, but still getting this error:

/home/wacky/NetBeansProjects/virtualMarket/src/main/scala/org/tobster/model/Order.scala:51:
 
error: value lotValue is not a member of Long
override def _toForm = Full({Order.this.lots * 
Order.this.marketPlace.lotValue})


What is the explanation for this behavior?

thanks
>
>
> On Sun, Jun 21, 2009 at 6:38 AM, Tobias Daub  > wrote:
>
>
> I'm stucked again with the simple things
>
> I've a trait that extends BaseLongKeyedMapper and I wanna add a field
> (currentCost) that does some calculation. Nothing special. Here's
> the code:
>
> /*
>  * Order.scala
>  *
>  * To change this template, choose Tools | Template Manager
>  * and open the template in the editor.
>  */
>
> package org.tobster.model
>
> import net.liftweb._
> import mapper._
> import http._
> import SHtml._
> import util._
> import model._
>
> /* Describes a general order.  */
> trait Order extends BaseLongKeyedMapper{
>
>/* The number of lots this order has */
>object lots extends MappedInt(this.asInstanceOf[MapperType])
>
>/* The person who owns the order */
>object owner extends
> MappedLongForeignKey(this.asInstanceOf[MapperType], User){
>
>// hides this field in the CRUDify list/create forms
>override def dbDisplay_? = false
>
>//set the default value to the current logged in user (at
> creation time)
>override def defaultValue = User.currentUser.map(_.id.is
> ) openOr 0L
>}
>
>/* The market place where the order belongs to  */
>object marketPlace extends
> MappedLongForeignKey(this.asInstanceOf[MapperType],
> MarketPlaceMetaObj){
>override def _toForm = Full(SHtml.selectObj[MarketPlace](
>  MarketPlaceMetaObj.findAll.map(mp
> => (mp, mp.name.is )),
>  obj,
>  (mp: MarketPlace) => apply(mp)))
>}
>
>/* The basic trade types are: BUY and SELL */
>object tradeType extends
> MappedLongForeignKey(this.asInstanceOf[MapperType], TradeTypeMetaObj){
>override def _toForm = Full(SHtml.selectObj[TradeType](
>TradeTypeMetaObj.findAll.map(t => (t, t.name.is
> )),
>obj,
>(t: TradeType) => apply(t)))
>}
>
>
>object currentCost extends
> MappedInt(this.asInstanceOf[MapperType]){
>override def _toForm = Full({this.lots *
> this.marketPlace.lotValue})
>
>
>
> Try:
> override def _toForm = Full({Order.this.lots * 
> Order.this.marketPlace.lotValue})
>
>  
>
>
>}
>
> }
>
> I get the following compiler error:
>
> [WARNING]
> 
> /home/wacky/workspace_VirtuelleBoerse/virtualMarket/src/main/scala/org/tobster/model/Order.scala:51:
> error: value lots is not a member of Int
> [WARNING] override def _toForm = Full({this.lots *
> this.marketPlace.lotValue})
> [WARNING]  ^
> [WARNING] one error found
>
> The field marketPlace.lotValue is of type MappedInt as well as the
> field
> lots.
>
> I tried things like "this.lots.is " or
> "this.lots.i_is_!" but without
> success. I ran out of ideas...
>
>
> thanks.
>
>
>
>
>
> -- 
> 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
>
> >


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



[Lift] Re: Changes to ajax handling?

2009-07-03 Thread marius d.

Yeah that what happens when you're coding late in the night ... the
null monster bites you.

Marius

On Jul 2, 7:47 pm, Kris Nuttycombe  wrote:
> Marius, that fix appears to work fine, thank you!
>
> Bloody nulls. :)
>
> Kris
>
> On Thu, Jul 2, 2009 at 7:17 AM, marius d. wrote:
>
> > Corrected and pushed. Please do an update and give it a try.
>
> > Br's,
> > Marius
>
> > On Jul 2, 8:56 am, "marius d."  wrote:
> >> On Jul 2, 12:40 am, Kris Nuttycombe  wrote:
>
> >> > To answer my own question, looking over the commit log 28595307 looks
> >> > extremely suspicious. I can revert it locally but would prefer a
> >> > mainline fix, and don't want to attempt it myself. Marius?
>
> >> > Kris
>
> >> > On Wed, Jul 1, 2009 at 3:33 PM, Kris
>
> >> > Nuttycombe wrote:
> >> > > Hi, all,
>
> >> > > Have there been recent changes made to liftAjax.js? I am encountering
> >> > > new errors from an ajaxSelect() today that were not present yesterday.
> >> > > Firebug complains:
>
> >> > > Use of getBoxObjectFor() is deprecated. Try to use
> >> > > element.getBoundingClientRect() if possible.
> >> > > [Break on this error] undefined
> >> > > liftAjax.js (line 111)
> >> > > aboutToSend.responseType is null
> >> > > lift_doAjaxCycle()()liftAjax.js (line 111)
> >> > > lift_ajaxHandler()()liftAjax.js (line 21)
> >> > > onchange(change )add_trig...Gyw%3D%3D (line 2)
> >> > > [Break on this error] if (aboutToSend.responseType.toLowerCase() === 
> >> > > "json")
>
> >> That is my commt but right now I don,t see how it affects other
> >> things ... But I,ll definitely look on it today. Note that there is no
> >> intent for ajax behavior changes .. Just an augmentation ...
>
> >> > > Thanks,
>
> >> > > Kris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---