Help to define the WSHtml trait that extends SHtml

47 views
Skip to first unread message

Sanx

unread,
May 31, 2012, 11:15:23 AM5/31/12
to Lift
Greetings to all

I'm trying to define the "WSHtml" trait that extends SHtml and
implements the radio and radio_* method:

the code here:

http://pastie.org/4002175

package code
package lib

import scala.xml._
import net.liftweb.http.SHtml
import net.liftweb.common._
import net.liftweb.http.S._


trait WSHtml extends SHtml {


override def radio(opts: Seq[(String, String)], deflt: Box[String],
func: String => Any, attrs: ElemAttr*): ChoiceHolder[String] =
radio_*(opts, deflt, SFuncHolder(func), attrs: _*)


override def radio_*(opts: Seq[(String, String)], deflt:
Box[String], func: AFuncHolder, attrs: ElemAttr*):
ChoiceHolder[String] = {
fmapFunc(func) {
name =>
val itemList = opts.flatMap{
case (value, text) =>
ChoiceItem(
text,attrs.foldLeft(<input type="radio" name={name}
value={value}/>)(_ % _) %
checked(deflt.filter((s: String) => s == value).isDefined)
)
}
ChoiceHolder(itemList)
}
}


}

but sends me the following error:

[error] /home/hector/lift/produccion/portal/src/main/scala/code/lib/
WSHtml.scala:23: type mismatch;
[error] found : WSHtml.this.ElemAttr
[error] required: scala.xml.MetaData
[error] text,attrs.foldLeft(<input type="radio"
name={name} value={value}/>)(_ % _) %
[error]
^
[error] one error found

do not know if this is the best way to do this
but can someone tell me I'm doing wrong or what I need


David Pollak

unread,
May 31, 2012, 12:27:18 PM5/31/12
to lif...@googlegroups.com
Why extend SHtml?

Why not just create your own singleton?



--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Sanx

unread,
May 31, 2012, 1:09:23 PM5/31/12
to Lift
Ok, thank you very much for the suggestion
but the problem remains the same and I'm using singlenton


[error] found : net.liftweb.http.SHtml.ElemAttr
[error] required: scala.xml.MetaData
[error] text,attrs.foldLeft(<input type="radio"
name={name} value={value}/>)(_ % _) %
[error]
^
[error] one error found



> Visi.Pro, Cloud Computing for the Rest of Ushttp://visi.pro
> Lift, the simply functional web frameworkhttp://liftweb.net

Jeppe Nejsum Madsen

unread,
Jun 1, 2012, 3:26:23 AM6/1/12
to lif...@googlegroups.com
Sanx <hecto...@gmail.com> writes:

> Ok, thank you very much for the suggestion
> but the problem remains the same and I'm using singlenton
>
>
> [error] found : net.liftweb.http.SHtml.ElemAttr
> [error] required: scala.xml.MetaData
> [error] text,attrs.foldLeft(<input type="radio"
> name={name} value={value}/>)(_ % _) %
> [error]
> ^
> [error] one error found

The problem is that the % operator is defined on ApplicableElem which is
private.

I've also run into this an the workaround is to include

class ApplicableElem(in: Elem) {
def %(attr: SHtml.ElemAttr): Elem = attr.apply(in)
}
implicit def elemToApplicable(e: Elem): ApplicableElem = new ApplicableElem(e)

in your own code.

I'm not sure why these are private, but maybe David has input?

/Jeppe

David Pollak

unread,
Jun 1, 2012, 12:47:22 PM6/1/12
to lif...@googlegroups.com
On Fri, Jun 1, 2012 at 12:26 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk> wrote:
Sanx <hecto...@gmail.com> writes:

> Ok, thank you very much for the suggestion
> but the problem remains the same and I'm using singlenton
>
>
> [error]  found   : net.liftweb.http.SHtml.ElemAttr
> [error]  required: scala.xml.MetaData
> [error]             text,attrs.foldLeft(<input type="radio"
> name={name} value={value}/>)(_ % _) %
> [error]
> ^
> [error] one error found

The problem is that the % operator is defined on ApplicableElem which is
private.

I've also run into this an the workaround is to include

   class ApplicableElem(in: Elem) {
     def %(attr: SHtml.ElemAttr): Elem = attr.apply(in)
   }
   implicit def elemToApplicable(e: Elem): ApplicableElem = new ApplicableElem(e)

in your own code.

I'm not sure why these are private, but maybe David has input?

I generally go for private implicits so they don't spill over into anything that imports SHtml._  I'm cool with opening it up.  Can you make the change today so it gets into M1?



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net

Jeppe Nejsum Madsen

unread,
Jun 2, 2012, 5:25:10 AM6/2/12
to lif...@googlegroups.com
David Pollak <feeder.of...@gmail.com> writes:

> On Fri, Jun 1, 2012 at 12:26 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk>wrote:
>
>> Sanx <hecto...@gmail.com> writes:
>>
>> > Ok, thank you very much for the suggestion
>> > but the problem remains the same and I'm using singlenton
>> >
>> >
>> > [error] found : net.liftweb.http.SHtml.ElemAttr
>> > [error] required: scala.xml.MetaData
>> > [error] text,attrs.foldLeft(<input type="radio"
>> > name={name} value={value}/>)(_ % _) %
>> > [error]
>> > ^
>> > [error] one error found
>>
>> The problem is that the % operator is defined on ApplicableElem which is
>> private.
>>
>> I've also run into this an the workaround is to include
>>
>> class ApplicableElem(in: Elem) {
>> def %(attr: SHtml.ElemAttr): Elem = attr.apply(in)
>> }
>> implicit def elemToApplicable(e: Elem): ApplicableElem = new
>> ApplicableElem(e)
>>
>> in your own code.
>>
>> I'm not sure why these are private, but maybe David has input?
>>
>
> I generally go for private implicits so they don't spill over into anything
> that imports SHtml._ I'm cool with opening it up. Can you make the change
> today so it gets into M1?

Nope :-)

But have some time this weekend so will have a look. See other mail
about M1

/Jeppe
Reply all
Reply to author
Forward
0 new messages