Monday, December 31, 2012

JSF 2.x Tip of the Day: Dynamic <ui:include/> with <f:viewParam/>

Introduction

I encountered a situation the other day where I need to include a JSF page based on a parameter passed in via a <f:viewParam>. This seems like a very reasonable kind of idea. I expected to be able to make the <ui:include/> use a dynamically set src parameter using EL from the <f:viewParam>. This is where I went wrong (the idea was good...). The <ui:include/> is a tag handler. It is evaluated on Restore View Phase. The value processing does not take place until the Apply Request Values Phase. This presents a problem since the EL binding for my <ui:include/> is based on the <f:viewParam> which is a UIInput object. So we are out of phase. The page will display the results, but all the AJAX will not work.

A Solution

A solution to the problem involves using static <ui:include/> elements wrapped in <ui:fragment/> elements. This allows the tag handler to resolve the page to include, and then the fragment determines (via late binding) whether to display the page based on the <f:viewParam> passed. The page is supported by a @ViewScoped bean to keep the page in scope.

Code

Here is an example of how to do it.

Conclusion

I have put the complete NetBeans 7.2.1 project using Mojarra on Bitbucket. The project uses Apache Maven, and was tested using GlassFish 3.1.2. Here is the complete project: dynamic-include

Creating and Implementing An HttpSessionWrapper

Introduction

I am faced with a problem currently where I have an application that was written before the J2EE specification was written. The application has its own application server, session, and state management. I am in the process of modernizing this application and transforming it into a standard Java EE application. However, there is a lot of code over 1.5m LOC. That makes this process very intensive.

One of the issues I have been wrestling with is session management. As I previously noted, the application has its own session and state management mechanisms. The session object is not too vastly different from a standard HttpSession object. This has given rise to an idea that I could wrap a standard HttpSession object with a decorator similar to HttpServletRequestWrapper and perhaps a implementation of the old session mechanism.

Currently there is no HttpSessionWrapper like HttpServletRequestWrapper, or HttpServletResponseWrapper so I wrote my own. It was simple to do and I hope others who may need a HttpSessionWrapper will use it. Once I wrote the wrapper, implementing it was the harder part.

Implementation

Implementation requires a little knowledge of how HTTP requests are handled by servlets, and request and response handling in general. The most important thing to remember is: the HttpSession is created from the HttpServletRequest object. This important fact can help determine how to implement our HttpSessionWrapper. I think that the easiest mechanism is to use an HttpServletRequestWrapper in a @WebFilter. Filters are the first items that a request will pass through to reach the servlet, and the last thing it will pass through in the response.

If you use this mechanism, for implementing your HttpSessionWrapper, you must ensure that this is the first filter that the request will pass through. If it is the only filter, that should be very easy to implement. If you are using multiple filters with annotations, you will need to use a web.xml file to place them in the order you want them applied.

The example code I have below takes advantage of the fact that I can use a filter and that once I pass in my HttpServletRequestWrapper with its modified getSession() methods that return my HttpSessionWrapper. The HttpSessionWrapper can be downloaded here: session-wrapper

Code

The code below includes the HttpSessionWrapper and an example implementation of how to use it.

HttpSessionWrapper.java



HttpSessionWrapperImpl.java



HttpServletRequestWrapperImpl.java



WrappingFilter.java



Conclusion

Implementing a HttpSessionWrapper can be done very easily with a little thought, and perhaps a good blog article on it. The session-wrapper and session-wrapper-example code is available on BitBucket as Mercurial projects.. The projects were developed using NetBeans 7.2.1 and Apache Maven and was tested using Glassfish 3.1.2.

Thursday, December 27, 2012

Tomcat 7: Custom Valve

I was asked today by a colleague for some help on creating a valve for use with Apache Tomcat 7. I had never done one before, so I thought I would give it a quick try. +Craig McClanahan  had done a great job on creating a simple mechanism for creating a Valve with a lot of the heavy lifting done by ValveBase.

