Thursday, July 25, 2013

Tapestry 5.4: An Avalanche of Fixed Issues

I've been working through the Tapestry issue list over the last couple of days; I'm closing a lot of duplicate and invalid bugs, and fixing some low-hanging fruit. Still, the number of fixed bugs already is impressive:

Bug

  • [TAP5-800] - Server side error during provideCompletions event for Autocompleter mixin is not reported on the client side properly
  • [TAP5-860] - JavaScript errors when adding validations to checkboxes
  • [TAP5-986] - A request can fail with an NPE in some cases, when a Tapestry page is acting as the servlet container error page
  • [TAP5-1010] - Fix Finnish validation message translation - corrected file attached
  • [TAP5-1193] - tapestry.js prevents using the back/forward browser cache
  • [TAP5-1200] - Nested Ajax calls result in a call to $T(null)
  • [TAP5-1569] - Grid should implement the ClientElement interface
  • [TAP5-1601] - Sometime a method that references a field with a conduit will not be instrumented, resulting in an NPE accessing the field itself
  • [TAP5-1668] - JavaDoc for @Parameter.value() should be clearer about the empty string
  • [TAP5-1691] - AssetPathConstructorImpl should URL-encode the application version
  • [TAP5-1704] - Localizing the "Today" and "None" labels in the core datefield component
  • [TAP5-1729] - Sometimes YUICompressor can fail with java.util.EmptyStackException
  • [TAP5-1734] - Race condition loading JavaScript libraries with ProgressiveDisplay
  • [TAP5-1735] - Most packages lack package-level javadocs
  • [TAP5-1742] - AfterRender() in Loop component should not short circuit
  • [TAP5-1762] - Some components do not have include a description of their parameters in their JavaDoc pages
  • [TAP5-1765] - PerThread scope is not honored when service is created using autobuild
  • [TAP5-1768] - @ActivationRequestParameter does not encode to be URL friendly
  • [TAP5-1770] - PageTester causes StringIndexOutOfBoundsException for any page request path with query parameter
  • [TAP5-1773] - FormFieldFocus mixin passes control name, not client id, to JavaScriptSupport.autofocus()
  • [TAP5-1779] - Tapestry allows directory listing of assets via client browser
  • [TAP5-1784] - Extra comma in tapestry-messages_de.js causes Internet Explorer to fail to work
  • [TAP5-1785] - Exceptions while compressing JavaScript are not fully reported
  • [TAP5-1787] - TextField should be usable with HTML5 type values (such as "number", "email", etc.)
  • [TAP5-1788] - Service id 'environment' has already been defined by org.apache.tapestry5.services.TapestryModule with Spring 3.1
  • [TAP5-1791] - On some JDKs, the complex regular expression used by ComponentEventLinkEncoderImpl will cause a stack overflow
  • [TAP5-1798] - Grid and BeanDisplay should ignore properties that are actually static fields
  • [TAP5-1822] - LinkSecurity should be public, not internal, as it is used with the public Link interface
  • [TAP5-1825] - Incorrect order of parameter in localization messages within ValidationMessages Italian lang
  • [TAP5-1831] - DelegatingInjectionResources does not pass generic type information to its first delegate
  • [TAP5-1836] - "LocalhostOnly" WhitelistAnalyzer check "0:0:0:0:0:0:0:1%0" ip address instead "0:0:0:0:0:0:0:1"
  • [TAP5-1844] - Datefield not fires onchange event on changes
  • [TAP5-1848] - tapestry-jpa ignores persistence provider from persistence.xml
  • [TAP5-1854] - AjaxComponentEventRequestHandler doesn't handle the case where a response has already be returned, and may append an empty JSON Object to the response
  • [TAP5-1860] - Access to protected component fields does not always reflect in subclasses
  • [TAP5-1868] - SRSCachingInterceptor returns compressed version of asset for all clients once it was compressed for some client
  • [TAP5-1870] - javascript added while in the render phase of a component from an ajax request is never executed
  • [TAP5-1873] - JavaScript execution exception is not logged
  • [TAP5-1880] - GZip compression should be disabled if the request is over http 1.0
  • [TAP5-1881] - TypeCoercion from Number to Boolean returns false for any number that is an even multiple of 256
  • [TAP5-1887] - Client-side JavaScript error if console.info/debug/... is available but not a function
  • [TAP5-1890] - PlaceholderBlock should implement RenderCommand
  • [TAP5-1892] - FormFragment validates non-displayed fragments (reopen)
  • [TAP5-1903] - Client-side exception when a Zone containing a Form with an Upload component is re-rendered
  • [TAP5-1906] - Interaction between client-side validation and submit buttons can result in a server-side error parsing JSON array
  • [TAP5-1907] - Client exception in IE9 when partial page render introduces stylesheets
  • [TAP5-1911] - Tree leaf is still not selectable
  • [TAP5-1926] - PropertyDisplayBlocks Date's display block is not thread safe
  • [TAP5-1929] - High contention in method InternalComponentResourcesImpl.postRenderCleanup() and NamedSet.getValues()
  • [TAP5-1931] - Alerts can not be dismissed in IE8.
  • [TAP5-1933] - Email validation should use a different regular expression
  • [TAP5-1935] - ContextResource uses a deprecated File.toURL
  • [TAP5-1937] - removeCookieValue with custom path
  • [TAP5-1938] - The ValueEncoder for JPA entity types should encode transient instances as null rather than throw an exception
  • [TAP5-1945] - Clojure integration breaks if tapestry-core is on the classpath
  • [TAP5-1949] - Alerts component does not show alerts added from a component that occurs later in the template
  • [TAP5-1950] - ResourceStreamer sends SC_NOT_MODIFIED as an error, but it should be just status
  • [TAP5-1952] - JavaScript Compressor should log warnings as well as errors, and identify the input clearly
  • [TAP5-1956] - Tapestry.ZoneManager creates memory leaks
  • [TAP5-1960] - @javax.annotations.Inject on a field, without @Named, does not inject service resources
  • [TAP5-1963] - Original exception lost in CommitAfterWorker upon abort
  • [TAP5-1964] - In production mode, placeholder timestamp needs to be limited to one-second accuracy
  • [TAP5-1969] - Excessive warnings from YUICompressor
  • [TAP5-1973] - :443 added to URLs when using the Link.toAbsoluteURI(true)
  • [TAP5-1976] - XML Parser adds attributes with default values and produces invalid HTML5 markup
  • [TAP5-1977] - Memory leak (perm gen) in component reloading
  • [TAP5-1979] - Changing the implementation of a method after adding method advice does not work; the original implementation remains
  • [TAP5-1983] - PerThreadManager does not cleanup on shutdown, can lead to memory leaks when application redeployed
  • [TAP5-1984] - Adding alerts doesn't work during ajax rendering
  • [TAP5-1985] - Clicking Alert component's "dismiss all" link scrolls to top of page
  • [TAP5-1988] - Tapestry Security Violations
  • [TAP5-1991] - YUICompressor should be less verbose about common warnings
  • [TAP5-1992] - Switch YUICompressor dependency back to com.yahoo version 2.4.7
  • [TAP5-1995] - Tapestry5 Application can not be deployed as Tomcat7 HotDeploy Package
  • [TAP5-2001] - Race condition while loading javascript file via ajax
  • [TAP5-2004] - Tapestry-Ioc fails to build on Windows (ReloadTest.java)
  • [TAP5-2008] - Serialized object data stored on the client should be HMAC signed and validated
  • [TAP5-2009] - Downgrade bundled Prototype version back to 1.7
  • [TAP5-2010] - Broken links in Javadoc pages
  • [TAP5-2014] - Zone highlight leaves behind an explicit background-color which overrides css background-color
  • [TAP5-2015] - Tomcat .war path is not decoded properly
  • [TAP5-2017] - Triggerfragment Mixin does not work when used within a table element for IE7
  • [TAP5-2025] - Duplicate generated ids
  • [TAP5-2034] - When the application operates with a context path, asset URLs are incorrectly formed
  • [TAP5-2037] - ValidationTracker/Flash persistence race condition with AJAX
  • [TAP5-2040] - TapestryAppInitializer should have access to system properties; this is a reversion in 5.4
  • [TAP5-2041] - Links within subheadings are invisible on Javadoc pages
  • [TAP5-2045] - Set default CSS class for Label component to be "control-label", but allow overrides
  • [TAP5-2047] - ElementWrapper#find jQuery implementation is broken if there is no match
  • [TAP5-2049] - Tapestry should provide locking semantics for attributes stored in the session, to prevent multiple simultaneous requests (due to Ajax) from conflicting
  • [TAP5-2052] - tapestry-ioc has a compile dependency on tapestry-test
  • [TAP5-2053] - Use of 'transient' property in alert options breaks JavaScript processors
  • [TAP5-2054] - `dom.js` implementations break when minified
  • [TAP5-2057] - CSS URL rewriting is incomplete
  • [TAP5-2061] - core_**.properties got wrong encoding
  • [TAP5-2062] - Ajax alerts not rendered after a JS call to dismissOne()
  • [TAP5-2064] - Add 'info' style to info alerts
  • [TAP5-2068] - Use <button>, not <a>, tags for the close buttons on alerts
  • [TAP5-2071] - Tapestry should output valid HTML5 when using the HTML5 doctype in templates
  • [TAP5-2073] - AbstractEventContext always emits "null" regardless of what values are defined by subclass
  • [TAP5-2079] - Tapestry should handle the case where the context path is (incorrectly) "/" (not the empty string)
  • [TAP5-2081] - datefield: cannot blank out date value via text input
  • [TAP5-2082] - When the last alert that is removed is transient, the outer container is not removed
  • [TAP5-2084] - Form should decode its link parameters
  • [TAP5-2087] - Checkboxes in forms always return "on" (considered as "checked" server-side)
  • [TAP5-2089] - JavaScript errors when using Autocomplete mixin
  • [TAP5-2092] - Tapestry-mongodb has a compile dependency on tapestry-test
  • [TAP5-2095] - Module assets should not be sent a far-future expires header
  • [TAP5-2101] - BeanEditor should always provide a new BeanValidationContext (JSR-303)
  • [TAP5-2103] - ElementWrapper#text() jQuery implementation does not work
  • [TAP5-2106] - Tapestry incorrectly rewrites CSS urls in a variety of cases
  • [TAP5-2110] - MinLength and MaxLength validators don't import "t5/core/validation"
  • [TAP5-2119] - Depenencies excluded in Gradle build files are not excluded in the generated Maven POMs
  • [TAP5-2120] - StringIndexOutOfBoundsException computing relative paths for certain Resources
  • [TAP5-2121] - Broken image (for Tapestry Logo) in generated documentation page
  • [TAP5-2122] - visible() on empty <div> is false; prevents valiation of Palette component
  • [TAP5-2124] - events.zone.refresh must be triggered directly on zone element, can fail otherwise
  • [TAP5-2125] - Ajax form submissions via jQuery may pass t:formdata as "t:formdata[]" if there are multiple values
  • [TAP5-2126] - TAP5-2063 fix (multi-valued parameters in Link) conflicts with use of ActivationRequestParameter and PageLink.parameters parameter
  • [TAP5-2132] - Generation of documentation for t5/core/dom should use the split (for jQuery, for Prototype) files, not the combined source file
  • [TAP5-2137] - Tree component renders empty nodes as expandable, AssertionError when expanded
  • [TAP5-2141] - Ajax form submission should ignore fields with no name
  • [TAP5-2142] - Exceptions thrown during Ajax processing or validation force a traditional form submission
  • [TAP5-2148] - VersionUtils should close the stream it opens

