lift framework
DESCRIPTION
This presentation is giving a short overview of forms, site map and mappers in the lift framework.TRANSCRIPT
![Page 1: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/1.jpg)
The Lift frameworkat least some parts of
![Page 2: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/2.jpg)
agenda - How we divide
![Page 3: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/3.jpg)
forms in lift
![Page 4: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/4.jpg)
some facts
Standard GET/POST support AJAX and JSON forms support No HTML form tags needed Implement as snippet in Scala Form generated by net.liftweb.http.SHtml
Stateless by default Extend StatefulSnippet Use RequestVars for statefull purpose
![Page 5: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/5.jpg)
some short dive 1 / 2
![Page 6: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/6.jpg)
some short dive 2 / 2
![Page 7: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/7.jpg)
checkbox - text area - password inputs
![Page 8: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/8.jpg)
text area - password inputs
Mostly like standard HTML input elements Generated by Shtml Overload XML with Pair(String, String)
“attribute” → ”value”
![Page 9: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/9.jpg)
checkbox
Not submitted if unchecked
![Page 10: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/10.jpg)
hidden element
Not a plain value like in HTML Defined function is called on submit For logging, debugging or other
calculations
![Page 11: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/11.jpg)
Link - radio - (multi) selection
![Page 12: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/12.jpg)
Link
Like an HTML anchor Defined function is invoked on click Passing objects to linked page
![Page 13: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/13.jpg)
radio button
Set of radio buttons with String labels
![Page 14: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/14.jpg)
(multi) selection
selection List of options as Pair(value, display) Only one item may be selected
multiselection Multiple select or pre-select Callback function proceeds for every returned value
selectObj Handles passed objects as Pair(object, display)
![Page 15: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/15.jpg)
file upload 1/2
Special case of form submission SHtml generates file upload
element with callback File is typed as FileParamHolder
refenced by SHtml Whole file is loaded into
memory on complete
![Page 16: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/16.jpg)
file upload 2/2
![Page 17: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/17.jpg)
site map
![Page 18: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/18.jpg)
site map - facts
Provides a map for your site Not only links and basic menu functionality Nested menus with hierarchies Grouping menus Access control mechanism Request URL rewriting State-dependent computations for page titles,
page-specific snippets, etc.
![Page 19: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/19.jpg)
Basic siteMap 1/2
![Page 20: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/20.jpg)
Basic sitemap 2/2
Creating menu entries with unique Loc reference
Allow access to any pages with help of match
Nested menu holds one or more child menus
![Page 21: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/21.jpg)
customize display of menu
Hide menu entries to restrict access Control menu item text Render menu title Customize menu with help of CSS Add JavaScript functionality Build menu groups
![Page 22: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/22.jpg)
access control
Extending binary control of given request "matches→display" otherwise don't display
If LocParam Test Function evaluates given path Message Function returns failure response
string User redirected to page with display for error
state Unless LocParam Mirrors Test Function of If LocParam
![Page 23: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/23.jpg)
Page-specific Rendering
![Page 24: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/24.jpg)
The mapper and record
frameworks- Making things persistent -
![Page 25: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/25.jpg)
What is persistence?
Wikipedia
“Persistence in computer science refers to the characteristic of data that outlives the execution of the program that created it. Without this capability, data would only exist in RAM, and would be lost when this RAM loses power, such as on computer shutdown. This is achieved in practice by storing the data in non-volatile storage such as a hard drive or flash memory.
”
![Page 26: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/26.jpg)
and mapping?
User
passwort:Stringname:Stringstreet:Stringpostnr:Longint
![Page 27: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/27.jpg)
record vs. mapper
Mapper is original Lift persistenceframework Closely tied to JDBC
Record is new refactorization of Mapper Define own Mapping Strategies (XML, JDBC,
JPA) Mapper will be deprecated as soon as
Records is stable Mapper will be used in this presentation
![Page 28: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/28.jpg)
Extendnet.liftweb.mapper.ConnectionManagertrait
Implement methods: newConnection andreleaseConnection
Get connected
![Page 29: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/29.jpg)
Dbvendor extends connectionManager
name parameterused to havemultiple databases
newConnectionneeds to return a Box[java.sql.Connection]
releaseConnectionused to havecomplete control ofthe connectionlifecycle
Declare object in Boot.scala
Call theDB.defineConnectionManager to bind Manager into theMapper
![Page 30: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/30.jpg)
make my class persistent Class Transaction from the PocketChange application We want to store:
Date Description with a max length of 100 chars Amount of money used in a transaction And a account we want to reference to (described in detail
later)
![Page 31: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/31.jpg)
What have I typed here?
Use LongKeyedMapper trait: Provide primary key for our entity Key should be long IdPK trait implements getPrimaryKeyField-method
Defined as object due to MetaMapper, who needs access forvalidation
getSingleton defines the MetaObject
![Page 32: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/32.jpg)
how to set fields?
Fields are no instance members: Use apply method to set:
Use is to get:
![Page 33: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/33.jpg)
Object relationship - one to many
![Page 34: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/34.jpg)
Object relationship - many to many
![Page 35: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/35.jpg)
Indexing
More complex indexing via usage of theIndex, IndexField and BoundedIndexFieldcase classes
![Page 36: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/36.jpg)
schema mapping
Create database schema according toyour objects
Declared in Boot.scala
![Page 37: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/37.jpg)
Working with entities
MetaMapper is providing a lot ofoperations for an entity:
![Page 38: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/38.jpg)
how to query data
findAll returns all instances Use flag to define criterias to limit search
result (trait QueryParam)
By is used for direct value comparison BySQL let us use plain SQL as where clause
![Page 39: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/39.jpg)
Other Queryparams to search for data
![Page 40: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/40.jpg)
Getting things ordered
![Page 41: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/41.jpg)
from mapping to html
asHTML is rendering the mapper instance„as HTML“.
Overriding for own behaviour eg own date format
![Page 42: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/42.jpg)
from mapping to a form
toForm is making it easy to create a form appropriate to an instance
Third method has a „redo“ snippet parameterto save status User do not have to re-enter everything
![Page 43: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/43.jpg)
from form to validation
Validate submitted data User is not allowed to enter dates in the future
Link function to validation
![Page 44: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/44.jpg)
crud support
Create, read, update, delete: Use CRUDify trait
![Page 45: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/45.jpg)
Doing it oldschool - sql 1/2
findAllByPreparedStatement
findAllByInsecureSql Executes the String you submit directly without
any checks
![Page 46: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/46.jpg)
Doing it oldschool - sql 2/2
DB.runQuery provides support for non-entity SQL queries
![Page 47: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/47.jpg)
Protouser
ProtoUser trait defines some basic fields fora user (email, firstName, lastName, password and superUser)
Already some defs used to format thefields for display or to provide form labels
![Page 48: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/48.jpg)
megaprotouser
Extends the ProtoUser trait Automatically handle all of the scaffolding
for a complete user management system User registration page Login page Lost password page Change password page User edit page Simple method to generate SiteMap
![Page 49: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/49.jpg)
[- Showing some code in eclipse -]
![Page 50: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/50.jpg)
conclusion
Concepts are pretty nice Getting things done very quick out of box
Scala as scripting language makes it mighty Would have been better to do presentations
AFTER project Pretty hard to „give control“ to the framework
(„What is happening in the background?“) Lift book is bad. We would still prefer (G)Rails due to better
tooling and experience
![Page 51: Lift Framework](https://reader031.vdocument.in/reader031/viewer/2022020115/55557336b4c9055f5f8b4a82/html5/thumbnails/51.jpg)
Disclaimer
All images in this presentation are downloaded from flickr.com and marked with the creativecommons licence forcommercial use.
This presentation is restricted with the creativecommons licence (http://creativecommons.org/licenses/by-nd/3.0/de/deed.en):