The Source for Java Technology Collaboration
User: Password:



Dru Devore's Blog

February 2008 Archives


Web Service Creation error with Glassfish 2

Posted by ddevore on February 28, 2008 at 05:40 PM | Permalink | Comments (1)

Lately I have been working with EJB 3.0, and I love it. For quick tests and to see what is being returned I threw web services around them. The services ended up being a really nice and easy test though it pointed out a bug in Glassfish 2. The bug has beenentered as an issue in Glassfish here if you are interested. Basically the problem is that if you have two services with operations that have the same name the WSDL generation becomes confused and creates the WSDL definition for one of the operations and uses it for both of the services. This leads to a problem that one of the operations will always throw an exception. If this isn't bad enough the duplicated operation is not always the same one, this took a while to track down why my service was erroring because sometimes it would throw an exception and sometimes it wouldn't.

Anyway I posted the problem to the Glassfish mail group and Bhakti Mehta replied and confirmed the bug and submitted it as an issue for me. He also found a workaround for me. So if you are having a problem simply add the following two annotations to the operations that are having the problem.

@RequestWrapper(className="servicetwoRequest")@ResponseWrapper(className="servicetwoResponse")

Thanks Bhakti for the help.



JSF Tables with POJOs in NetBeans 6.0

Posted by ddevore on February 12, 2008 at 07:24 PM | Permalink | Comments (8)

This is an addition to the JSF Visual Web JavaServer Faces in NetBeans Tutorial. For this information to be useful to you, you will have to have a JSF Visual Web JavaServer Faces project created. To create the project please refer to the earlier blog. Also, this tutorial is basically a continuation of the JSF Tables with databases in NetBeans 6.0 so you may want to also take a look at that it.

Useful Data

I know that a lot of people out there in the Java world will agree that the table and other components, such that are found in JSF, are not useful in larger installations if the data only comes directly from a database. Most larger installations will require a MVC architecture and will even hide the data behind services and data access layers. Because of this I will now show you how to bind the table used in the last blog to an array as might be returned by a service.

Data Model

First we must have a data object to work with so lets make one for the address. First I made a package named model under the existing jsf.tutorial package then a class Address with all the same fields as in the database, just to keep things consistent. If you are really observant you will see that I changed the structure of my address to be more international, I changed the zip to postalCode and added a countryCode. The following is the Address class that I will use.
package jsf.tutorial.model;

public class Address {
    private int id;
    private int type;
    private String line1;
    private String line2;
    private String city;
    private String state;
    private String postalCode;
    private int countryCode;
    private String note;

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public int getCountryCode() {
        return countryCode;
    }

    public void setCountry(int countryCode) {
        this.countryCode = countryCode;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLine1() {
        return line1;
    }

    public void setLine1(String line1) {
        this.line1 = line1;
    }

    public String getLine2() {
        return line2;
    }

    public void setLine2(String line2) {
        this.line2 = line2;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
    
}

As a side note you must love the auto generation provided by IDEs.
Next we will put an array of the Addresses in the SessionBean1.
private Address[] addressArray;

public Address[] getAddressArray() {
    return addressArray;
}

public void setAddressArray(Address[] addressArray) {
    this.addressArray = addressArray;
}

Once we have done this we can then switch over to the Designer of Page1 and change the binding of the table to addressArray. If you right click on the table and select Bind to Data you will not see the addressArray though, which is a bug. For it to show up in the dropdown list in the Bind to Data dialog you must clean and build the project, do this now. Once it is cleaned and built you can then right click on the table and select Bind to Data and drop the list down and you will see addressArray (SessionBean1). Selecting this will give you a list of tables in alphabetical order which is not that hard to change, simply select the column and move it up or down. In this dialog you can also select which rows you do and do not want shown.

Other things you can do


You can select each column and change the header text to capitalize the first chars if you would wish, this being the most noticeable at first. But you can change just about any property from the property editor upon selecting the column or table. If you would like you can also go into the JSP selection to modify it directly but that isn't nearly as fun as doing it in the designer. The property I like the most is the pagination settings on the table itself. You can add pagination to the table easily and give the user control that would normally require a lot of work.

This is supposed to be able to work with Lists also but I have not seen it work yet. If anyone can confirm that it works with Lists and what build it works with please let me know.

That is it for now I hope you have enjoyed working with the tables with POJOs.


JSF Tables with databases in NetBeans 6.0

Posted by ddevore on February 05, 2008 at 06:42 PM | Permalink | Comments (4)

This is an addition to the JSF Visual Web JavaServer Faces in NetBeans Tutorial. For this information to be useful to you you will have to have a JSF Visual Web JavaServer Faces project created. To create the project please refer to the earlier blog. This is the project I will be working with in this tutorial.

Empty Table

This is what you would do to start with most of the components in JSF. First open Page1.jsp and you will see the Design selected with the nice grid.



The next step is to select the Table from the Palette and click in the Designer. At this point you will have a page that looks like this.



If you run the project at this point you will get a page that looks just like the Designer above. This is because the default table data object DefaultTableDataProvider provides some data by default. The next step is to put some data into the table that is not simply the default.

Database data in Table

For this part you will need a database connection defined, please check here to create a connection. Once the database is defined open the page designer with the table in it and select the Services tab. For this tutorial I have a database named JSFTutorial in MySQL with a table named address.



I will be using the address table, since it is the only table I currently have defined. To bind the JSF table to the address table simply drag and drop the table from the Services tab to the JSF table in the designer. You will now be asked to choose a target, select table1. Once do this you will see the table change to reflect the same number of rows as the address table with the same names as the columns.



That is all there is to binding a database to a JSF Table in NetBeans 6.0.

You can now change the column names and the table name by simply clicking on them or selecting the JSP tab of Page1 and change the headerText attributes. You can also select the table and check out the properties and see what they do, pagination is really cool. Next time I will discuss how to use different types of data for the table.

JSF Visual Web JavaServer Faces in NetBeans Tutorial

Posted by ddevore on February 02, 2008 at 07:38 AM | Permalink | Comments (1)

I recently started working with JSF for more than simply messing around with the components. In performing this work I have found that some of the information needed to develop JSF seems to be missing or hard to find. Because of this I have decided to write up what I have found to pass along the joy of JSF.

Because the tutorials for working with Visual Web JavaServer Faces in NetBeans will require a project I will start by describing how to create a project. This should work in pre 6.0 but I have used 6.0 and the latest 6.1 dev version for this blog.

Create the Project

Select File -> New Project. In the dialog select Web category and Web Application project then click Next.

Choose a Project

In the next dialog give the project a name, I named mine JSFTableTutorial, and keep the default for Server, Java EE Verion, and Context Path. Then click Next.

Name the Project

In the final dialog select Visual Web JavaServer Faces for the framework and please change the Default Java Package, mine is com.jsf.tutorial yes I know it is not a good package name but it is better then the default jsftabletutorial. The rest leave as the defaults.

Choose the Frameworks

When you get done you will have a view in NetBeans similar to this.

Project View

This view shows the designer and the palette also in case you are unfamiliar with the NetBeans designer.

If you didn't get here from one of the tutorials on using JSF components you may be wondering why I wrote this. The reason is because I am writing multiple tutorials on using JSF components which all will need a project so here it is.

Please check back for a list of tutorials on using JSF components.





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds