SHtml.fileUpload and CRUDify ?

56 views
Skip to first unread message

Hannes

unread,
Dec 6, 2010, 10:08:50 AM12/6/10
to lif...@googlegroups.com
I have a problem with SHtml.fileUpload.

My code looks like this:

trait IViewable extends BaseLongKeyedMapper {

object image extends MappedBinary(this.asInstanceOf[MapperType]) {
override def dbDisplay_? = false
}

object imagePath extends MappedBinary(this.asInstanceOf[MapperType]) {
def notEmpty(input: String) = {
println("input=" + input)
if (input.isEmpty) {
List(FieldError(this, "Choose a file!"))
}
else Nil
}
override def _toForm = {
Full(SHtml.fileUpload(saveFile _))
}
override def displayName = "BILD"
//override def validations = notEmpty _ :: Nil
}

private def saveFile(fp: FileParamHolder): Unit = {
println("*** saveFile ***")
fp.file match {
case null => {
println("saveFile: null")
}
case x if x.length == 0 => {
println("saveFile: empty file")
}
case _ => {
println("saveFile: default")
}
}
}

}


On my Mapper object I use CRUDify and mixin the above trait.

The overridden _toForm renders fine, but when I select a file and
"create" my CRUDified instance I see that the method saveFile is not
invoked. Why?


thanks.

David Pollak

unread,
Dec 6, 2010, 11:08:04 AM12/6/10
to lif...@googlegroups.com
You can't use CRUDify with multi-part MIME uploads and multi-part MIME is required for file upload.  Sorry.


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

Hannes

unread,
Dec 6, 2010, 11:10:19 AM12/6/10
to lif...@googlegroups.com
Okay, thanks.

So this means this is a limitation of CRUDify and in case I wanna have uploads I need to make my own Snippet?
You can't use CRUDify with multi-part MIME uploads and multi-part MIME is required for file upload.ᅵ Sorry.

On Mon, Dec 6, 2010 at 7:08 AM, Hannes <hannes...@gmx.li> wrote:
I have a problem with SHtml.fileUpload.

My code looks like this:

trait IViewable extends BaseLongKeyedMapper {

ï¿œobject image extends MappedBinary(this.asInstanceOf[MapperType]) {
ᅵ override def dbDisplay_? = false
ᅵ}

ï¿œobject imagePath extends MappedBinary(this.asInstanceOf[MapperType]) {
ᅵ def notEmpty(input: String) = {
ᅵ ᅵ println("input=" + input)
ᅵ ᅵ if (input.isEmpty) {
ᅵ ᅵ ᅵ List(FieldError(this, "Choose a file!"))
ᅵ ᅵ }
ᅵ ᅵ else Nil
ᅵ }
ᅵ override def _toForm = {
ᅵ ᅵ Full(SHtml.fileUpload(saveFile _))
ᅵ }
ᅵ override def displayName = "BILD"
ᅵ //override def validations = notEmpty _ :: Nil
ᅵ}

ï¿œprivate def saveFile(fp: FileParamHolder): Unit = {
ᅵ println("*** saveFile ***")
ᅵ fp.file match {
ᅵ ᅵ case null => {
ᅵ ᅵ ᅵ println("saveFile: null")
ᅵ ᅵ }
ᅵ ᅵ case x if x.length == 0 => {
ᅵ ᅵ ᅵ println("saveFile: empty file")
ᅵ ᅵ }
ᅵ ᅵ case _ => {
ᅵ ᅵ ᅵ println("saveFile: default")
ᅵ ᅵ }
ᅵ }
ᅵ}


}


On my Mapper object I use CRUDify and mixin the above trait.

The overridden _toForm renders fine, but when I select a file and "create" my CRUDified instance I see that the method saveFile is not invoked. Why?


thanks.

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

David Pollak

unread,
Dec 6, 2010, 11:24:02 AM12/6/10
to lif...@googlegroups.com
On Mon, Dec 6, 2010 at 8:10 AM, Hannes <hannes...@gmx.li> wrote:
Okay, thanks.

So this means this is a limitation of CRUDify and in case I wanna have uploads I need to make my own Snippet?

Yes.
 

You can't use CRUDify with multi-part MIME uploads and multi-part MIME is required for file upload.  Sorry.

On Mon, Dec 6, 2010 at 7:08 AM, Hannes <hannes...@gmx.li> wrote:
I have a problem with SHtml.fileUpload.

My code looks like this:

trait IViewable extends BaseLongKeyedMapper {

 object image extends MappedBinary(this.asInstanceOf[MapperType]) {
  override def dbDisplay_? = false
 }

 object imagePath extends MappedBinary(this.asInstanceOf[MapperType]) {
  def notEmpty(input: String) = {
    println("input=" + input)
    if (input.isEmpty) {
      List(FieldError(this, "Choose a file!"))
    }
    else Nil
  }
  override def _toForm = {
    Full(SHtml.fileUpload(saveFile _))
  }
  override def displayName = "BILD"
  //override def validations = notEmpty _ :: Nil
 }

 private def saveFile(fp: FileParamHolder): Unit = {
  println("*** saveFile ***")
  fp.file match {
    case null => {
      println("saveFile: null")
    }
    case x if x.length == 0 => {
      println("saveFile: empty file")
    }
    case _ => {
      println("saveFile: default")
    }
  }
 }

}


Michael Lex

unread,
Dec 6, 2010, 3:06:01 PM12/6/10
to lif...@googlegroups.com
As a workaround, you could add the following to your MetaMapper object:

override def _createTemplate = super._createTemplate % new
UnprefixedAttribute("multipart", Text("yes"), Null)

It will add the required multipart="yes" to the snippet tag in the create-
template.

While looking through the code, I found the property uploadField_? of the
class BaseField (BaseField.scala:103). Unfortunately this property is not used
by Crudify (It's only used in the Screen library). I will try to write a patch
for this (and add a ticket).

Regards,
Michael

signature.asc

Hannes

unread,
Dec 6, 2010, 5:38:23 PM12/6/10
to lif...@googlegroups.com
Wow, that would be really cool!

I thought about how I gonna write all my Snippets, cause at the moment they're all build with CRUDify...

thanks.

Hannes

unread,
Dec 7, 2010, 2:27:10 PM12/7/10
to lif...@googlegroups.com
I tried that one out, but I got an compiler error:

error: not found: type UnprefixedAttribute

Its not part of the 2.1 API docs neither part of CRUDify...?

By the way, I saw that there's a LongCRUDify trait which should be used with LongKeyedMetaMappers. I use a LongKeyedMetaMappers but with the "old" CRUDify, is that a problem?


thanks.

Michael Lex

unread,
Dec 7, 2010, 5:03:52 PM12/7/10
to lif...@googlegroups.com
> I tried that one out, but I got an compiler error:
> error: not found: type UnprefixedAttribute
> Its not part of the 2.1 API docs neither part of CRUDify...?
It's part of the scala xml library. "import xml.UnprefixedAttribute" should be
enough.


> By the way, I saw that there's a LongCRUDify trait which should be used
> with LongKeyedMetaMappers. I use a LongKeyedMetaMappers but with the
> "old" CRUDify, is that a problem?

LongCRUDify is the same as CRUDify[Long], so I don't think there is a problem
in using either one

signature.asc

Uruhara

unread,
Dec 7, 2010, 10:45:33 PM12/7/10
to Lift
A limitation but surely something that can be extended?

On Dec 6, 11:10 am, Hannes <hannes.flo...@gmx.li> wrote:
> Okay, thanks.
>
> So this means this is a limitation of CRUDify and in case I wanna have
> uploads I need to make my own Snippet?
>
>
>
>
>
>
>
> > You can't use CRUDify with multi-part MIME uploads and multi-part MIME
> > is required for file upload.  Sorry.
>
> > On Mon, Dec 6, 2010 at 7:08 AM, Hannes <hannes.flo...@gmx.li
> > <mailto:hannes.flo...@gmx.li>> wrote:
>
> >     I have a problem with SHtml.fileUpload.
>
> >     My code looks like this:
>
> >     trait IViewable extends BaseLongKeyedMapper {
>
> >      object image extends MappedBinary(this.asInstanceOf[MapperType]) {
> >       override def dbDisplay_? = false
> >      }
>
> >      object imagePath extends
> >     MappedBinary(this.asInstanceOf[MapperType]) {
> >       def notEmpty(input: String) = {
> >         println("input=" + input)
> >         if (input.isEmpty) {
> >           List(FieldError(this, "Choose a file!"))
> >         }
> >         else Nil
> >       }
> >       override def _toForm = {
> >         Full(SHtml.fileUpload(saveFile _))
> >       }
> >       override def displayName = "BILD"
> >       //override def validations = notEmpty _ :: Nil
> >      }
>
> >      private def saveFile(fp: FileParamHolder): Unit = {
> >       println("*** saveFile ***")
> >       fp.file match {
> >         case null => {
> >           println("saveFile: null")
> >         }
> >         case x if x.length == 0 => {
> >           println("saveFile: empty file")
> >         }
> >         case _ => {
> >           println("saveFile: default")
> >         }
> >       }
> >      }
>
> >     }
>
> >     On my Mapper object I use CRUDify and mixin the above trait.
>
> >     The overridden _toForm renders fine, but when I select a file and
> >     "create" my CRUDified instance I see that the method saveFile is
> >     not invoked. Why?
>
> >     thanks.
>
> >     --
> >     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
> >     <mailto:lif...@googlegroups.com>.
> >     To unsubscribe from this group, send email to
> >     liftweb+u...@googlegroups.com
> >     <mailto:liftweb%2Bunsu...@googlegroups.com>.
> >     For more options, visit this group at
> >    http://groups.google.com/group/liftweb?hl=en.
>
> > --
> > Lift, the simply functional web frameworkhttp://liftweb.net
> > Beginning Scalahttp://www.apress.com/book/view/1430219890

Hannes

unread,
Dec 8, 2010, 2:35:34 AM12/8/10
to lif...@googlegroups.com
Thanks, I forgot the standard library...

Michael Lex

unread,
Dec 8, 2010, 8:54:02 AM12/8/10
to lif...@googlegroups.com

David Pollak

unread,
Dec 8, 2010, 9:00:12 AM12/8/10
to lif...@googlegroups.com
On Wed, Dec 8, 2010 at 5:54 AM, Michael Lex <mich...@gmail.com> wrote:
I just added the ticket:
https://www.assembla.com/spaces/liftweb/tickets/761-allow-file-uploads-with-crudify

And I just closed it as invalid.

Please do not open tickets without discussing them first.

Crudify is a starting point, not a kitchen sink of all possible features.
 

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

Hannes

unread,
Dec 8, 2010, 10:01:54 AM12/8/10
to lif...@googlegroups.com
Hi Michael,

I'm just trying out your suggested workaround and so far it seems to work.

thanks!
Reply all
Reply to author
Forward
0 new messages