Pages

Monday, June 27, 2011

Determining Absolute Path in a Web Application

I was looking at the NetBeans EE forums, and someone asked how to determine the path in a web application. This is a common question so I thought I would provide two examples. The first is a servlet which returns the absolute path to the web application root. The other is a JSF application that does the same thing, and lists the files.
Note: The code is based on Java EE 6.

PathServlet.java



DirectoryLister.java



index.xhtml


Login Page Examples (j_security_check)

I have created a number of login page examples for use with Tomcat 6 which use j_security_check in the browser. There are three examples included:
  1. HTML based login page
  2. HTML and JSF Hybrid login page
  3. JSF based login page

Note: The JSF based login page is REQUIRED to still use an HTML <form> tag.

These examples were developed in NetBeans and are located here: LoginPageExamples.zip.
Enhanced by Zemanta

Sunday, June 26, 2011

How to Check JDK Supported Encodings and Locales

A map of the various different languages in EuropeImage via Wikipedia
I was working on an issue with a customer about supported locales.  The JDK comes in two varieties: one is for only western languages including European languages, and the other is multilingual. This includes languages like Thai which have different glyphs. The supported encodings for Java 6 are defined here: Supported Encodings. The issue was a download of the standard JDK download on Windows which does not include charsets.jar for use in an international application.

I figured out the issue by creating a simple web application to check the encodings. I figured I would provide it just in case other folks may be able to use it Otherwise it would just be good simple code gone to waste. Here is a link to the maven project: SupportedLocales.zip


Enhanced by Zemanta

Saturday, June 25, 2011

SD Times: Inside the Java Community Process

Java Community ProcessImage by Obie Fernandez via Flickr
I just finished reading an article in SD Times June 2011 edition about "Inside the Java Community Process" which details how the JCP works, and its membership. There are some errors and omissions which could have been resolved with a little fact checking. Especially since the material is public.

Becoming a JCP Member details how to become a member. The article mentions educational, governmental, and non-profits must pay $2,000.00 USD per year to become members. However, there is an exception for Java User Groups. Java User Groups can participate for FREE. The details are Java User Groups get free first row seats in the JCP!. This was a serious omission since, we (Java Users Groups) have two seats on the Java Standard Edition (SE) Executive Committee (EC), and the article refers to this later. Any JUG can participate in the JCP and a representative can be elected, or ratified to a seat on the EC.

The author also failed to look at the voting results which clearly show that SouJava and London Java Community (LJC) were elected, and not Central Ohio Java Users Group. I hope in future elections to see dedicated Java Users Groups like Central Ohio Java Users Group to get a seat, but this was not the case for the special elections. Congratulations to both SouJava and London Java Community on their election by the JCP community.

I like the SD Times, but this is basic journalism to check facts, and be clear.

Enhanced by Zemanta

Building PHP 5 on Solaris 10

This is an article I meant to publish a long time ago. I was going through my blog posts, and noticed this entry as a draft from four years ago. I thought it may still be relevant to some folks and decided to publish it. There may be circumstances which require native PHP. This is how I did it using the native version.

Note: Today I would recommend using Quercus on GlassFish 3 instead of using pure PHP.  Please see Quercus PHP 3.2.1 on GlassFish 2.1 as an example of how to implement it.

1. Set the path as follows:

export PATH=/opt/csw/bin:/usr/sfw/bin:/usr/sbin:/usr/bin: \
/usr/openwin/bin:/usr/dt/bin:/usr/ccs/bin


2. Install the following packages from blastwave.org

pkg-get -U
pkg-get -i autoconf
pkg-get -i automake
pkg-get -i gsed
pkg-get -i libxml2


2. Check software revision levels

which autoconf && autoconf --version | head -2
/opt/csw/bin/autoconf
autoconf (GNU Autoconf) 2.59
Written by David J. MacKenzie and Akim Demaille.


which automake && automake --version | head -2
/opt/csw/bin/automake
automake (GNU automake) 1.9.6
Written by Tom Tromey .