Improvement

  • [TAP5-336] - The Cookies service interface could be simplified using a builder pattern
  • [TAP5-672] - Translation for Vietnamese
  • [TAP5-1008] - The order in which zones are added to the MultiZoneUpdate should be honored on the client side, to allow nested zones to be updated all in a single request
  • [TAP5-1268] - Have Tapestry's core library contribute to the global message catalog; move all validation messages and component catalogs to the single file
  • [TAP5-1394] - Adding method to Cookies api that lets you set path, domain, and maxAge at once.
  • [TAP5-1405] - XHR requests should be easily callable from javascript and not rely on a zone
  • [TAP5-1560] - Remove internal dependancies on deprecated features
  • [TAP5-1570] - Zone elements in the client should trigger events so that the application can react to changes
  • [TAP5-1748] - Alerts component should render informal parameters
  • [TAP5-1756] - Let the asset path prefix be configurable
  • [TAP5-1775] - Improve javascript performance while creating zone events
  • [TAP5-1781] - Improve javascript load time of pages improving onDomLoadedCallback
  • [TAP5-1801] - Component fields should not need to be private, merely non-public
  • [TAP5-1805] - Selectable Tree component look and feel is lacking in user affordances
  • [TAP5-1808] - Change Form to (by default) immediately render markup when there are validation errors, to avoid creating the session
  • [TAP5-1816] - Add CSS rule for DIV.t-exception-container to default.css that sets a very high z-index
  • [TAP5-1824] - New translations for Norwegian BokmÃ¥l
  • [TAP5-1827] - KaptchaField should have a parameter to allow it to operate as a visible text field rather than a password field
  • [TAP5-1832] - Tapestry could do an even better job of filtering unnecessary stack frames from the exception report
  • [TAP5-1840] - Add method Request.isSessionInvalidated()
  • [TAP5-1847] - An extension component template (with a root t:extend element) should allow t:block elements to be nested
  • [TAP5-1849] - The text "Dismiss All" used in client-side Alerts is not localized or localizable
  • [TAP5-1878] - Default for parameter visible of component KaptchaField should change from false to true
  • [TAP5-1889] - Improve integration test execution speed
  • [TAP5-1905] - Not serializable: org.apache.tapestry5.tree.DefaultTreeExpansionModel - can't persist sessions across cluster
  • [TAP5-1914] - Alerts needs a parameter to show/hide "Dismiss all"
  • [TAP5-1940] - Typo in interface LocalizationSetter.setNonPeristentLocaleFromLocaleName()
  • [TAP5-1970] - JSON API improvements
  • [TAP5-1987] - ProgressiveDisplay update parameter as a symbol
  • [TAP5-1990] - Link interface should be more fluid to allow setting of anchor, etc., more concisely
  • [TAP5-1993] - Support returning an URL for an ajax request
  • [TAP5-1996] - Add Severity.SUCCESS enum for alerts
  • [TAP5-2013] - "Parameters" table often too wide in component javadocs
  • [TAP5-2022] - Add PropertyAccess.getAnnotation
  • [TAP5-2035] - Make it easier to choose another slf4j backend
  • [TAP5-2039] - Element.attribute() should treat "class" specially, appending the new value to the old
  • [TAP5-2046] - Should use OperationTracker to track type of request (ajax component event, traditional component event, page render request)
  • [TAP5-2050] - Grid sort icons should be added via CSS instead of rendering an embedded img element
  • [TAP5-2051] - Fix Plastic objects memory leaks
  • [TAP5-2058] - Support X-Forwarded-Proto to identify a Request secured (https)
  • [TAP5-2063] - Add support for multivalued parameters in Link
  • [TAP5-2102] - Allow supplying EntityManager properties via TapestryPersistenceUnitInfo
  • [TAP5-2131] - Update Javadoc CSS to reflect changes in the html generate by JDK7