Creating your own valve is really simple using NetBeans 7.2.1 along with Apache Maven.

  1. Create a Maven Java Application.
  2. Add the following dependency:
  3. Create your Java class and extend it from ValveBase.
  4. Implement invoke(Request request, Response response)
  5. Build your library (.jar) file
  6. Install the library in the ${tomcat.home}/lib directory.
  7. Configure server.xml to use your new Valve. For example:
  8. Start the server to see your new valve in action
Here is my simple example.

ProcessingValve.java

Here is the output...
INFO: Server startup in 1442 ms
Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke
INFO: Header --> host Value --> localhost:8080
Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke
INFO: Header --> host Value --> localhost:8080
Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke
INFO: Header --> host Value --> localhost:8080
Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke
INFO: Header --> host Value --> localhost:8080

As you can see it was very easy to implement. Here is the code for my example: valve-example.zip

The source can also be found on Bitbucket: valve-example

Wednesday, November 21, 2012

What is the definition of a JUG Leader?

Daniel deOliveira, a friend of mine, asked me for what I thought a JUG leader definition should be:
I’m writing an academic paper about the seven dimentions of collaboration in JUGs and I needed a definition for a JUG Leader. I looked in several search engines and … nothing :-( Amazing :-0
I replied to him, and the JUG Leaders list with my definition below. One of the things he noted was that there is no definition out on the Internet that he could find. I decided to add one.

What is the definition of a JUG Leader?

A JUG leader is someone who is passionate about Java. That is the most obvious answer. However, that answer has many different levels. A JUG Leader can be a very technical individual, and some are the best developers in their JUG. This does not need to be the case.

A JUG Leader understands the power of communication, collaboration, and community. As I noted, a JUG leader does not need to be the technical expert of the group, but they need to be able to identify those members (community) and get them to share (communicate) their knowledge. The group dynamic results in a number of synergies that lead to making the group successful (collaboration).

JUG Leaders can act as facilitators. They tend to pay attention to the activities of their members. Often, when someone mentions an issue, or something that they need assistance with, a JUG Leader knows someone else in the community who may have the answer, or provide direction.

JUG Leaders introduce people. We tend to meet really interesting people, and cool projects. When a member asks about a project, or a person, we can often introduce them to the right people. They can also provide assistance to employers looking for people. They tend to know who is in their communities and their expertise.

The best JUG Leaders are people oriented. They are personable, and are the type of people you want to hang around with. They realize that technology changes, but that people are the constant. This leads them to make relationships with people. The power of relationships with people will overcome technical challenges, and personal conflicts. We already know that JUG Leaders are passionate, but the relationship part tempers our dealings with others. We understand that people will disagree, it is how we deal with disagreement that others will judge us.

A JUG Leader is the continual "newbie". They tend to be first adopters. This results in an appreciation for new members. They are always new to some technology, and publicly recognize those projects that support new people.

A JUG Leader is social. As a JUG leader, you tend to be involved with social media. A number also tend to be bloggers. This passion for communication and sharing drives them to blog, or tweet.

A JUG Leader cultivates success. The most successful JUGs have other leaders which are pulled from the membership to make the JUG successful. The JUG should not succeed, or fail on the efforts of one individual. The leader organically grows its members, and asks them to do things that they will be successful in. Move people forward by giving them opportunities to succeed.

Hard projects should only be handled the JUG Leader, or those who will not be deterred by failure. Those projects which could fail should be very public. In the event of failure, the JUG Leader can demonstrate that failure is OK, and that we move on. The leader mentions the failure in terms of themselves, and not the JUG. This is very important.

Success will breed success, and a very public success is a win that should be mentioned in terms the JUG making it possible. Communal ownership and pride in your JUG will make the leader and the JUG grow.

Those are some of my thoughts on what a JUG leader is, or at least what we should aspire to be.

Tuesday, November 20, 2012

Article: Java needs new ideas, not a vague slogan

I read the Opinion piece from the editors of SD Times issue 283 November 2012. I was taken aback that I felt that the Monday morning arm chair quarterback had taken over the SD Times. They completely missed JavaOne 2012, and failed to deliver quality journalism by missing the community aspects. Here is the letter I sent in rebuttal.
I have been attending the JavaOne conference for the last 8 years. This was a great JavaOne. It was great because there were no earth shattering announcements. The community has grown and developed. JDK8 was delayed for some legitimate technical reasons, and some less technical. A lot of work was done on OpenJDK to enhance its adoption, and usage. This was apparent to everyone, except the editorial staff. "Dull" the show was not. This year, a number of participants, and speakers talked about what a "good", or "great" show it was. In my sessions, the talks were packed, and in one case standing room in the back.
ARM was a big winner with a lot of talk about using Java embedded. Raspberry Pi got a lot of developers talking about it along with Java. 
The Java Users Group Sunday, NetBeans Day, and GlassFish Day were well attended by enthusiastic crowds. The Java Users Group Sunday was a community led event without any input from Oracle. Oracle graciously offered us the space and technical staff. I should know I was one of the many organizers. NetBeans Day was community driven as well. The big winners at JavaOne were the communities. 
Did the editorial staff notice that two user groups got Duke's Choice Awards: London Java Community, and jDuchess. Humanitarian efforts went noticed with the United Nations High Commissioner on Refugees (UNHCR) getting a Duke's Choice Award for Level I Registration. A number of open source projects also got the coveted Duke's Choice award including Agrosense. The judging was also community driven. 
The JCP is always a tough subject. It is also the easiest to score political points on by saying its broken. Try talking about the advancements in the JCP. The SE/EE Executive committees are merged. The process has worked on cleaning up a lot of the low hanging fruit, and now the big challenges are left. This is no secret. Wait, that's right... transparency has been put into place in the JCP so it really is no secret. 
I am not a fanboy of JavaFX, but Oracle has made significant investments in it. It provides a development platform that will work where Java runs. HTML5 is not the panacea that answers everything. I know that tech writers seem to make it seem that way. Thick clients are here to stay, and why not have "sexy" ones. 
"Make the future Java" may seem an odd choice of slogans, but from my perspective; the future is what I make it.

Thursday, November 15, 2012

Annoying IE9 CSS Hover and Overflow Issue

Case

I have a <table/> which is surrounded by a <div/> which has the attribute style="overflow:auto". The table has a hover attribute to highlight table rows on mouseover. Additionally, There are some checkboxes arranged in a table below it, but it could be another element. When you mouseover the table in the div, the checkboxes start moving the the bottom of the page.

Resolution

I found the following bug posted on the jQuery bug tracker: Problem with .hover() and IE9 that describes the behavior. Brian Richards, who is linked to in the bug, has a simple bug elegant fix that worked for me.In his blog post, IE9 Hover Bug Workaround, he simply added min-height:0% to the style.

I hope that the solution works for others who may encounter the problem. I also found another blog to put on my blog roll to keep an eye on. Thanks for blogging Richard.

Tuesday, November 13, 2012

JSF 2.x Tip of the Day: AJAX Composite Component with AJAX Event Listener

This example is using a JSF composite component to create an AJAX enabled <h:commandButton/> that has an <f:ajax/> component. Additionally, there is a listener that handles the AJAX events that occur.

This is a simple example which demonstrates the concepts, but could be extended to create your own type  of AJAX button like you would find in PrimeFaces, or RichFaces.

The source code for the project can be found here: cc-ajax-commandbutton.zip

The composite component is located in a directory called resources/lotuscc. The only thing interesting about the implementation is the method-signature for the listener.

ajaxCommandButton.xhtml



The index.xhtml page, and IndexBean are very straightforward.

index.xhtml



IndexBean.java


JDK7 vs. JDK 6 File Monitoring

One of the really nice advancements, or features of Java 7 is the WatchService. This feature takes advantage of the OS file event notification facilities where available, or otherwise uses a "primitive" polling mechanism. In my blog article WatchService Using ScheduledExecutorService Example, I show an example of how to use the WatchService along with an ExecutorService to do file monitoring. This is really easy to implement and use.

However, the question of how to do it on JDK 6 was posed to me for those who can't do an upgrade for business reasons. I did a quick Google search to see what was out there. Alas, some of the most popular search results were poor, or really badly implemented solutions. I did come across a nice piece of code done by Pascal Essiembre. I didn't find much more on the developer. I would give a link to his work if I were sure that what I found was him. Pascal wrote the code below which is EPL 1.0 so you are free to use it. I used it to check it out, and it works likely in the same manner as the "primitive" implementation in JDK7. Here is the code unmodified from the form I found. This is very nicely done. Good code lives on. I just wish this were more near the top of the search results.

Thanks Pascal for your code contribution to the Java community.

Sunday, November 11, 2012

Article: Oracle's Java Revival

I just finished reading an article titled Oracle's Java Revival by Andrew Binstock in InformationWeek. It was apparently renamed for print from the article in Dr. Dobbs Two Years Later: A Report Card On Oracle's Ownership of Java. It is a good article with some positive remarks on Oracle's stewardship and  some criticism.

Oracle has a very business savvy approach to IDEs. They have two IDEs which they own. JDeveloper which is the industry step-child and really is only used by Oracle developers, and NetBeans. Oracle also supports Eclipse too. This allows them to cover all the bases for Java developers. A big winner in the article is NetBeans. I agree with the remarks from Andrew on this
As for tools, Oracle has certainly stepped up investment in the open-source NetBeans IDE. Since the 7.0 release, each version has added new capabilities while maintaining the product's historical light and usable feel. The upcoming v. 7.3 looks to continue the trend.
This is true. As I write this post, NetBeans has released 7.3 Beta 2. NetBeans continues to innovate and provide tooling that developers need. I would like to see more focus on making sure that the IDE plugins can be upgraded in an easy manner. There are a number of great plugins which have been developed over the years. The upgrade path should be as simple as the Inspect and Transform Refactoring tool for migrating your code to Java 7. There are a number of plugins which I would love to see upgraded.

I found that Andrew's remarks around OSS projects disappointing and incorrect.
Oracle's ambiguous relationship with the JCP and the OSS communities remain two other weak points. Except for its work with NetBeans, the OpenJDK, and the GlassFish server projects, Oracle's open-source presence is low profile, in direct contrast to Google, which is a continuous and enthusiastic contributor to OSS.
I don't think this is an accurate assessment. NetBeans, and GlassFish are vibrant communities which are closely integrated. When a feature becomes available in GlassFish, you can expect that it will be available in NetBeans. OpenJDK is an enormous project on top of which Java itself rests. The excitement and participation have never been better. Communities like London Java Community have been working with the OpenJDK project to make it easier for community members to contribute.

Google does not work on anything that does not benefit Google. All of the F/OSS software from Google is a strategic move to get community contributions to make their products better. Is this bad? No, but I don't think they should be given a free benevolence pass either. OpenJDK benefits Oracle for sure, but in a number of cases it is pure benevolence. A vibrant Java community is good for Oracle.

GlassFish is a reference implementation of Java EE. The work here benefits Oracle for sure. Again, the work here is used by more than just Oracle. There are a number of businesses whose only dealings with Oracle are via NetBeans, GlassFish, and OpenJDK. No money to be made for Oracle. Is this more benevolent? I will let you decide that one.

Google has done a lot for Java and I will be the first to applaud their efforts.
The biggest growth in Java undoubtedly comes from Google's adoption of the language for Android. So the lawsuit that Oracle filed (and lost) against the search giant is a howitzer shell fired at one of Java's biggest users and most important evangelists. Given the personalities of the two corporations, I expect this is a stand-off that will endure for a long time. Java will have to grow despite it, rather than through it.
Nothing could be truer! The lawsuit has done nothing, but harm to the community. I am angry that Oracle pursued the legal course, and Google for forcing the issue when they did not get what they wanted in the JCP and via other communications channels. There is enough blame to spread on both companies here.

The JCP is a conundrum. There is a lot of positive work being done here with two large Java User Groups (SouJava, and London Java Community) leading the efforts from the community side. Patrick Curran, JCP staff, executive boards, and members have done a lot of work to improve the process. A lot of work remains to be done. The recent elections and confirmation that JUGs are here to stay on the JCP should be taken as good things to come.

JavaOne 2012 was one of the best events I have attended over the years. This one is in my top two from the years I have attended.  James Gosling was in attendance, and gave a presentation at the community keynote. A sea change from the previous year.
...I'm inclined to agree with James Gosling's revised opinion of Oracle's stewardship, that it's been good for Java.
This has been my observation as well. I have thanked Oracle publicly and privately for their work, and will continue to do so. I have had a  better relationship with Oracle than I have sometimes in the past with Sun. I hope that this continues going forward.

The article closed with this remark which I think is shallow. While Oracle has gotten its fair share of black eyes around things. Sun was a moving target. This was especially true near the end. Its sudden dropping of projects which it claimed to sponsor, vaporware, and conferenceware were a source of a lot of developer excitement and angst. IBM has never enjoyed a lot of love from the developer community.  It has been considered by a number of developers as the "less evil" twin of Microsoft for better, or worse. Oracle I think can get some developer love. It may take a while, but they do have a commitment to the developer community, and it is beginning to pay dividends.
While I doubt it will ever know the love that both Sun and IBM enjoyed from the developer community, if it continues to develop the language, the platform, and supporting tools well, it will be successful enough and Java and the JDK will continue to occupy a preferred place in the development firmament.

Saturday, November 10, 2012

WatchService Using ScheduledExecutorService Example

I was developing some code for the Java Certification Boot Camp project on Java.net where I wanted to demonstrate how to use the WatchService from JDK7 to monitor filesystem activity. I also wanted to demonstrate using it with an Executor.

As part of the process, I needed a graceful way to exit the program when the program completed. I thought that I would simply Google a solution, but I did not find one that met my needs.

So here is the use case I would like to have a WatchService running in its own thread and monitoring the filesystem. After a time period, I would like the service to shutdown gracefully.

I decided to use A ScheduledExecutorService which would start the WatchService using a Callable<V>, and another Runnable which was scheduled to shutdown the WatchService and the ScheduledExecutorService.

So here is how I did it.

WatchServiceImpl.java


Monday, November 05, 2012

JSF 2.x Tip of the Day: Using <ui:decorate/>, <ui:fragment/>, and <ui:include/>

We have been doing a lot of JSF work lately, and I was surprised that my team really did not have a really good grasp of mixing <ui:decorate/>, <ui:fragment/>, and <ui:include/>. These elements are very powerful and allow you to build more complex and reusable code.

The <ui:fragment/> is probably one of the most important elements in Facelets. The ability to use the rendered attribute to determine if the contained content should be displayed is one of the most important uses. Today, I see a lot of examples where you place some code in a <h:panelGroup/> element where you set the rendered attribute using an EL binding. This has the side effect of producing a <span/> element. If you add enough of them, you end up with spans inside spans inside spans... you get the idea.

The <ui:fragment/> has no side effects. You either produce (emit) the code you want, or nothing. A very clean process. The <ui:decorate/> component is one of the least most used and not very well understood. The <ui:decorate/> component is used to add additional functionality to a page. If any other template code is in the decorator page to be included, it is added to the page. In other words, it includes the other content on the page. For example, take a look at the code below for a decorated table. Note that the <table/> is included in the output. It is also outside of the <ui:decorate/> tag.

decoratedTable.xhtml


This was added to a page as you can see in the next snippet, and produced the image below.

DecoratedPage.xhtml



Finally, the <ui:include/> allows you to add content from another page into the current page. This inclusion mechanism allows you to take advantage of code that can be templated for reuse. In order to be complete, I will show the remaining code snippets from the examples above, as well as another example.

unorderedListTemplate.xhtml



listElements.xhtml



decoratedExample.xhtml



Friday, November 02, 2012

Servlet 3.0 and JSF 2.x Tip of the Day: JSF Forward to External Servlet in Different Context

I posted a previous postServlet 3.0 Tip: How Do I Get to Another Servlet Context? which demonstrates how to get to another context. This extends that discussion by showing how to forward a JSF request to the other context and have the servlet output the results. Here is the basic code to be called from the JSF page.

Here is the method.

Here is the servlet I called.

CrossAppServlet.java



Success

Note: If you were going to pass it to JSF, you would need to remove the view state since the Faces Servlet receiving the values would result in a ViewExpiredException since this view state is not in the target Faces Servlet.

JSF 2.x Tip of the Day: <ui:fragment/> and Namespaces

A junior engineer lamented that he could not get NetBeans auto-completion to work, and that his xhtml pages were all red. He wished that NetBeans could be "smarter".

I told him it was "smarter", but he needed to show a little understanding. His problem was that he was using the <ui:fragment/> without namespaces defined.

So here is how you do it to avoid a sea of red. Notice how I just simply added the namespaces as attributes right to the <ui:fragment/>. No more red, and NetBeans is happy.

Thursday, November 01, 2012

Servlet 3.0 Tip: How Do I Get to Another Servlet Context?

This was a question I got tonight. It was a little more complicated prior to Servlet 3.0, but now it is very easy. In fact I almost thought it was not worth writing a post about it. Then I asked a friend in IM if he knew how to do it. It was so much more complicated, I decided to capitulate and post my response.

So how do I navigate to another web application on the server from my current application context?

Simple...

Dynamic Servlet Registration Example

Today I wanted to load a servlet dynamically, and decided to figure out how to do it. It turns out to be really simple.
I created a ServletContextListener and annotated it. In the contextInitialized() method, I set the servlet name, its class, and a mapping and we are done.

We can then deploy the project and watch the magic. Here is the Apache Maven project: dynamic-servlet.zip

ServletContextListenerImpl.java



ExampleServlet.java


Wednesday, October 31, 2012

Servlet 3.0 and HTML 5 File Upload Servlet Example

Someone asked how simple is it to create a servlet using 3.0 technology which could upload a file. It took me about 5 minutes to do using NetBeans 7.2, and another 10 minutes to tweak for the file name. I hope that this proves how quick and easy it is to do. The code is also very readable.

Here is the code for my servlet, and form:


Tuesday, October 30, 2012

NetBeans 7.2.x Tip of the Day: Sharing PMD Configuration Files

I use the PMD plugin for NetBeans 7.2 for my development. If you are not using it, you should consider it. The plugin uses the ruleset from PMD project for static code analysis. Members of my team asked which rules I use when I evaluate their code so that they can handle it before I look at their code. I thought it would be as simple as exporting it, but that was not the case.

I filed an enhancement request for the feature: Export PMD Default Configuration Ruleset. Until it is added as a feature, here is how to pass your selected ruleset along.

The file that contains the rules which I am using is called pmd.properties. The file is located in a couple of different places depending on if you are using Windows, or Mac OS X.

On Mac OS X it is located:

/Users/{USER_HOME}/Library/Application Support/NetBeans/7.2.1/config/Preferences
On Windows it is located:

C:\Users\{YOUR_USER_DIRECTORY}\AppData\Roaming\NetBeans\7.2\config\Preferences
I hope that helps if you need to share your rules.

Wednesday, October 24, 2012

JSF 2.x Tip of the Day: Creating RichFaces <a4j:commandLink/> Programmatically

As soon as I posted the previous blogpost Java Evangelist John Yeary's Blog: JSF 2.x Tip of the Day: Programmatic <h:commandLink/> I got a request for how to do it with RichFaces. The process is almost the same.

Here is an example for creating <a4j:commandLink/>
This example creates one for a table sorter on a RichFaces data table.

JSF 2.x Tip of the Day: Programmatic <h:commandLink/>

The JSF Tip of the Day is an amalgamation of a couple of tips: JSF 2.x Tip of the Day: Programmatically Creating EL ValueExpression and JSF 2.x Tip of the Day: Programmatically Creating EL MethodExpression which are combined with this tip.

In this tip we will create a <h:commandLink/> programmatically. The code from the previous tips noted, are used to create the component.

The component is bound using the following:

Article: How to get (almost) everything you ever wanted in one (not very) easy step

I finished reading the article How to get (almost) everything you ever wanted in one (not very) easy step by Richard Kennard in SD Times magazine. At first I thought it was going to go in a direction that I thought would be helpful for most developers who want to get involved in open source projects, or just become more involved in their respective development communities. My hope was quickly dashed. Don't get me wrong, the article is good, but most folks will not be able to take this approach. 

Richard's approach is to find something that you can turn in to a doctoral thesis, and work on your Ph.D. The article then covers how Richard did this himself.  Richard's passion is a project called Metawidget. This is a really cool technology. In fact it was so cool, that as part of the JavaOne paper selection committee I strongly recommended it. The committee agreed, and Richard gave a talk about it at JavaOne a couple of years ago.

I like Richard's passion about putting in the extra mile to get something accomplished for you, and the community. I just want to make sure that people don't get lost in the idea of a Ph.D. as a minimum level of commitment.

I have an email from Ed Burns the specification lead for JSF. He is asking for assistance with Javadoc updates. This is for JSR-344 JSF 2.2. This is an example of something where you can make a difference without a lot of personal time expense, and may provide the push to continue into bigger and better things.


I sure could use some help in bringing the new Javadoc 7 style to the generated portion of the JSF spec [1].  Can anyone from the Adopt-a-JSR program help me out here?  The task would be very hands-on, as the generated portion of the spec uses several different kinds of documents as its source inputs.
Ed
[1]https://javaee.github.io/javaserverfaces-spec/
It can be something simple like this that would make the difference for a lot of people. 

Obviously, I like to blog which does not require a lot of time. Here is my secret about blogging... I forget things. My blog is a reminder of how to do things that I figure out, and need every so often. I know it may sound funny, but I often Google for something and get my own blog. Other times, I blog about articles which I find interesting. Like this article.

If you want to participate in any project, or technology just ask. The smart project owners/leads will find a place in their project for you. Eventually, you may lead your own project.


Saturday, October 20, 2012

Article: The JVM's Popularity

JVM and Modula3
I had kept an article from Dr. Dobbs Report called The JVM's Popularity by Eric J. Bruno with the intent of writing a quick blog post on it. This is the time I have to do it.

The article covers the Java VM versatility in a quick two page article. It describes some of the recent additions to the Java Language to support dynamic languages like JRuby called invokedynamic (JSR-292). This additional functionality allows dynamically typed languages to run without a performance penalty. The article explains this in a little more detail.

The article characterizes three categories of JVM languages: improve Java, port an existing language, and miscellaneous. Nothing too controversial. I did find one comment which I could not confirm though:

...NetRexx (the original JVM scripting language);
This was a surprising remark. I had never really heard of NetRexx running on the JVM until about a year ago when I was looking at a listing of JVM languages, and saw it. Does anyone know, and can confirm that it was the original JVM scripting language?

The last part of article refers to the upcoming release of Java 8 including the replacement Nashorn JS engine for Rhino.

A good quick article for an executive rundown on VM languages.

Article: Employers Hot On Application Developers

I just got through reading Employers Hot On Application Developers by Art Wittman in Information Week in the Practical Analysis series. It is a great read for anyone who is talking about career paths for students, and developers making career decisions.

I think one of the selling points is the money of course. The median income for staff developers is $95,000.00 USD. The other interesting information was that 7% of companies surveyed said that they would increase staffing of application developers by 21-30%, 11% were planning on staffing by more than 30%. I don't normally pay much attention to percentages without sampling data. However, it is still impressive.

It is a one page article and I recommend taking a peek at it. I found it interesting, and I hope you will too.

JSF 2.x Tip of the Day: Programmatically Creating EL MethodExpression

A common need is to create a MethodExpression for use in binding a JSF component action, or actionListener attributes to a value in the JSF/CDI managed beans.
Here is an example of how to use the method. In the example below I use both a ValueExpression and a MethodExpression for clarity. The MethodExpression is bound to a method called sort() in the IndexBean. Since this is bound to the action on the UICommandLink, it is expected that a String is returned which is used for determining navigation. Also note that an empty new Class[]{} array is passed as the expected parameter type.

Friday, October 19, 2012

JSF 2.x Tip of the Day: Programmatically Creating EL ValueExpression

A common need is to create a ValueExpression for use in binding a JSF component attribute to a value in the JSF/CDI managed beans.

This is a convenience method that I have created to create these expressions.
Here is an example of how to use it. In this example I bind the <h:commandLink/> value programmatically to the @ManagedBean called IndexBean value called columnHeader.

Sunday, October 07, 2012

Article: Even World of Warcraft is tracking you!

I just finished reading the Backspin article of the same name from the September 24th Network World Magazine. It is just another article that points out once again the lack of personal privacy and laws on the Internet.

Let me spare you a few cycles here, Blizzard Entertainment decided to use steganography to secretly (in this case the secrets out) encode trackable user information. This came to light earlier last month when screenshots were analyzed. The information includes account ID, time stamp, and IP address of the current realm. All of which can be used to stage an attack on the account owner. NICE!

The really bad thing is that the original information contained account ID which was equivalent to login information back in 2007. This has changed with upgrades, but warning to those with old accounts.

While I believe that most of us don't want to trust our government to monitor us to keep us safe. I do believe that they have a responsibility, as do we, to demand that laws which protect our privacy should have a minimal threshold. Let's call it a "Stupidity Factor" which says when you place personally identifiable information, or secondary information which combined with easily accessible information completes the picture, should make the exposer liable.

I am not one for lawsuits, but having something like a financial penalty which is a strong deterrent, and also offering civil liability make companies make "better" decisions. The general maxim for most companies has something like "maximizing shareholder value." Litigation and governmental fines, or restrictions in the ability operate are counter that proposition.

Essentially by holding these companies financially responsible is more likely to cause them to behave better, or at least give them pause.

Friday, October 05, 2012

JavaOne 2012: MICE and men

I attended a wonderful presentation on MICE (MASE) from the NATO Defence Programme as part of development on the NetBeans Platform. I was impressed with how NATO looked at NetBeans and understood what many of us already knew; NetBeans platform should be the first choice for doing Rich Client (Swing) development.

NATO was able to take advantage of common functionality provided by the platform like file handling, and user options, this left them to focus on the business of developing an air defense program. This is the way it development should be.

I had a great opportunity to talk with Angelo D' Agnano, one of the principal developers, at JavaOne. I was very excited to be able to give them a Duke's Choice Award at JavaOne. It was well deserved. The follow on talks just confirmed how cool it is.

Check out the The NetBeans Zone article on Dzone: Updated NATO Air Defence Solution Based on the NetBeans Platform

It will not disappoint.

Friday, September 21, 2012

Java Certification Boot Camp - Generics and Collections

Module 04 - Generics and Collections

Java Certification Boot Camp - Object Oriented Design Principles

Module 03 - Object-Oriented Design Principles

Monday, September 10, 2012

JSF 2.1 Tip of the Day: Using <iframe /> Elements with PrimeFaces

Carousel and LightBox
We have some requirements on a project I am working on to display <iframe /> elements which are connected to external pages within our JSF pages. Since JSF supports template language such as plain HTML, we could directly use an <iframe /> in the page. However, it would not match up with our existing page layouts.

PrimeFaces offers a component called a Light Box (<p:lightBox />) which supports <iframe /> elements directly. You can see an example from the PrimeFaces showcase for how to use it.

I thought I would share a more interesting approach using a <p:caraousel /> object to display multiple <iframe /> elements in a more "sexy" approach.

The cool thing is that the code is really easy to implement!

The code was developed using NetBeans 7.2 and Apache Maven. The code can be downloaded here: iframe-example.zip

code


Sunday, September 09, 2012

JSF 2.1 Tip of the Day: Progressive Update, or Graceful Degradation with <f:ajax/>

When designing a web application, you should always consider how the application should perform if JavaScript is disabled. There are some JSF frameworks which will not work at all if JavaScript is disabled. Mojarra, the reference implementation, is designed to work even if JavaScript is disabled.

The design is generally called progressive enhancement. This means that the application will work with basic components, but its functionality is further enhanced using JavaScript and CSS. The same side of the coin is also called graceful degradation. To follow the designs, you must take advantage of the component semantics, for example alt attribute on <img /> tag.

The code below shows you two different ways to use <f:ajax /> to enhance a standard <h:selectBooleanCheckbox />. The second example is not as common. There is also a <h:commandButton /> which can be used just in case JavaScript is disabled.

A best practice when considering your design is to make sure that the form will perform the expected behavior prior to adding AJAX. Once the AJAX is enabled, check to make sure that the behavior is still as expected.

Code


Popular Posts