which gsed && gsed --version | head -2
/opt/csw/bin/gsed
GNU sed version 4.1.4
Copyright (C) 2003 Free Software Foundation, Inc.


which gcc && gcc --version | head -2
/usr/sfw/bin/gcc
gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
Copyright (C) 2004 Free Software Foundation, Inc.


which gmake && gmake --version | head -2
/opt/sfw/bin/gmake
GNU Make 3.80
Copyright (C) 2002 Free Software Foundation, Inc.

which flex && flex --version | head -2
/usr/sfw/bin/flex
flex version 2.5.4

which bison && bison --version | head -2
/usr/sfw/bin/bison
bison (GNU Bison) 1.875
Written by Robert Corbett and Richard Stallman.

#which gm4 && gm4 --version | head -2
/opt/csw/bin/gm4
GNU M4 1.4.5
Written by Rene' Seindal.

which perl && perl -v | head -2
/opt/csw/bin/perl
This is perl, v5.8.8 built for sun4-solaris-thread-multi

which gunzip && gunzip -V | head -2
/usr/bin/gunzip
gunzip 1.3.3-patch.1
(2002-03-08)

which gtar && gtar --version | head -2
/opt/csw/bin/gtar
tar (GNU tar) 1.15.91
Copyright (C) 2006 Free Software Foundation, Inc.


4. Use the following build script

./configure \
--enable-so \
--with-apxs2=/usr/apache2/bin/apxs \
--enable-fastcgi \
--enable-debug \
--with-zlib \
--with-bz2 \
--enable-calendar \
--enable-dba=shared \
--with-flatfile \
--enable-dbase \
--enable-ftp \
--with-openssl \
--with-ldap \
--with-ldap-sasl \
--enable-soap \
--with-oci8=/opt/oracle/app/oracle/product/10.2.0/db_1 \
--with-libxml-dir=/opt/csw \
--enable-mbstring \
--with-mycrpt

5. Run make all

6. Run make install


Enhanced by Zemanta

CIO Magazine: 5 Things You Need to Know MySQL

MySQLImage via Wikipedia
There is a nice five point things you need to know article about MySQL in CIO Magazine. The number one item is "Rumors of its demise have been greatly exaggerated". Check out the brief article for other interesting bits.
Enhanced by Zemanta

Oracle Magazine: Survey Says

Oracle Magazine (July/August 2011) has a Community Bulletin by Justin Kestelyn. The article details a survey performed on community members (not sure that I took this one, but I generally do take their surveys) about what they want and need from Oracle Technology Network (OTN) and Java.net (not mentioned, but applies). The overall rating was "Good" which I think is a fair assessment. I am happy that the Sun Developer Network (SDN) was merged into OTN. They still need to have a number of links fixed, but in fairness some may have been previously broken. Google often resolves this from a cached version of the link you are looking for if it is broken.

I am very thankful for the upgrades to Java.net, and the continuing support to make it better.

One of the items was the lack of attendance at Virtual Developer Days and Developer days. I have attended a few of them, and some have been very good. It is a gem in the rough, and I think that more developers should attend one to decide on their value. One note is to remove any sales/marketing people from the events. If I like your tech, I will follow-up with your sales people. Marketers are welcome to listen in (mute), but I would like "Marketers are to be unseen and unheard." Please don't misconstrue my remarks to mean these are vendor talks my fellow developers... the sales and marketing people are just sometimes at the events too.

The benefits of membership are not clear on OTN, or Java.net. These should be more prominent.

I was surprised that newsletters were ranked higher than sample code. Who doesn't like good sample code!

Rewards points was a surprise. I can see one thing that Sun did well and Oracle has not gotten down quite yet: T-Shirts. I know it is hard to believe, but we developer like swag, and t-shirts are like a badge of honor. A manager at my former company asked  "Why do you always wear Sun shirts? Why don't you wear our company shirts?" My response was simple: "When you start giving out our shirts for free, I will start wearing them!"

