I do developing with Java Server Pages (JSF) since the early beginning with version 1.0. Today , 17 years later, we have version 2.3 and thus a lot of improvements and new features. I’ve made many mistakes in using this standard web framework in my own applications. And therefore I would like to show some best practice rules in this Blog. And I hope this will simplify the work with JSF – for you and also for me – during refactoring my own applications. Most of which I write here comes from the great book ‘ The Definitive Guide to JSF in Java EE 8’ written by Bauke Scholtz (BalusC) and Arjan Tijms. I recommend you to buy this book if you have had already made experience with JSF. So let’s start…
Continue reading “JSF Best Practice”JSF, f:ajax and render…..
Designing JSF pages with the usage of the <f:ajax> tag can be a pretty frustrating affair. For example, if you’re trying to build a table with Ajax behavior, it often won’t work the way you expect it to. For example imaging a table with a delete-button which changes the content of your table:
<h:panelGroup layout="block"
id="artikel_table_id"
binding="#{artikelTableContainer}">
<table>
<ui:repeat var="bookingItem" value="#{childItemController.childItems}">
<tr>
<td>....</td>
<td><h:commandLink value="delete"
actionListener="#{childItemController.remove(bookingItem.item['numpos'])}">
<f:ajax render="artikel_table_id"/>
</h:commandLink>
</td>
</tr>
</ui:repeat>
</table>
....
This example won’t work even if it looks logical. The problem here is the render attribute pointing to the id of an outer h:panelGroup. This UI component tree is created during the initial build of the view. If You’re manipulating the component references after building the view, the changes will not be reflected in the UI component tree during a ajax event life-cycle if you do not care to also execute the compete tree.
To solve this you can change the render attribute in the following way:
<f:ajax render="#{artikelTableContainer.clientId}"
execute="#{artikelTableContainer.clientId}"/>
In this way now you have a binding to a component instance which forces jsf to execute and to rebuild the complete UI component tree. Note: the execution is necessary to update input fields placed within a table row.
ui:repeat versus c:forEach
At a first look it seems that between ui:repeat and c:forEach there is not big difference. This is true if only want to visualize a data set. But if you want to manipulate the entries too – e.g in a table with an embedded edit-mode than you can run in trouble if you are working with an ui:repeat. As explained in the example before, the elements inside a ui:repeat are not part of the component tree. This becomes an issue if your entries are editable. It will work on the first look if you simply submit the outer component. But in case of a JSF validation error, which is initiating the JSF-Life-Cycle the component tree will lost your entered values.
For that reason it is recommended to use a c:forEach tag instead of a ui:repeat if your data set is editable.
Enclosing Ajax Tags
If you use an enclosing ajax tag like in the following example, please note that you need to use a c:foreach instead of ui:repeat :
<h:panelGroup binding="#{artikelTableContainer}">
<f:ajax onevent="updateOrderItems">
<table>
<c:forEach var="orderitem" items="#{childItemController.childItems}">
<tr>
<td>....</td>
<td><h:commandLink value="delete"
actionListener="#{childItemController.remove(bookingItem.item['numpos'])}">
<f:ajax render="#{artikelTableContainer.clientId}"
execute="#{artikelTableContainer.clientId}"/>
</h:commandLink>
</td>
</tr>
</c:forEach>
</table>
</f:ajax>
</h:panelGroup>
In this case you should not call the ‘execute’ in the enclosing ajax!
Manage Big Data With Apache Cassandra
In this article, I will share my experience with Cassandra and how you can manage big data in an effective way. Apache Cassandra is a high-performance, extremely scalable, fault-tolerant (i.e., no single point of failure), distributed non-relational database solution. But Cassandra differs from SQL and RDBMS in some important aspects. If, like me, you come from the world of SQL databases, it’s hard to understand Cassandra’s data concept. It took me several weeks to do so. So let’s see what is the difference. Continue reading “Manage Big Data With Apache Cassandra”
EJB Transaction Timeout in Wildfly
If you have long running transactions, in Wildfly it can happen that you run into a timeout durinng your processing EJB method. In this case you can change the default timeout from 5 minutes via the standalone.xml file:
<subsystem xmlns="urn:jboss:domain:transactions:4.0"> <core-environment> <process-id> <uuid/> </process-id> </core-environment> <recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/> <coordinator-environment default-timeout="1200"/> <object-store path="tx-object-store" relative-to="jboss.server.data.dir"/> </subsystem>
In this example I changed the coordinator-environment default-timeout to 20 minutes
An Alternative to Kubernetes
Kubernetes is an container-orchestration system which helps you to automate your deployment, scaling and management of containerized applications. Originally this platform was designed by Google and is today part of the Cloud Native Computing Foundation. Kubernetes is surely one of the major providers in the market of container operating systems.
But what many do not know, is the complexity of this platform if used in smaller projects. To understand this you need to know, that Kubernetes was designed for the operation of large cloud environments as they are operated by Google, Amazon or Microsoft. This means that with the help of Kubernetes you can not only manage one server, but hundreds of servers with thousands of services. For most projects, this power is superfluous. Continue reading “An Alternative to Kubernetes”
WWW Inventor Tim Berners-Lee Launches a Project to Save the Internet
The WWW Inventor Tim Berners-Lee Launches a new open platform called “Solid”. With Solid, users can share their data with others without having to surrender their sovereignty to a group. Users should be able to decide for themselves who can access the data and which apps will be used.
To solve the problem of how to control personal data, in Solid all data is stored in a so called Solid POD. This Solid POD can be in your house or workplace, or with an online Solid POD provider of your choice. Since you control your server you own your data. You’re free to move it at any time, without interruption of service.
In my opinion, this is the only sensible solution to return data control back to the user. I hope this project gets enough attention. Your data is too serious to ignore.
Use Docker Instead of Kubernetes
Docker Container Persistence
Today I found a very good article on DZone.com about how to manage persistence for statefull docker containers. The article is from StorageOS and gives a very good overview about the problems and requirements.
Read the full article here: https://dzone.com/refcardz/persistent-container-storage?chapter=1
XSLT 2.0 with Eclipse and Wildfly
Eclipse IDE provides a cool feature which allows you to execute XSL templates within the IDE. You just need to select the XSL file together with the XML file and choose from the context menu
Run As -> XSL Transformation
But for some reasons Eclipse is not supporting XSL 2.0 – which is standard in these days. So for example if you try to use xsl functions like ‘format-date-time’ or ‘replace’ this will not work. This is also true for Wilfly application server. So here is how to add XSLT 2.0 support for both – Eclipse and Wilffly
Eclipse IDE
You can install an XSLT 2.0 processor manually into your Eclipse IDE:
- Download the latest Saxon XSLT processor
- Unzip the package to get the saxon9he.jar file and place it into your workspace or some external folder
- In eclipse choose “Window > Preferences” then “XML > XSL > Java Processors > Add”
- Fill in a “Processor Name”, e.g. “Saxon XSLT 2.0”
- In field “Processor type” choose “Saxon (XSLT 2.0)”
- Choose “Add external jar” and choose your saxon jar, e.g. “saxon9he.jar”
- Confirm by clicking “OK”
Now you can use saxon for XSLT 2.0 transformations in Eclipse. You need just configure your Run As Configurations and select the option ‘use specific process‘ to select the newly added Saxon processor.
Wildfly Sever
Also wildfly server supports only XSL 1.0 per default. If you need XSL 2.0 in your application add the following maven dependency:
<!-- XSL 2.0 support-->
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>9.8.0-14</version>
</dependency>
docker-compose Fails After Network Is Removed
Today I run into a strange problem concerning docker-compose. I have several stacks defined in my developer environment. For some reason I removed old networks with the command
docker network prune
After that I was no longer able to start my aplications with docker-compose up:
docker-compose up
Creating network "myapp_default" with the default driver
Starting myapp_app_1 …
Starting myapp-db_1 … error
ERROR: for myapp-db_1 Cannot start service myapp-db: network 656be42244ac96cd35bf7fb786
The problem was that docker-compose created a new default network, but this was not defined for the already existing containers. Containers always connect to networks using the network ID which is guaranteed to be unique. And this ID was now no longer valid.
One solution is to remove all existing containers maunally. A better solution is to shut down the conainers with the command
$ docker-compose down
This will remove the internal Network IDs and you can restart the containers again with
$ docker-compose up
