After seven weeks of hard work, we’ve published BootsFaces 0.9.0. It’s a major improvement over BootsFaces 0.8.6. Unfortunately, a little error slipped through our QA gate: It seems we’ve involuntarily published a Java 8 version. If you are using Java 6 or 7, you’ll have to wait until 0.9.1 comes out in a few weeks, or you may use the developer snapshot on Maven Central. It was a small bug, easy enough to fix it within a day.
While BootsFaces 0.9.0 is more than a bug-fix version, it clearly concentrates on polishing BootsFaces, removing bugs and finishing things we had started in previous versions. That’s not a small achievement: the number of commits on GitHub went from 856 (BootsFaces 0.8.6) to 1028. And that’s only the base library. The showcase has improved a lot, too. And we’ve managed to finish a component many developers desperately need:
<b:dataTable />. What makes this component unique in the JSF world is that it is rendered on the client. That makes it feel a lot faster and much more responsive than traditional server-side data tables. We’ve already received a lot of bug reports and enhancement requests, even during the development phase. Thus I’m sure the data table will remain in our focus during the new few updates of BootsFaces.
A more liberal license
Probably the most important point of BootsFaces 0.9.0 is the license. Now, BootsFaces is available under an Apache V2 license being a lot more liberal than the old GPL V3 license. For example, you can use BootsFaces in commercial products without further ado.
Granted, this is a minor topic, much less sophisticated than most of my blog’s posts. But it took me a couple of hours to find out how to run the Atom editor behind a firewall, so it me be worth a short article.
If you’re running Atom behind a firewall, you won’t be able to install plugins not updates until you configure the proxy settings. Basically, all you have to do is to set two user-defined variables:
https-proxy. However, it’s not that obvious where to configure these variables.
The easiest way find or create the configuration file is to open the settings dialog (“File” –> “Settings”). On bottom of the left hand side, there’s a button called “Open config folder”. Clicking it opens a new project (
.atom). That’s the settings folder in your user profile. The root folder should contain a file called
.apmrc. If it doesn’t, create it.
Next you add these lines to the file (replacing
proxyserver and the port number with the settings you use in your internet browser):
Don’t add the variable
proxy, nor try to write the variables in capital letters. Sometimes people suggest these things, but Atom ignores these variables.
Not that you have to prefix the proxy server name with
http://. If you omit it, you’ll get a “parse exception”. In my case I had to use
http:// for both the http and the https protocol – but that may be a peculiarity of my company’s network.
It’s a bit inconvenient and error-prone to define an ID for each input field, each label and each message of a JSF view. You can make your like easier using the advanced search expressions. Used wisely, advanced search expressions enable you to move input fields on the screen or between JSF views without having to update zillions of ids. In fact, search expressions are possibly the most compelling reason to use PrimeFaces or – since version 0.8.0 – BootsFaces. Their search expression engines go far beyond the JSF standard.
Why are there different search expression engines?
Traditionally, JSF relies heavily on ids. Standard JSF 2.x adds a few generic search expression that allow you to get rid of the ids in many cases. The PrimeFaces team – and Thomas Andraschko in particular – took the idea to another level. They implemented a variety of new search expressions such as
@previous. Unfortunately, these search expressions can only be used with PrimeFaces widgets. There’s an open ticket offering to implement the PrimeFaces search expressions in the Mojarra framework. Last time I looked the ticket was still dormant, laid aside due to performance considerations.
These days it’s kind of official: AngularJS implements the Model-View-Whatever paradigm. That’s a nice solution to a series of fruitless discussions about whether AngularJS implements MVVM, MVC or something else.
However, one of these days I stumbled upon a couple of slides claiming AngularJS implements the MVC pattern during my research for another article. I knew from various tutorials that this isn’t exactly true. My curiosity was piqued. What exactly is the difference between MVC, MVVM and MVP? Are there other useful design patterns? And while we’re at it: do JSF and AngularJS implement one of these design patterns?
Actually, I already knew there are different design patterns you can use successfully. When I implemented my former company’s framework, I got the idea of MVC wrong. So I implemented something slightly different. That earned me a lot of trouble with external consultants. You know, every once in a while we invited a consultant to look over our architecture. Inevitably, they would complain about our non-standard implementation. But our implementation worked, and it worked well, so what?
That’s an important thing to keep in mind: don’t waste your time on this nonsense. It’s like talking about politics: it’s a lot of fun to discuss about the advantages of MVP over MVC and whether your program following on paradigm or the other. But at the end of the days, it’ll change little. It’s more important to chose a clean, sustainable architecture and stick to it. If you need a name, call it Model-View-Whatever. Whatever works for you.
But today I’m not going to listen to the voice of reason. Today I want to have fun. Let’s dissect the design patterns, and let’s see how JSF and Angular fit into the pattern.
At a glance
Look at these pictures. They cover three of the most popular patterns: MVP, MVC and MVVM. Don’t soak yourself in the details – that’s what the rest of the article is about. Just look at the general picture. Do you notice anything?
Ralf Engelschall compiled a nice comparison of typical snippets of the two languages.
There’s also a comprehensive compatibility matrix. It’s interesting that at the time of writing even the best transpilers don’t exceed 59% (Traceur) or 71% (Babel+core.js) compatiblity (according to the compatibility matrix). On the other hand, the most popular desktop browsers – which are targeted at the mass market and can’t afford to implement features speculatively, only to remove them later – support ES6 already remarkably well, most of them exceeding the 50% mark.
More often than not, the keyword
static confuses Java programmers. As a consequence, Ken Fogel asks his students never to use static in Java unless explicitely told to do so. While that’s a good hint for starters, it’s only part of the story.
Funny thing is, I recommend to use
static as often as possible. There’s a twist: Never use
static variables, but always use
Stop looking for our Easter egg: you’ve found it. The BootsFaces team celebrate Easter with a new version of their responsive JSF framework. By now, BootsFaces is available on Maven Central, and in a couple of days it’ll arrive on the jCenter repository.
Basically, BootsFaces 0.6.6 is a bug fix release. There are also a number of minor improvements, such as adding the style attribute to a number of components that ignored in in the previous version.
You readers rock!
In 2014, BeyondJava has been read more than 400.000 times. That’s 400.000 reasons to carry on.
What’s in score for you in 2015? Time will tell… but there are a few articles I’ve already prepared, so I can pique your curiosity. BootsFaces 0.6 has just been released, so it deserves an article or two. Soon I’ll release AngularFaces 2.1. That’s the first version of AngularFaces that has extensions specifically for BootsFaces. JSF will remain a hot topic, as well as AngularJS and AngularDart. I’d like to write a couple of philosophical articles. “How to Abuse a Framework” is the working title of one of those articles.
I’m also preparing a series of articles dealing with how the JVM works. Did you know your Java program is compiled to machine code – sometimes, that is? Did you know how to read and analyze this assembler code? Did you know which optimizations the JVM performs? Stay tuned!
Maybe I’ll also include articles about WordPress. That’s the platform of this website, so I’ve learned a lot how to do thing and how not to do things. During the last couple of days I’ve started to make the website faster again. Chances are I’ll write an article about how to optimize WordPress performance.
Oh, just in case you didn’t read the geeky part of Twitter: 2015 is a palindrome. Written as a binary number, it’s 11111011111.
Welcome to the year of the palindrome!
Did you know characters don’t always fit into chars?
Did you know
String::length() does not always return the number of letters of the
Did you know you can’t reliably read a text using a
Did you know many characters have more than one Unicode encoding?
Before leading you to McDowells great “guide to character encoding”, I’d like to show a couple of interesting characters to you:
- The letter A is encoded in UTF-8 as 0x41. That’s simply good old 7-bit ASCII code.
- The french letter é (as in écouter) is part of many 8-bit extensions of ASCII. In UTF-8 it’s encoded as C3 A9.
- However, it also can be constructed as a combination of “e” and the accent “´”. That amounts to 0x65CC81 in Unicode. That’s the first example of the three byte representation of a character.
- Characters can become as complicated as क्तु. That’s a 12 byte encoding in UTF-8: E0A495 E0A58D E0A4A4 E0A581. As far as I can tell, that’s a base character followed by three modifiers.
The last character doesn’t fit into a Java
"क्तु".length() yields 4 – albeit it’s considered a single Devenagari letter.
There’s a lot more information on Java character encoding on McDowells “exhausting, but not exhaustive” article Java: a rough guide to character encoding.
Maven’s central idea is to use libraries stored at a trusted central repository, such as Maven Central. However, sometimes you need to use a library that’s not stored in such a repository. This applies to legacy libraries as well as to developer versions. In my case I needed the developers’ build of PrimeFaces containing the latest changes, so I had to build my own snapshot.
A co-worker of mine found a nice decription how to make Maven use such a local library.
There’s good news to all those who hadn’t the opportunity to visit this years JavaOne: Quite a few talks have been published on parleys.com. At the time of writing roughly 60 talks are available for you. Most of the videos are just the sliders with the audio track underlaid, so don’t be surprised if you don’t see the speaker waving her or his hands.
The JavaOne home page
JavaOne 2013 talks at parleys.com
Google trends on Scala, Groovy and JRuby
Preparing another example for the AngularFaces showcase I just noticed a funny thing: the current period of low interest rates is a challenge to programmers!
Decades of banking apprentices learned how to calculate the monthly payment rate of a loan like so:
var q = 1 + (interestRate / 100);
var annuity = amount * Math.pow(q, loanTerm) * (q - 1)
(Math.pow(q, loanTerm) - 1);
These days many interest rates are very close to zero per cent. Sometimes they even reach the 0 per cent mark, and that’s where the problem arises: traditional formulas fail because of the singularity. A
DivisionByZeroExcetion is raised.
Of course it’s pretty simple to solve the bug. But I guess hardly anybody thought of crashing computer programs when the Bank of Japan lowered it’s interest rates to zero. That’s more than a decade ago, but still, the story might repeat now that both US fund rates and ECB refinancing interest rate are close to zero:
As I mentioned, it’s not a big deal to solve the problem. The bottom line it has to be solved by someone (computer programmers, to be precisely) – and it’s a nice example of unexpected side effects of decision done by politician and managers. I suppose many people aren’t aware of those side effects, and they’d be pretty surprise to learn how much money many decisions they consider harmless cost. Mind you, every financial institute has to correct their software to be able to cope with a zero interest rate!
Actually that’s not a new phenomenon. Many programmers become very busy when new laws are passed or important treaties are changed. For instance, my companies work is based on a collected labor agreement, and most changes of the treaty have to be mapped by our software.
But of course I’m not one to complain. I’m making my living solving those problems :).
Today, I’ve found a nice description why Java’s
RunTime.exec() method feels to clumsy. Since Java 5 there’s a major improvement – the
ProcessBuilder class – but still, it could be done better. AdiGuba offers an library to do so (see Runtime.ecec() n’est pas de plus simple). If you’re able to read an article written in french, you will find a nice API.
A problem that hasn’t been solved by this API is that you can’t influence a process you didn’t start. Sometimes it happens that your Java applications starts an external process, crashing before the external process stops. You can restart your Java application, but it cannot kill the process its predecessor called into life. If you want to to things like that, you have to use JNI and to do some native C coding.
There is a nice library that makes creating and reading JSON object fun: Google GSon. I use it in every class of mine to implement a toString() method. You can even use to to implement the clone() method (if you don’t care about performance):
During my last trip to France, I bought a french prepaid sim card to reduce costs. However, it didn’t pay.
Zipping a file in Java is a rather trivial task you can find in many tutorials. However, I’d like to use it in a subsequent article, so I publish it anyways. By the way, it is another example of (almost) correct resource handling before Java 7.
I’ve seen so many questionable solutions of Java file and database IO that I decided to offer a template you can freely copy. By the way, being a hurried (and lazy) programmer, I frequently do Java IO wrong myself, so I will copy this template, too :).
your comments are important to me. They help me a lot to improve this blog – and they show me there are people who read this blog, and, judging from your comments, even enjoy it. Thank you very much!
Sometimes it can be useful to read and analyse a java class. This can be a tedious task; the classical approach is to write a grammar for the language and to generate a parser. This is exactly what Júlio Vilmar Gesser did. His parser has a simple interface, allows both reading and modifying java code and is available under the LGPL.
Liferay has a nice feature to influence the portals behaviour by deployable items. Among other things you can use theese “hooks” to call a java method if the user logs in or logs off again. My particular use case was to show different pages to different user groups.
Hooks are described nicely at http://www.liferay.com/de/community/wiki/-/wiki/Main/Portal+Hook+Plugins. Unfortunately this description is a little outdated. For the sake of convenience I jot down the basic steps to write a hook.