I think that Java.net and OTN are doing good work, and as a community member I would like to thank the teams who make it work everyday. Thanks and keep up the good work.
Enhanced by Zemanta

Thursday, June 23, 2011

NetBeans 7.0 Tip: Generating SerialVersionUID for Serializable Objects

If you are doing any work on a class which implements Serializable, you should take the time to generate a unique serialVersionUID for the class. By default, the IDE will add a serialVersionUID which is defined as 1L.This is a rather poor substitute for doing it correctly. The serialVersionUID is extremely important in Web Development (Session scoped beans must be Serializable), and in Java Persistence API (JPA) which needs to be able to serialize entities.

I have covered this plugin in a previous blog post, but there is an updated NetBeans plugin to help you with serialization. The Kenai project is located here: serialVersionUID generator for Netbeans. The actual downloadable nbm for NetBeans 7.0 is located here: eu-easyedu-netbeans-svuid.nbm. It was the first plugin I looked for when I installed NetBeans 7.0.
Enhanced by Zemanta

Wednesday, June 22, 2011

How Do I Dynamically Change Styles Based on Selection Criteria in JSF?

A recent JUG Meeting featured a fantastic speaker, Arun Gupta, from Oracle. During Arun's Java EE 6 with NetBeans tutorial, a member of the JUG asked a question.
How Do I Dynamically Change Styles Based on Selection Criteria in JSF?

Without disrupting the tutorial, I decided to write a quick application which would change style based on a criteria. In this case, I used the customers name. Specifically, I have a <h:selectOneMenu/> which allows you to pick a letter. This letter changes the style based on whether a customer name begins with the letter. Admittedly, this is contrived, but it demonstrates a point.

The NetBeans project files can downloaded here: VIPCustomers.zip


index.xhtml


<?xml version='1.0' encoding='UTF-8' ?>
<!--
 Copyright 2011 Blue Lotus Software, LLC.
 Copyright 2011 John Yeary.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 under the License.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:head>
        <title>VIP Customer Selection</title>
    </h:head>
    <h:body>
        <h:form>
            <h:selectOneMenu value="#{indexBean.vip}" onchange="submit()">
                <f:selectItems value="#{indexBean.letters}"/>
            </h:selectOneMenu>
        </h:form>
        <ul>
            <ui:repeat value="#{indexBean.customers}" var="customer">
                <li>
                    <h:outputText value="#{customer.name}"
                                  style="#{customer.name.startsWith(indexBean.vip) ? 'color:red': 'color:black'}"/>
                </li>
            </ui:repeat>
        </ul>
    </h:body>
</html>

IndexBean.java


/*
 *  Copyright 2011 Blue Lotus Software, LLC.
 *  Copyright 2011 John Yeary <jyeary@bluelotussoftware.com>.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
/*
 * $Id: IndexBean.java 365 2011-06-23 03:06:01Z jyeary $
 */
package beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.model.SelectItem;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import model.Customer;

/**
 *
 * @author John Yeary <jyeary@bluelotussoftware.com>
 * @version 1.0
 */
@Named
@SessionScoped
public class IndexBean implements Serializable {

    private static final long serialVersionUID = 1L;
    @PersistenceContext
    private EntityManager em;
    private String vip = "B";

    @SuppressWarnings("unchecked")
    public List<Customer> getCustomers() {
        return (List<Customer>) em.createNamedQuery("Customer.findAll").getResultList();
    }

    public String getVip() {
        return vip;
    }

    public void setVip(String vip) {
        this.vip = vip;
    }

    public List<SelectItem> getLetters() {
        List<SelectItem> items = new ArrayList<SelectItem>();
        for (int i = 65; i < 91; i++) {
            items.add(new SelectItem(String.valueOf((char) i), String.valueOf((char) i)));
        }
        return items;
    }
}

Enhanced by Zemanta

Monday, June 20, 2011

NetBeans Tip: How to Add a © Symbol to NetBeans Javadocs

