How to compile facelets? - java

Many times I had errors like:
-tag is not closed(xml error)
-xhtml has duplicated id
Id like to write validator to check is those errors exist in files. I bet there is some facelets compiler that compile xhtml into java classes and than validates it.

Eclipse WTP, although not being the best thing out there, has some validation for .xhtml / .jsp files. You can try the corresponding editor in NetBeans or IntelliJ.
If checking the validity by opening the page takes you too much time (due to slow redeployment), consider sending the page to the servlet container on save - either using WTP dynamic project, deployed on a server, or via the FileSync plugin.

Have you considered using a good XML editor? It will catch the bad XML.
I also believe that schema aware XML editors will catch that id's must be unique.

You can't "compile" them, but if working with Seam on JBoss, just by saving the xhtml file the changes will be transfered to the running instance, so you can check "on the fly".
Also, on the duplicate id issue, if you don't add the id field, it will be autogenerated, avoiding this problem.

Related

Evaluating Jsweet for applet to HTML conversion

I have been evaluating Jsweet since the past 4 days in order to finalize a tool that can be used to modernize an application from applet to html5/js based front end. I have been able to try the trial examples where applet based java files are getting transpiled to .js files. As a next step I need to have Jsweet introduced to the an applet based application which has 9 tabs with considerable components like dashboards, report generation related drop downs, date picker elements, tables etc. However this application which I need to modernize is not maven based and hence does not have a pom.xml. It is executed using Tomcat.
Is maven a pre requisite for Jsweet?
My expectations from Jsweet are that if I am able to introduce Jsweet to my codebase like in the example and able to create a build using maven, I should be in a position to get .js files created in the target>js>applet folder. Could these be confirmed please?
You might consider CheerpJ (https://leaningtech.com/cheerpj/) for this project. From your description it seems likely that the applet would work out-of-the-box.
If you want to give quickly give it a try: https://chrome.google.com/webstore/detail/cheerpj-applet-runner/bbmolahhldcbngedljfadjlognfaaein
Full disclosure: I am lead dev of CheerpJ and CTO of LeaningTech.

versioning javascript files as part of maven build to avoid web browser caching

I have a java/spring web app application that uses a fair bit of javascript as part of the gui. However when I release a new version I am manually, well using my ide's refactoring tool, renaming javascript files if they are edited.
This avoids users getting stuck with an incompatible/out of date javascript file that doesn;t include new functionality... or worse breaks with the newer jsp/html.
Is there a better way to add versioning to javascript files and their scrip tag references ?
You could do something like this. Which enforce the browser to load the new updated javascript.
yourscript.js?version=1234567890
On
<script type="text/javascript" src="yourscript.js?version=1234567890"> </script>
Every time you update the javascript file just update the number like yourscript.js?version=1234567891
How does it work?
Browser does interpret this as a new file every time when you'll update with new version number. So older javascript files would not cached.
A good practice is to insert a hash (or part of it) in the file name. The way I use it, it does a md5 on the file content (after minifying and compiling all files together).
You end up with a file name looking like script.H6oylsUj9sWn.min.js for instance.
That way, if the file didn't change, the hash stays the same and the client doesn't have to re-download the file.
Beside of that my compiler also generates my server side script that insert them in my html. You can of course automate all that.

JRebel doesn't update HTML

I'm using JRebel 5.0.0 in Intellij IDEA (Leda preview, 122.746) with JRebel plug-in. The server is GlassFish v3.1.
My application uses Wicket, with HTML templates placed in the same place as classes.
The problem is that updated classes do successfully reload after project rebuild, but updated HTMLs do not. For instance, I can add an element both to the page class and to the HTML, and then get an exception from Wicket saying that this element is referenced in the code, but absent in the markup.
Updated HTML resources and recompiled classes end up in the same directory (which I've checked), this directory is present in rebel.xml (and this setup is valid because recompiled classes are indeed updated).
What might be the problem?
Well, that was completely my fault, and kind of a stupid one.
I just haven't noticed a <wicket:extend> tag in the edited HTML, so my updates ended up ignored.
HTML refresh does actually work, everything runs smoothly even without clearing markup cache (thanks to a Wicket plug-in).

JSP errors, disable in Eclipse Juno

I have Eclipse, the Juno release. Just recently I am getting a few JSP errors which aren't valid or I don't care to see. Examples of the errors are below.
The function fn:replace is undefined
Attribute (cellpadding) is obsolete. Its use is discouraged in HTML5 documents.
The function error is not valid, as it working perfectly fine when I run the web application. I simple don't care the HTML5 related obsolete messages. I'd like Eclipse to not display these "errors".
I've tried enabling project specific validations, and turning off the HTML, JSP, & Tag validators, but it made no difference.
Maybe you mean that your project is using using older type of (x)html. If you don't like Eclipse falling by default to HTML5, go to project properties, then Web Content Settings, then in Document Type select the one you use.

How to make Liferay not produce condensed HTML code?

I found that Liferay transfers my JSP code in a somehow "condensed" way -- putting most of the text into a few very long lines.
This makes it uncomfortable to debug javascript.
Is it possible to turn off this feature temporary?
For others looking at this post, if you simply want to do this on an adhoc basis you can add these params to the URL:
/web/guest/page?js_fast_load=0&css_fast_load=0&strip=0
Note this is for JS, CSS and HTML
HTML Minification is on regardless you're in developer mode or not since HTML stripping can itself produce problems you want to see in developer mode.
You can add strip=0 parameter to the URL to prevent the served HTML page being stripped.
In order to turn HTML-Stripping completely off change in your system.properties:
com.liferay.filters.strip.StripFilter=false
But as #BalusC said you should use a tool which does the formatting when debugging. So you're not bothered by the stripping.
There are two ways to do it. Copy the following in portal-ext.properties and restart the server
javascript.fast.load=false
or If you dont want to restart and its just for temporary purpose add js_fast_load parameter to url and set its value to false.
For example if you are in a page http://localhost:8080/web/guest/home in which your portlet or the javascript is present. Use this url instead http://localhost:8080/web/guest/home?js_fast_load=0
Liferay has a file named portal-developer.properties as template in WEB-INF/classes. You can either reference this or just copy/paste the content into your portal-ext.properties.
This has several options to minify html, js, css and others. You'll kill your loading time - i.e. you really only want these options at development time, but then it really helps.
By default all files are also combined into a single one (for js, another for css etc.) - with the development options you'll get a separate request for every file on every page request.
I just want to update package name for Liferay 6.2 from #Fabian Barney's answer:
com.liferay.portal.servlet.filters.strip.StripFilter=false

Categories

Resources