New Feature

  • [TAP5-999] - Implement an agnostic tapestry.js layer + adapters to allow developers to switch from prototype to jquery
  • [TAP5-1168] - Add @Operation annotation that can be used to automatically track a component or service method invocation using the OperationTracker
  • [TAP5-1794] - Allow for configuring Selenium-based integration tests using an annotation
  • [TAP5-1807] - In development mode, Tapestry should include a <meta> tag to identify the active page
  • [TAP5-1809] - Option to render a particular page instance in its current state (without page activation)
  • [TAP5-1833] - Merge functionality of Tynamo.org's tapestry-exceptionpage module with the built-in ExceptionHandler
  • [TAP5-1843] - Allow all of the properties of the Messages services to be accessed
  • [TAP5-1857] - Add a SubmitMode (for Submit and LinkSubmit components) for unconditionally submitting the form
  • [TAP5-1944] - Add basic integration between Tapestry and Clojure
  • [TAP5-2055] - Polish translations
  • [TAP5-2065] - Introduce support for MongoDB access as a service
  • [TAP5-2094] - E-Tags support

Task

  • [TAP5-1518] - Remove ClassFactory / ClassFab / Javassist Dependency
  • [TAP5-1780] - Upgrade Selenium dependency to 2.14.0
  • [TAP5-1790] - Update Tapestry build to create a binary release archive (in addition to a source and javadoc archive)
  • [TAP5-1792] - Upgrade Tapestry/Spring integration to Spring 3.1.0.RELEASE
  • [TAP5-1810] - Remove deprecated "suppress redirects from action" code
  • [TAP5-1826] - Setup the Sonar plugin to let analysis.apache.org analyze the source base
  • [TAP5-1852] - Upgrade Plastic to use ASM 4.0
  • [TAP5-1909] - Update Underscore JavaScript library to latest version 1.3.3
  • [TAP5-1922] - Upgrade Hibernate dependency to latest, Hibernate 4.1.2.Final
  • [TAP5-1965] - Replace use of Request.getContextPath() with a symbol defined at application startup
  • [TAP5-1989] - Upgrade bundled Prototype to version 1.7.1

Thursday, July 18, 2013

Closing in on Tapestry 5.4

We're getting very close to a beta release of Tapestry 5.4. I've spent the last couple of weeks converting an existing client's very large application (120+ pages, tons of components, lots of client-side JavaScript) from 5.3 to the current 5.4 alpha, and it's been a lot of work ... but also a lot of reward.

Before the switch, the application was already using jQuery, Bootstrap, and a limited amount of Backbone; under Tapestry 5.3, that means that Prototype and Scriptaculous were also in the mix ... and there were quite a few conflicts between Prototype and jQuery.

It's not just that Prototype and jQuery both want to use window.$ as their point of entry; the conflicts can be deeper and more subtle. For example, I had a nasty time with a Boostrap modal dialog that didn't dismiss correctly. After a lot of debugging, I found out that jQuery treats a method on an element as an event handler for the event with the matching name; Bootstrap was triggering a hide event, and jQuery was invoking the hide() Element method added by Prototype. That kind of thing has been my life under the mixed stack.

Tapestry 5.4 manages this better; and with the new abstraction layer it is possible to turn off Prototype completely and use just jQuery. That removes these conflicts ... and also speeds things up, but reducing the amount of JavaScript code downloaded to the client.

The transition from 5.3 to 5.4 was a chance to review and improve all that code. Here's a few observations.

