[Lift] Re: automaticly generated forms and submit button naming

2009-09-28 Thread Ross Mellgren

Ah, that's because it should be a flatMap not a map --  
f.toForm.toList.flatMap(form => { bind(...) }) should typecheck.

The way you have it now, if the bind expands to more than one element  
or node, the ones after the first will be dropped.

Glad it (mostly) worked for you.

-Ross

On Sep 28, 2009, at 5:48 AM, Martin wrote:

>
> Hi,
>
> Ross, thank you for your help. This code works perfectly for me. I
> heaven't noticed I could group many elements in one lift tag.
>
> I changed somethings in your code. Maybe it's not worth mentioning but
> if someone has similar problems it can help a little.
> I corrected only to things: changed parameters order in one bind and
> added some code to other.
> Result is here:
>
>def newPlace(ns: NodeSeq, place : Place): NodeSeq = {
>def bindFields(innerNs: NodeSeq): NodeSeq = {
>var s : String = "test"
>signupFields.
>map(fi => getSingleton.getActualBaseField(place, fi)).
>flatMap(f => {
>f.toForm.toList.map(form => {
>bind("field",
> innerNs,
>"displayName" -
>> f.displayName,
>"form"-
>> form)(1);
>})
>})
>}
>
>def handleSubmit(): Any = {
>}
>
>bind("place", ns,
> "fields" -> { (ns: NodeSeq) => bindFields(ns) },
> "submit" -> { (ns: NodeSeq) => SHtml.submit("Submit new
> place", handleSubmit _) })
>}
>
> Still I don't get why I need to get second element from bind result
> (which is NodeSeq) and pass it to .toForm.toList.map(...).
> When I first compiled this code i got type mismatch error:
> found   : scala.xml.NodeSeq
> required: scala.xml.Node
>
> So I picked up first non empty element from the result by using bind
> (...)(1) and it works in my scenario. Maybe I will catch it later ;)
>
> Again this code works perfectly for me. Great thanks Ross!
>
> - Martin
>
>
>
>
> On 24 Wrz, 16:15, Ross Mellgren  wrote:
>> It sounds like you probably want { SHtml.submit("Title of submit
>> button", () => actionToTakeWhenButtonIsUsedToSubmitForm) }
>>
>> By the way, what you have there doesn't seem to be following the  
>> usual
>> lift pattern of binding snippets, is there a reason that you prefer
>> this to:
>>
>> template:
>>
>> 
>>  Place details
>>  
>>  
>>  
>>  
>>  
>>  
>>  
>>  
>>  
>> 
>>
>> Snippet:
>>
>> def newPlace(ns: NodeSeq): NodeSeq = {
>>  val place = /* make a new place somehow */
>>
>>  def bindFields(ns: NodeSeq): NodeSeq =
>>  signupFields.
>>  map(fi => getSingleton.getActualBaseField(place, fi)).
>>  flatMap(f => {
>>  f.toForm.toList.map(form => {
>>  bind(ns, "field",
>>   "displayName" -> f.displayName,
>>   "form"-> form)
>>  })
>>  })
>>
>>  def handleSubmit(): Any = /* do something with place */
>>
>>  bind("place", ns,
>>   "fields" -> { (ns: NodeSeq) => bindFields(ns) },
>>   "submit" -> { (ns: NodeSeq) => SHtml.submit("Submit new
>> Place", handleSubmit _) })
>>
>> }
>>
>> This way lets you see most of the HTML in one place (the template). I
>> inlined localForm, but there's no particular reason that it needs to
>> be local (other than it closes on place, but you could just pass that
>> in)
>>
>> -Ross
>>
>> On Sep 24, 2009, at 6:55 AM, Martin wrote:
>>
>>
>>
>>> Hi all,
>>
>>> I've got a following problem. When I create a form form  
>>> automaticly..
>>> similar to the User login/register example I encontered a problem  
>>> I'm
>>> not posible to cope with.
>>
>>> Firstly I have 'written' a function (using Copy&Paste method) which
>>> creates a form fields list based on my class properties:
>>
>>>private def localForm(place: Place, ignorePassword: Boolean):
>>> NodeSeq = {
>>>signupFields.
>>>map(fi => getSingleton.getActualBaseField(place, fi)).
>>>filter(f => !ignorePassword || (f match {
>>>case f: MappedPassword[Place] => false
>>>case _ => true
>>>})).
>>>flatMap(f =>
>>>f.toForm.toList.map(form => {f.displayName}>> label> {form}) )
>>>}
>>
>>> Next, I wrote some code to return a complete form to the snippet:
>>
>>>def newPlace(place: Place) =
>>>
>>>Place details
>>>
>>>{
>>>localForm(place, false)
>>>}
>>>
>>><_WHAT_SHOULD_I_WRITE_HERE_:submit />
>>>
>>
>>> My question is... what do I write in _WHAT_SHOULD_I_WRITE_HERE_ ?
>>> Or better.. how/where to define this value?
>>
>>> In a user login/register examp

[Lift] Re: automaticly generated forms and submit button naming

2009-09-28 Thread Martin

Hi,

Ross, thank you for your help. This code works perfectly for me. I
heaven't noticed I could group many elements in one lift tag.

I changed somethings in your code. Maybe it's not worth mentioning but
if someone has similar problems it can help a little.
I corrected only to things: changed parameters order in one bind and
added some code to other.
Result is here:

def newPlace(ns: NodeSeq, place : Place): NodeSeq = {
def bindFields(innerNs: NodeSeq): NodeSeq = {
var s : String = "test"
signupFields.
map(fi => getSingleton.getActualBaseField(place, fi)).
flatMap(f => {
f.toForm.toList.map(form => {
bind("field",
innerNs,
"displayName" -
> f.displayName,
"form"-
> form)(1);
})
})
}

def handleSubmit(): Any = {
}

bind("place", ns,
 "fields" -> { (ns: NodeSeq) => bindFields(ns) },
 "submit" -> { (ns: NodeSeq) => SHtml.submit("Submit new
place", handleSubmit _) })
}

Still I don't get why I need to get second element from bind result
(which is NodeSeq) and pass it to .toForm.toList.map(...).
When I first compiled this code i got type mismatch error:
 found   : scala.xml.NodeSeq
 required: scala.xml.Node

So I picked up first non empty element from the result by using bind
(...)(1) and it works in my scenario. Maybe I will catch it later ;)

Again this code works perfectly for me. Great thanks Ross!

- Martin




On 24 Wrz, 16:15, Ross Mellgren  wrote:
> It sounds like you probably want { SHtml.submit("Title of submit  
> button", () => actionToTakeWhenButtonIsUsedToSubmitForm) }
>
> By the way, what you have there doesn't seem to be following the usual  
> lift pattern of binding snippets, is there a reason that you prefer  
> this to:
>
> template:
>
> 
>      Place details
>      
>          
>              
>                  
>                  
>              
>          
>      
>      
> 
>
> Snippet:
>
> def newPlace(ns: NodeSeq): NodeSeq = {
>      val place = /* make a new place somehow */
>
>      def bindFields(ns: NodeSeq): NodeSeq =
>          signupFields.
>              map(fi => getSingleton.getActualBaseField(place, fi)).
>              flatMap(f => {
>                  f.toForm.toList.map(form => {
>                      bind(ns, "field",
>                           "displayName" -> f.displayName,
>                           "form"        -> form)
>                  })
>              })
>
>      def handleSubmit(): Any = /* do something with place */
>
>      bind("place", ns,
>           "fields" -> { (ns: NodeSeq) => bindFields(ns) },
>           "submit" -> { (ns: NodeSeq) => SHtml.submit("Submit new  
> Place", handleSubmit _) })
>
> }
>
> This way lets you see most of the HTML in one place (the template). I  
> inlined localForm, but there's no particular reason that it needs to  
> be local (other than it closes on place, but you could just pass that  
> in)
>
> -Ross
>
> On Sep 24, 2009, at 6:55 AM, Martin wrote:
>
>
>
> > Hi all,
>
> > I've got a following problem. When I create a form form automaticly..
> > similar to the User login/register example I encontered a problem I'm
> > not posible to cope with.
>
> > Firstly I have 'written' a function (using Copy&Paste method) which
> > creates a form fields list based on my class properties:
>
> >    private def localForm(place: Place, ignorePassword: Boolean):
> > NodeSeq = {
> >        signupFields.
> >        map(fi => getSingleton.getActualBaseField(place, fi)).
> >        filter(f => !ignorePassword || (f match {
> >                    case f: MappedPassword[Place] => false
> >                    case _ => true
> >                })).
> >        flatMap(f =>
> >            f.toForm.toList.map(form => {f.displayName} > label> {form}) )
> >    }
>
> > Next, I wrote some code to return a complete form to the snippet:
>
> >    def newPlace(place: Place) =
> >    
> >        Place details
> >        
> >            {
> >                localForm(place, false)
> >            }
> >        
> >        <_WHAT_SHOULD_I_WRITE_HERE_:submit />
> >    
>
> > My question is... what do I write in _WHAT_SHOULD_I_WRITE_HERE_ ?
> > Or better.. how/where to define this value?
>
> > In a user login/register example there is submit defined like this:
> > 
>
> > Placing there name of the owner class didn't work.
> > I know I could use bind but as far as I know next I should create a
> > complete snippet with all the fields by hand.. and I would to avoid
> > it.
>
> > I was digging for solution in a Lift Book and on group as well, but
> > without success.
> > Help!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Go

[Lift] Re: automaticly generated forms and submit button naming

2009-09-24 Thread Ross Mellgren

It sounds like you probably want { SHtml.submit("Title of submit  
button", () => actionToTakeWhenButtonIsUsedToSubmitForm) }

By the way, what you have there doesn't seem to be following the usual  
lift pattern of binding snippets, is there a reason that you prefer  
this to:

template:


 Place details
 
 
 
 
 
 
 
 
 


Snippet:

def newPlace(ns: NodeSeq): NodeSeq = {
 val place = /* make a new place somehow */

 def bindFields(ns: NodeSeq): NodeSeq =
 signupFields.
 map(fi => getSingleton.getActualBaseField(place, fi)).
 flatMap(f => {
 f.toForm.toList.map(form => {
 bind(ns, "field",
  "displayName" -> f.displayName,
  "form"-> form)
 })
 })

 def handleSubmit(): Any = /* do something with place */

 bind("place", ns,
  "fields" -> { (ns: NodeSeq) => bindFields(ns) },
  "submit" -> { (ns: NodeSeq) => SHtml.submit("Submit new  
Place", handleSubmit _) })
}

This way lets you see most of the HTML in one place (the template). I  
inlined localForm, but there's no particular reason that it needs to  
be local (other than it closes on place, but you could just pass that  
in)

-Ross

On Sep 24, 2009, at 6:55 AM, Martin wrote:

>
> Hi all,
>
> I've got a following problem. When I create a form form automaticly..
> similar to the User login/register example I encontered a problem I'm
> not posible to cope with.
>
> Firstly I have 'written' a function (using Copy&Paste method) which
> creates a form fields list based on my class properties:
>
>private def localForm(place: Place, ignorePassword: Boolean):
> NodeSeq = {
>signupFields.
>map(fi => getSingleton.getActualBaseField(place, fi)).
>filter(f => !ignorePassword || (f match {
>case f: MappedPassword[Place] => false
>case _ => true
>})).
>flatMap(f =>
>f.toForm.toList.map(form => {f.displayName} label> {form}) )
>}
>
> Next, I wrote some code to return a complete form to the snippet:
>
>
>def newPlace(place: Place) =
>
>Place details
>
>{
>localForm(place, false)
>}
>
><_WHAT_SHOULD_I_WRITE_HERE_:submit />
>
>
>
> My question is... what do I write in _WHAT_SHOULD_I_WRITE_HERE_ ?
> Or better.. how/where to define this value?
>
> In a user login/register example there is submit defined like this:
> 
>
> Placing there name of the owner class didn't work.
> I know I could use bind but as far as I know next I should create a
> complete snippet with all the fields by hand.. and I would to avoid
> it.
>
> I was digging for solution in a Lift Book and on group as well, but
> without success.
> Help!
>
> >


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