Skip to content
Browse files

A collection of minor updates

1. Some old edits I've had on my todo list for a long
time concerning typos, code clarification, etc
2. An update on file upload handling describing the new
OnDiskFileParamHolder capability
3. An update on XML binding with the "_id_>" operator
  • Loading branch information...
1 parent 7818618 commit 228f9e881f72cfccf85157769a34721aef70836d @dchenbecker dchenbecker committed Aug 23, 2010
Showing with 343 additions and 35 deletions.
  1. +2 −2 chap-demoapp.lyx
  2. +200 −29 chap-forms.lyx
  3. +141 −4 chap-snippets.lyx
View
4 chap-demoapp.lyx
@@ -1672,7 +1672,7 @@ class AddEntry extends StatefulSnippet {
\begin_layout Plain Layout
- error("We're going to need at least one tag.")
+ S.error("We're going to need at least one tag.")
\end_layout
\begin_layout Plain Layout
@@ -1821,7 +1821,7 @@ class AddEntry extends StatefulSnippet {
\begin_layout Plain Layout
- notice("Entry added!")
+ S.notice("Entry added!")
\end_layout
\begin_layout Plain Layout
View
229 chap-forms.lyx
@@ -1549,16 +1549,6 @@ name "lst:Using-multiselect"
\begin_layout Plain Layout
-import scala.collection.mutable.Set
-\end_layout
-
-\begin_layout Plain Layout
-
-...
-\end_layout
-
-\begin_layout Plain Layout
-
def mySnippet ...
{
\end_layout
@@ -1575,7 +1565,7 @@ def mySnippet ...
\begin_layout Plain Layout
- val updated = Set.empty[Category]
+ var updated = Set.empty[Category]
\end_layout
\begin_layout Plain Layout
@@ -2002,6 +1992,26 @@ name "sec:File-Uploads"
\end_inset
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+File uploads
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Forms ! File uploads
+\end_layout
+
+\end_inset
+
+
\end_layout
\begin_layout Standard
@@ -2141,11 +2151,73 @@ fileUpload
FileParamHolder
\family default
, a special case class that contains information about the uploaded file.
- Unlike some other web frameworks, Lift doesn't store the file on the local
- system and then give you the filename; instead, Lift reads the whole file
- into memory and gives you the array of bytes to work with.
- Usually this isn't an issue, since the web server itself will have meaningful
- limits on POST sizes.
+ The FileParamHolder case class has four parameters:
+\end_layout
+
+\begin_layout List
+\labelwidthstring 00.00.0000
+
+\family typewriter
+name
+\family default
+ The name of the form field that this file is associated with, as sent by
+ the client
+\end_layout
+
+\begin_layout List
+\labelwidthstring 00.00.0000
+
+\family typewriter
+mimeType
+\family default
+ The mime type as sent by the client
+\end_layout
+
+\begin_layout List
+\labelwidthstring 00.00.0000
+
+\family typewriter
+filename
+\family default
+ The filename as sent by the client
+\end_layout
+
+\begin_layout List
+\labelwidthstring 00.00.0000
+
+\family typewriter
+file
+\family default
+ An
+\family typewriter
+Array[Byte]
+\family default
+ containing the uploaded file contents
+\end_layout
+
+\begin_layout Standard
+In our example, we want to save the file data into a
+\family typewriter
+MappedBinary
+\family default
+ field on our expense entry.
+ You could just as easily process the data in place using a
+\family typewriter
+scala.io.Source
+\family default
+ or
+\begin_inset Newline linebreak
+\end_inset
+
+
+\family typewriter
+java.io.ByteArrayInputStream
+\family default
+, or output it using a
+\family typewriter
+java.io.FileOutputStream
+\family default
+.
\end_layout
\begin_layout Standard
@@ -2210,7 +2282,12 @@ class AddEntry {
\begin_layout Plain Layout
- // Add the optional receipt if it's the correct type
+ val e : Expense = ...
+\end_layout
+
+\begin_layout Plain Layout
+
+ // Add the optional receipt if it's the correct type
\end_layout
\begin_layout Plain Layout
@@ -2220,6 +2297,16 @@ class AddEntry {
\begin_layout Plain Layout
+ // An empty upload gets reported with a null mime type,
+\end_layout
+
+\begin_layout Plain Layout
+
+ // so we need to handle this special case
+\end_layout
+
+\begin_layout Plain Layout
+
case Full(FileParamHolder(_, null, _, _)) => true
\end_layout
@@ -2347,28 +2434,112 @@ class AddEntry {
\end_layout
\begin_layout Standard
-In our example, we want to save the file data into a
+By default
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Forms ! saving file uploads to disk
+\end_layout
+
+\end_inset
+
+, Lift will utilize the
\family typewriter
-MappedBinary
+InMemoryFileParamHolder
\family default
- field on our expense entry.
- You could just as easily process the data in place using a
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+InMemoryFileParamHolder
+\end_layout
+
+\end_inset
+
+to represent uploaded file data.
+ This implementation reads the uploaded data directly into memory (you retrieve
+ the byte array with the
\family typewriter
-scala.io.Source
+file
\family default
- or
-\begin_inset Newline linebreak
+ val).
+ If you would prefer to have Lift write uploaded data to disk and then give
+ you a server-local filename to work with, you can use the
+\family typewriter
+LiftRules.handleMimeFile
+\family default
+ configuration hook to instead use the
+\family typewriter
+OnDiskFileParamHolder
+\family default
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+OnDiskFileParamHolder
+\end_layout
+
\end_inset
-
+, as shown in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Using-OnDiskFileParamHolder"
+
+\end_inset
+
+.
+ The OnDiskFileParamHolder class has an additional property,
\family typewriter
-java.io.ByteArrayInputStream
+localFile
\family default
-, or output it using a
+, that is a
\family typewriter
-java.io.FileOutputStream
+java.io.File
\family default
-.
+ object for the temporary upload file.
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Using-OnDiskFileParamHolder"
+
+\end_inset
+
+Using OnDiskFileParamHolder
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+// in Boot.boot:
+\end_layout
+
+\begin_layout Plain Layout
+
+LiftRules.handleMimeFile = OnDiskFileParamHolder.apply
+\end_layout
+
+\end_inset
+
+
\end_layout
\end_body
View
145 chap-snippets.lyx
@@ -1103,7 +1103,6 @@ status open
\begin_inset Caption
\begin_layout Plain Layout
-
Defining an Explicit Snippet Object
\begin_inset CommandInset label
LatexCommand label
@@ -1280,7 +1279,6 @@ status open
\begin_inset Caption
\begin_layout Plain Layout
-
Binding Our Explicit Snippet Object
\begin_inset CommandInset label
LatexCommand label
@@ -1534,7 +1532,6 @@ status open
\begin_inset Caption
\begin_layout Plain Layout
-
Remapping A Snippet
\begin_inset CommandInset label
LatexCommand label
@@ -2936,7 +2933,6 @@ status open
\begin_inset Caption
\begin_layout Plain Layout
-
Explicit Dispatch with Stateful Snippets
\begin_inset CommandInset label
LatexCommand label
@@ -3697,5 +3693,146 @@ myId
>Sat Mar 28 16:43:48 EET 2009</span>
\end_layout
+\begin_layout Standard
+In addition to the
+\begin_inset Quotes eld
+\end_inset
+
+-%>
+\begin_inset Quotes erd
+\end_inset
+
+ binding operator, there is also the
+\begin_inset Quotes eld
+\end_inset
+
+_id_>
+\begin_inset Quotes erd
+\end_inset
+
+ operator, which uses the element's name as its
+\begin_inset Quotes eld
+\end_inset
+
+id
+\begin_inset Quotes erd
+\end_inset
+
+ attribute.
+ Listing shows a snippet method using the
+\begin_inset Quotes eld
+\end_inset
+
+_id_>
+\begin_inset Quotes erd
+\end_inset
+
+ attribute and Listing shows the resulting markup.
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Binding-with-the_id_"
+
+\end_inset
+
+Binding with the _id_> operator
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+def idByName (xhtml : NodeSeq) : NodeSeq =
+\end_layout
+
+\begin_layout Plain Layout
+
+ bind("example", xhtml, "name" _id_> <span>Fred</span>)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language=XML"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Markup-bound-using_id_"
+
+\end_inset
+
+Markup bound using _id_>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+<!-- Input: -->
+\end_layout
+
+\begin_layout Plain Layout
+
+<lift:HelloWorld.idByName>
+\end_layout
+
+\begin_layout Plain Layout
+
+ Hi, <example:name />
+\end_layout
+
+\begin_layout Plain Layout
+
+</lift:HelloWorld.idByName>
+\end_layout
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\begin_layout Plain Layout
+
+<!-- Output: -->
+\end_layout
+
+\begin_layout Plain Layout
+
+Hi, <span id="name">Fred</span>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
\end_body
\end_document

0 comments on commit 228f9e8

Please sign in to comment.
Something went wrong with that request. Please try again.