The application has some very complex client-side forms; well beyond the abilities of Tapestry to manage using the FormInjector and FormFragment components. Instead, we use Backbone is a kind of hybrid mode, where the Backbone Model or Collection is persisted to a hidden field, so that the data collected or edited is transmitted to the server as part of an over-all form submission.

Of course, this means creating a lot of content, including form control elements, on the fly. One of the main problem was integrating Tapestry's client-side validation for the newly created fields.

Under 5.3, this required examining and often hacking (or monkey patching) the Tapestry client-side code, which create FormEventManager and FieldEventManager objects for each form or form control element ... and there was lots of hackery to tap into the form's submission cycle to perform validations.

Under 5.4 it is much easier, when creating the new fields, we can specify the desired validations via attributes:

The data-validation attribute indicates the field participates in validation; it will have events triggered on it when the enclosing form submits. The t5/core/validation module supplies the code that handles fields with data-optionality="required" and ensures that a value is provided, displaying the data-required-message if the field is left blank.

That's the pattern throughout 5.4; data- attributes are used to identify where special behavior is desired, and a well documented system of events is used handle the processing of the behavior.

Very little on the server side changed with the upgrade to 5.4; but revisiting and rewriting all that JavaScript was more than enough work!

In addition, it was an opportunity to convert all the code to CoffeeScript. CoffeeScript is my preferred way of writing client-side code: it is more concise and readable than JavaScript, but the compiled output is still quite readable. It also has great features like the block strings (from the example code above) which largely eliminates the need for a separate template engine.