This is some ways is an easy tip. If you are creating Javadocs as part of your project, manage it from the IDE with the project properties. You can include a copyright © along with your company, or personal name by adding the following to the Additional Javadoc Options:
-footer "&#169; 2011 Blue Lotus Software, LLC."
Note: &#169; is Unicode for copyright.

This will result in a copyright being posted on all Javadocs.



Tuesday, June 14, 2011

Dr. Dobbs - Making Large Classes Small (In 5 Not-So-Easy Steps)

User Experience consists of Usability, Look an...Image via Wikipedia
This editorial by Andrew Binstock is really good. As a developer, we often forget to code our applications in a way to focus on the basics for maintenance, extension, usability (re-usability too), and testing. Andrew talks about these in a succinct article which I have linked to below. It is funny how often we forget these items in the "heat of battle" only to rediscover our sins later when trying to maintain our code.

Take a read on the article it is short and sweet.

Making Large Classes Small (In 5 Not-So-Easy Steps)
Enhanced by Zemanta

Monday, June 06, 2011

JSF 2.x Facelets Form Based Authentication (j_security_check)

Previously, I posted an example of how to use JSF 1.2 with form based authentication (j_security_check).

In this example, I use JSF 2.x to perform the same kind of login. The code is very similar, but the logout method has been simplified in JSF 2. There is no need to get the HttpSession object to invalidate the session. Here is my comment from the previous article.
One of the common issues that comes up frequently is how to use form based authentication with JSF with j_security_check. This code example and NetBeans project demonstrate how to use JSF and facelets with various browsers. The code is simple and undecorated. I wanted to make sure it had the broadest browser compatibility.

Maven project: jsf2-login.zip

Note: If you test it with other browsers, please post a comment to let me know what it works on. The list below is what I have available to me.

Compatibility

  • Mozilla Firefox 4
  • Internet Explorer 8
  • Chrome 11
  • Safari 5
  • Opera 11

Note: The xhtml form below did not work on Internet Explorer 8 until I disabled the comments in the web.xml file. There is a comment in the file which also indicates that it is an issue with IE 8.

Note: The login.xhtml form uses an HTML based form and not a JSF <h:form /> tag.

login.xhtml


<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright 2011 Blue Lotus Software, LLC.
 Copyright 2011 John Yeary.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 under the License.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <head>
        <title>Login</title>
    </head>
    <body>
        <form method="post" action="j_security_check" name="loginForm">
            <h:panelGrid columns="2">
                <h:outputLabel id="userNameLabel" for="j_username" value="#{msgs.username}:"/>
                <h:inputText id="j_username" autocomplete="off" />
                <h:outputLabel id="passwordLabel" for="j_password" value="#{msgs.password}:"/>
                <h:inputSecret id="j_password" autocomplete="off"/>
                <div/>
                <h:panelGroup>
                    <h:commandButton type="submit" value="Login"/>
                    <h:commandButton type="reset" value="Clear"/>
                </h:panelGroup>
            </h:panelGrid>
        </form>
    </body>
</html>

SessionBean.java


/*
 *  Copyright 2011 Blue Lotus Software, LLC.
 *  Copyright 2011 John Yeary <jyeary@bluelotussoftware.com>.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
/*
 *  $Id:$
 */
package com.bluelotussoftware.example.jsf.login;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

/**
 *
 * @author John Yeary <jyeary@bluelotussoftware.com>
 * @version 1.0
 */
@ManagedBean
@SessionScoped
public class SessionBean implements Serializable {

    private static final long serialVersionUID = 916055190609044881L;

    /**
     * Default constructor.
     */
    public SessionBean() {
    }

    /**
     * Logs the current user out by invalidating the session.
     * @return &quot;logout&quot; which is used by the {@literal faces-config.xml}
     * to redirect back to the {@literal index.xhtml} page.
     */
    public String logout() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        externalContext.invalidateSession();
        return "logout";
    }
}

Enhanced by Zemanta

Internet Explorer 8 and XHTML Comments

Never Internet ExplorerImage via Wikipedia
Yesterday, I posted a JSF 1.2 login example using nearly pure JSF. I discovered the answer to a bug which was not documented anywhere that I can find. The issue has to do with comments. Internet Explorer 8 seems to choke on them. When I created the example yesterday, I tested it extensively on a number of modern browsers that I have available to me. It works perfectly as expected... with one exception. The other browsers treat the <-- COMMENT --> perfectly. Internet Explorer can not seem to digest it. There is likely some reason (READ EXCUSE) for this behavior, but I can not seem to fathom it. The result on the login page is to cause the browser to spin until timeout, and then re-render the previous page.

This error seems to not care if the DOCTYPE is declared before, or after the comment. I checked just in case.

OK...So I found a bug, but how do you fix it. Well, it is really easy.
  1. Remove all the comments from the page. This is bad for obvious reasons.
  2. If you are using facelets, we have two methods available depending on the version of JSF you are using.
    • JSF 1.2 - Add this context parameter to the web.xml
      <context-param>
              <description>
                  If comments are enabled, the copyright header will prevent the login form
                  from working on Internet Explorer. Alternatively, you can remove the copyright
                  header.
              </description>
              <param-name>facelets.SKIP_COMMENTS</param-name>
              <param-value>true</param-value>
          </context-param>
      
    • JSF 2.x - Add this context parameter to the web.xml
      <context-param>
              <description>
                  If comments are enabled, the copyright header will prevent the login form
                  from working on Internet Explorer. Alternatively, you can remove the copyright
                  header.
              </description>
              <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
              <param-value>true</param-value>
          </context-param>
      

Once you disable the comments, the login page works perfectly. The comments also apparently cause issues with rendering RichFaces pages which now work without issue, or compatibility mode hacks.
Enhanced by Zemanta

Sunday, June 05, 2011

JSF 1.2 Facelets Form Based Authentication (j_security_check)

Simple Login Screen
One of the common issues that comes up frequently is how to use form based authentication with JSF with j_security_check. This code example and NetBeans project demonstrate how to use JSF and facelets with various browsers. The code is simple and undecorated. I wanted to make sure it had the broadest browser compatibility.

Maven project: jsf12-login.zip

Note: If you test it with other browsers, please post a comment to let me know what it works on. The list below is what I have available to me.

Compatibility

  • Mozilla Firefox 4
  • Internet Explorer 8
  • Chrome 11
  • Safari 5
  • Opera 11

Note: The xhtml form below did not work on Internet Explorer 8 until I disabled the comments in the web.xml file. There is a comment in the file which also indicates that it is an issue with IE 8.

Note: The login.xhtml form uses an HTML based form and not a JSF <h:form /> tag.

login.xhtml


<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright 2011 Blue Lotus Software, LLC.
 Copyright 2011 John Yeary.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 under the License.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <head>
        <title>Login</title>
    </head>
    <body>
        <form method="post" action="j_security_check" name="loginForm">
            <h:panelGrid columns="2">
                <h:outputLabel id="userNameLabel" for="j_username" value="#{msgs.username}:"/>
                <h:inputText id="j_username" autocomplete="off"/>
                <h:outputLabel id="passwordLabel" for="j_password" value="#{msgs.password}:"/>
                <h:inputSecret id="j_password" autocomplete="off"/>
                <h:commandButton type="submit" value="Login"/>
                <h:commandButton type="reset" value="Clear"/>
            </h:panelGrid>
        </form>
    </body>
</html>

SessionBean.java


/*
 *  Copyright 2011 Blue Lotus Software, LLC.
 *  Copyright 2011 John Yeary <jyeary@bluelotussoftware.com>.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
/*
 *  $Id:$
 */
package com.bluelotussoftware.example.jsf.login;

import java.io.Serializable;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author John Yeary <jyeary@bluelotussoftware.com>
 * @version 1.0
 */
public class SessionBean implements Serializable {

    private static final long serialVersionUID = 916055190609044881L;

    /**
     * Default constructor.
     */
    public SessionBean() {
    }

    /**
     * Logs the current user out by invalidating the session.
     * @return &quot;logout&quot; which is used by the {@literal faces-config.xml}
     * to redirect back to the {@literal index.xhtml} page.
     */
    public String logout() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        HttpSession session = (HttpSession) externalContext.getSession(false);
        session.invalidate();
        return "logout";
    }
}
Enhanced by Zemanta

JSF 1.2 (Mojarra) Reference Implementation (RI) on Google App Engine

Image representing Google App Engine as depict...Image via CrunchBase
I am working on publishing the various methods for deploying JSF on Google App Engine. This example is deployed using JSF 1.2 reference implementation. I am using NetBeans 6.9.1 with the Google App Engine plugin. The code used is vanilla JSF with no additional frameworks.

The web.xml and Maven pom.xml files are posted on the deployed application which is running on the App Engine itself.

The implementation can be found here: http://gae-jsf12.bluelotussoftware.com/
Enhanced by Zemanta

Saturday, June 04, 2011

Java Architecture for XML Binding (JAXB) Article

I was looking over the Java Architecture for XML Binding (JAXB) By Ed Ort and Bhakti Mehta from March 2003. It is a very good tutorial on JAXB, but it needed a little updating on some of the example code.

I am not sure how to get the code updated so, I will provide my modified version of UsingJAXBTest1. It uses generics, StringBuilder, and an enhanced for loop. I also removed some deprecated methods. Here is my new modified version with the original copyright.

UsingJAXBTest1


/**
 * $Id: UsingJAXBTest1.java,v 1.1 2003/01/01 03:18:32 bhakti Exp $
 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 */
package test.jaxb;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.util.List;

/**
 * This shows how to use JAXB to unmarshal an xml file
 * Then display the information from the content tree
 * @author bhakti
 * @author John Yeary
 */
public class UsingJAXBTest1 {

    public static void main(String args[]) {
        try {
            JAXBContext jc = JAXBContext.newInstance("test.jaxb");
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            Collection collection = (Collection) unmarshaller.unmarshal(new File("books.xml"));
            Collection.Books booksType = collection.getBooks();
            List<BookType> bookList = booksType.getBook();
            StringBuilder sb = new StringBuilder();

            for (BookType book : bookList) {
                sb.setLength(0);
                sb.append("Book  details\n");
                sb.append("Item id: ");
                sb.append(book.getItemId());
                sb.append("\n");
                sb.append("Book Name: ");
                sb.append(book.getName().trim());
                sb.append("\n");
                sb.append("Book ISBN: ");
                sb.append(book.getISBN());
                sb.append("\n");
                sb.append("Book Price: ");
                sb.append(book.getPrice().trim());
                sb.append("\n");
                sb.append("Book category: ");
                sb.append(book.getBookCategory());
                sb.append("\n");
                sb.append("Book promotion: ");
                sb.append(book.getPromotion().
                        getDiscount().trim());
                sb.append("\n");
                sb.append("No of Authors ");
                sb.append(book.getAuthors().getAuthorName().size());
                sb.append("\n");

                BookType.Authors authors = book.getAuthors();
                for (int j = 0; j < authors.getAuthorName().size(); j++) {
                    String authorName = authors.getAuthorName().get(j);
                    sb.append("Author Name ");
                    sb.append(authorName.trim());
                    sb.append("\n");
                }
                System.out.print(sb.toString());
            }

        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
}

Wednesday, June 01, 2011

OSCON 2011- Committee Discount Code

Anyone attending OSCON Java in July will want to use the discount code provided to the committee members.

Please use OS11COM to get a 20% discount for attending the event.

It was an honor and privilege to review papers for OSCON, and OSCON Java, and I hope everyone who attends likes the speakers that we selected to speak. I am excited about the event, and I hope you will be too. This is the inaugural event for OSCON Java and I hope there will be many more.