Download presentation
Presentation is loading. Please wait.
Published byPhilomena Douglas Modified over 8 years ago
1
Scripting JSF The best of both worlds Ed Burns Senior Staff Engineer Enterprise Java Platforms
2
2 Presentation Goals Share my opinion on scripting and server side applications Explain how scripting can benefit JSF developers Illustrate the power and flexibility of JSF
3
3 Agenda Historical Context > The Past is the Future? > Why Bother with Scripting? Let's Visit Phobos > Introducing Phobos > Combining JSF and Phobos JSF Extensibility
4
4 The Past is the Future? JavaScript > Thanks to Ajax, JavaScript is cool again > JavaScript support comes standard in JDK 6 > Scripting Java started in 1998 with Netscape LiveConnect. Virtual Machines > IBM System/370 from 1960 > Smalltalk-80 > Java VM: ubiquity (abundant) and price (free) are key JSR 223: Scripting for the Java Platform > Application level script interface > JavaScript, Ruby, Python bindings
5
5 Why Bother with Scripting? Benefits > Very malleable > Associative arrays really handy > Dynamically extend the language at runtime > Change design contracts with great fluidity Loose Typing Costs > performance: everything is interpreted every time it is needed > maintainability: lack of type system makes it impossible to concretely express design contracts JavaScriptClasses JavaScript Class Herder
6
6 Why Bother with Scripting? Benefits > Edit->Compile->Deploy->Debug->Repeat becomes Edit->Debug->Repeat > Akin to tuning an engine while it is running Costs > Can have a performance cost, but remember, Java itself is interpreted. > Also, many scripting languages can be sped up with compilation techniques No Deployment Step
7
7 Why Bother with Scripting? Benefits > Historically proven use of scripting: witness Perl > Works well on single host > Easy to get it done quickly Glue it all together Costs > Not so good with for assembling distributed apps > Easy to write obtuse code, and the contracts between system elements are not self evident to maintenance programmer.
8
8 Scripting Opinion Summary Scripting is here to stay Java is taking scripting seriously (no longer sacrilege to run non Java on the JVM JRuby on JVM will Rails apps natively > No I'm not afraid for the future of JSF
9
9 Scripting JavaServer Faces Lightweight Scripting Friendly Web Application environment Aimed at addressing emerging developer requirements Learns from Rails, but may prove to have different sweet spot than Rails: CRUD Let's visit Phobos
10
10 Scripting JavaServer Faces Let's visit Phobos
11
11 Lessons from Rails Directory layout for model, view, controller Naming conventions for mapping URL segments to scripts For example, given this layout controller/calculator.js view/calculator.ejs and an HTTP GET to http://host/calculator/calculator/show means: In the calculator application, find the “calculator” script in the controller directory, and invoke its “show” method. This method is responsible for rendering the view, usually by calling a library function with a view name.
12
12 Lessons from Rails For example, given this layout controller/calculator.js view/calculator.ejs and an HTTP POST to http://host/calculator/calculator/compute means: In the calculator application, find the “calculator” script in the controller directory, and invoke its “compute” method. This method is responsible for accessing the model, performing the calculation, and re-rendering the view, usually by calling a library function with a view name.
13
13 Lessons from Rails Easily mix scripts and markup > Like JSP Scriptlets (remember those?) > Uses simple “Embedded JavaScript” syntax: Status
14
14 Lessons from Rails Easy convention for adding libraries to the core framework > Not nearly as nice as ruby gems, yet. Application lifecycle events > startup shutdown Plans for scaffolding
15
15 Differences from Rails Designed to work with any JSR223 compliant scripting language Extreme ease of calling into Java and back again var builder = new Packages.org.jdom.input.SAXBuilder(); Backed by full power of Java EE JavaScript basis means it is easy to use widget libraries like Dojo, Scriptaculous, (jMaki) etc.
16
16 Combining JSF and Phobos 1)In a Phobos application, with a Phobos controller, use JSF components naturally 2)In a Phobos application, with a Phobos controller, write any JSF artifact in a JSR 223 compliant scripting language a)Managed Beans b)Application Listeners (ValueChangeListener, ActionListener) c)Converter, Validator d)Renderer, UIComponent 3)In a JSF application, with JSF controller, allow any JSF artifact to be written using script: Start out with script, move to Java once design is solid Goals
17
17 Phobos Lifecycle Without JSF
18
18 Phobos Lifecycle Without JSF
19
19 Phobos POST Lifecycle With JSF
20
20 Redirect after POST and JSF “execute” portion of Lifecycle “render” portion of Lifecycle
21
21 Redirect after POST and JSF
22
22 Demonstrations
23
23 Implementation Details ViewHandler: PhobosViewHandler > called by library.jsf.renderAfterRedirect(), and library.jsf.postBeforeRedirect() > Calls back into script to execute proper “.ejs” file > This writes to a buffer, which is tweaked slightly to ensure state saving is properly handled, then handed off to the FaceletViewHandler. This builds and renders the JSF component tree, and handles state saving. JSF Extension Points used
24
24 Implementation Details ELResolver: FlashELResolver > called by library.jsf.renderAfterRedirect(), and library.jsf.postBeforeRedirect() > Is a Map whose entries expire based on the request/response lifecycle. > Concept from Ruby on Rails > Useful in JSF without Phobos as well > Great for “master/detail” > Allows JSF to handle “redirect after POST” JSF Extension Points used
25
25 Implementation Details Map implementation: JavaScriptJavaBeanMap > Allows writing JSF Managed Beans in JavaScript > Can use standard JSF faces-config.xml configuration syntax, but need not do so. > Change properties on the fly > Add new beans on the fly (not yet implemented) > If you put a Map in the scoped namespace, it immediately becomes available to the EL. JSF Extension Points used
26
26 Demonstrations
27
27 Summary Scripting is your friend It's the future, not the past Just because it's scripting, doesn't mean you can't use your old friends, quite the contrary! The extensible design of JSF makes it easy to integrate with Phobos Work is being done 100% in open source. CDDL License: please join! The Best of Both Worlds
28
28 Important Links Project Glassfish http://glassfish.dev.java.net Project Phobos http://phobos.dev.java.net JSF-Extensions, JSF Flash http://jsf-extensions.dev.java.net Project jMaki http://ajax.dev.java.net
29
JSF + Phobos ● Ed Burns – ed.burns@sun.com
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.