Working in CoffeeScript and Tapestry so much led to some quick evolution of the CoffeeScript support built into Tapestry (in the optional tapestry-wro4j module). Initially, any change to any CoffeeScript file forced all CoffeeScript files to be recompiled; when using the sluggish Rhino JavaScript engine to run the CoffeeScript compiler, we could see 10 - 20 seconds per source file!

I made some improvements, adding a special development-mode in-memory cache that would only recompile the CoffeeScript if the underlying source file content had changed. Since application restarts are rare in Tapestry, this was sufficient. I eventually added a file-system cache so that compilation could be avoided, even over restarts of the application.

I also started using Less instead of CSS. Less is a meta-language that compiles down to CSS, much like the relationship between CoffeeScript and JavaScript ... but I think even more dramatically. Compilation is pretty fast, based on the Less4J library.

I found that the out-of-the-box support for Less4J supplied by WRO4J was insufficient: it didn't do a great job with @import; a change to an imported source file didn't force a recompilation. I've addressed that with a custom (for Tapestry) wrapper that properly tracks dependencies.

So where does that leave us? There's still a huge amount of work to do before Tapestry 5.4 is ready for release, but it's mostly fixing bugs and other rough edges. As too often happens, the reality of earning a living have made me postpone some of my ideas for a later release.

I think that Tapestry is aging, if not gracefully, then at least comfortably, into a growing age where rich, single-page applications built with Backbone, AngularJS, or something else are the norm, and not the exception. I'm the first to admit that Tapestry was designed for a simpler time when Ajax was seasoning, not the meat-and-potatoes of the application. There's a lot of baggage in there, particularly related to forms and form controls. Yet, even so, there's some amazingly useful parts to Tapestry that apply equally well to modern applications:

Asset Pipeline
Tapestry's asset pipeline does much of the work normally associated with a command-line build step, but does it at runtime, with the benefit of being live for development. Tapestry can not only compile files from one type to another (e.g., CoffeeScript to JavaScript), but can also aggregate many small files into a single combined file and pass it through a minimizer. Further, Tapestry builds URLs that incorporate a content checksum. This checksum means that we can have the browser aggressively cache the file (using both E-Tags and a far-future expires header) as any change to the file will change the checksum as well, resulting in what looks to the client like an entirely new resource. Further, Tapestry caches both the straight-up file, and the GZip compressed version of the file. All of this means that Tapestry provides not just great throughput by processing requests quickly, but also great performance by reducing the number of requests from clients as well.
Asynchronous Module Definition (AMD) Support
Tapestry 5.4 introduces direct support for AMD via RequireJS. At the minimum, this means that JavaScript can be loaded in parallel ... but the real benefit is how AMD encourages you to organize your code in a manageable way. In addition, Tapestry ensures that your modules can be JavaScript or CoffeeScript, and provides a simple way on the server to override any built-in modules provided by Tapestry, should the need arise. Better yet, Tapestry has a server-side API for invoking client-side functions exported by AMD modules; these is a very clean and very useful way to knit together server-side and client-side logic.
Superior Feedback and Exception Reporting
When working on other stacks, the thing I miss the most now is Tapestry's exception reporting. This is cleanly integrated in Tapestry, where a server side failure will result in a detailed HTML report on the client. For Ajax requests, this report is presented in a floating <iframe>. The wealth of information available from the server side and reported directly in the client makes developing complex applications with involved server-side interaction much easier.

As Tapestry 5.4 transitions to beta, and to an eventual final release, I'm still targeted on the future ... and I'm focused on making Tapestry be a great choice for single-page apps as well as traditional applications. My head is bubbling with ideas to make this happen.