How To Build A JSF Application UIT JSF 2.0.3 · last update: may 2011 how to build a jsf...

27
Last Update: May 2011 HOW TO BUILD A JSF APPLICATION INTEGRANOVA USER INTERFACE TRANSFORMATION ENGINE WEB JSF

Transcript of How To Build A JSF Application UIT JSF 2.0.3 · last update: may 2011 how to build a jsf...

  • Last Update: May 2011

    HOW TO BUILD A JSF APPLICATION

    INTEGRANOVA USER INTERFACE TRANSFORMATION ENGINE WEB JSF

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 1

    Table of Contents 1 Document purpose ...................................................................................................................2

    1.1 What is the use of this document? ..................................................................................2 2 Environment configuration..................................................................................................3

    2.1 Folder structure ......................................................................................................................3 2.2 Environment variables configuration ..............................................................................4

    3 How to deploy an application with an IDE .................................................................6 3.1 Common steps ........................................................................................................................6 3.2 Eclipse Europa .........................................................................................................................7

    3.2.1 Building the project ....................................................................................................................... 7 3.2.2 Application server installation.................................................................................................... 9 3.2.3 Starting up the application........................................................................................................ 12

    3.3 NetBeans 6.0 .........................................................................................................................13 3.3.1 Building the project ..................................................................................................................... 13 3.3.2 Starting up the application........................................................................................................ 16

    4 How to connect with Server application....................................................................17 4.1 Connection with a C# Server (ASPListener.asp) .....................................................17

    4.1.1 ASPListener.asp source code ................................................................................................... 18 4.1.2 Virtual folder with ASPListener.asp webpage..................................................................... 19 4.1.3 Configuration of the JSF user interface application ......................................................... 21

    4.2 Connecting with an EJB Server.......................................................................................21 4.2.1 HTTP Connection........................................................................................................................... 21 4.2.2 JNDI Connection ........................................................................................................................... 22

    5 Setting up JBoss for listening in a public IP address ........................................24 6 Setting up a client application to work with URL rewriting ...........................26

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 2

    1 Document purpose 1.1 What is the use of this document? The purpose of this document is showing how to start working with a JSF application developed under the MVC pattern. It will show how to build and deploy a client application by using the two most used Integrated Development Environments (IDE) Eclipse and NetBeans. It will also explain how to connect with a server application generated by the Integranova Transformations Engines:

    Server C# through an ASP proxy Server EJB through JNDI and HTTP

    At the end, a tip can be found for publishing JBoss in a network.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 3

    2 Environment configuration 2.1 Folder structure In order to have a folder structure that is comfortable for configuring Java applications, it is possible to install the Server, IDE and libraries in a common tree folder as follows:

    Figure 1 Folder structure This folder structure is not mandatory but has been introduced into this document because in some sections it could be a guide for helping the User. In this case _JAVA is the main folder and contains 4 folders:

    ANT: Apache compiler version 1.7.0. IDE: For installing the Eclipse Europa environment. It is possible to install other

    Java development environments but this one is available free on the eclipse web page http://www.eclipse.org/. The Eclipse IDE does not need to be installed, just directly unzip the downloaded file from the eclipse web page to IDE folder in the folder tree structure explained.

    JDK: Java Development Kit libraries. The last jdk version is JDK 6 and is available on the Sun webpage http://java.sun.com/javase/downloads/index.jsp.

    APPLICATION SERVERS: Application servers where the JSF user interface will run. In this case the server used has been JBoss.

    http://java.sun.com/javase/downloads/index.jsphttp://www.eclipse.org/

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 4

    2.2 Environment variables configuration The environment variables needed to run the Java applications must be configured in the advanced system properties:

    Figure 2 Environment variables configuration form These environment variables must be added if they dont exist, or edited if they do

    exist.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 5

    Figure 3 Environment variables Path environment variable must be edited adding the JDK folder \bin.

    Figure 4 Path environment variable

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 6

    3 How to deploy an application with an IDE Modern IDEs provide the functionality needed to build and deploy an application in an easy and integrated way. Eclipse and Netbeans are the most commonly used IDEs, in their original distribution or as base for other popular distributions such as Sun Java Studio Creator, IBM WebSphere Studio or JBoss Developer Studio.

    3.1 Common steps JSF applications usually need a set of additional libraries. There are two different ways to add these required libraries:

    According to JSF specification, these libraries should be copied into the lib folder from the \ProjectName\WebContent\WEB-INF\ application path. Eclipse automatically detects them and they are added to the final *.war when the application is compiled.

    The other possibility is to copy the libraries into the lib folder from the application server deploy path. For example, if JBoss server is used, libraries should be copied in \APPLICATION_SERVERS\jboss-4.2.0.GA\server\default\lib path. The advantage of this option is that the application and the generated *.war file, when they are compiled, have their size greatly reduced, because they do not hold the libraries, but on the other hand, to develop the application in the Eclipse environment they should be manually referenced into the project build path.

    Refer to the Release Report of the Transformation Engine version which is used to obtain the code in order to know which Java libraries are needed.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 7

    3.2 Eclipse Europa The version used to explain how to build and deploy a client application will be 3.3, which is known as Europa. It is necessary to install a plugin from the Europa Discovery Site which is named Web Tools Platform (WTP). This plugin allows working with dynamic web projects in a more comfortable way. Install the Web Tool Platform (WTP) plugin in Eclipse

    3.2.1 Building the project In the Eclipse IDE, select File New Others in the main menu. In this window menu, the Dynamic Web Project needs to be selected in order to add the project required .

    Figure 5 Others windows menu In the following window it will be possible to assign a project name. Moreover, the project path where the JSF project is located will be selected. The Use Default check box must be unchecked and the project path will be selected by pressing the Browse button. Select the desired target runtime and configuration, JBoss in the example below. It is possible to create new target runtimes by means of the New button.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 8

    Figure 6 Dynamic Web Project options window In the following window, the default options should be used.

    Figure 7 Dynamic Web Project configuration window The following window gives the possibility of specifying the Java source code directory.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 9

    Eclipse suggests src but the source code folder name, recommended by the Java BluePrints, is named JavaSource:

    Figure 8 JavaSource directory After that, press the Finish button and the project will be correctly configured.

    3.2.2 Application server installation At the bottom in Eclipse IDE some tabs appear, one of them belongs to Servers. If the Servers tab does not appear by default in the IDE view, it is possible to display it from the main menu Windows Show View Other and by selecting the option Servers in the Server as shown in the following diagram:

    Figure 9 Show View menu options By placing the mouse pointer on the Servers window then pressing the right button on the

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 10

    mouse, by selecting the option New Server it is possible to add an Applications Server. In this example the selected Server is a JBoss 4.2.0 version, as shown in the following diagram:

    Figure 10 New Server window In the next window it is possible to edit the Server configuration:

    Figure 11 Server configuration window The final step in the addition of the new server allows projects to be added that will run on the Server engine.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 11

    Figure 12 Add and remove projects window With these steps the applications server will be configured and initialised in Stopped state. To Start the server, the Start option must be selected and pressed from the contextual menu from the mouse right button, buttons toolbar, main menu Run, etc.

    Figure 13 Eclipse environment picture

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 12

    3.2.3 Starting up the application When the system is correctly configured, it will be necessary to start a console window, location in the \AppDirectory\ant folder of the application path as shown in the following console diagram:

    Figure 14 Console picture with example application path In this location, command ant will be executed and the application will be built.

    Figure 15 Application build When the application is compiled, the *.war file will be created in \AppDirectory\build folder:

    Figure 16 *.war File build

    The final steps consist of deploying this *.war file created in the server. In this example the Jboss server was used. In order to deploy the *.war file, it will be copied into the \server\default\deploy folder of the Server application path installation.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 13

    And to run the server as shown in the following diagram from the \bin folder in the server path installation with command run:

    Figure 17 Run server When the server is started, it will be possible to run the application by introducing the URL in the browser, pointing to the *.war file included in the \deploy folder.

    Figure 18 Application opened in a browser

    3.3 NetBeans 6.0 With NetBean 6.0 it is possible to build and deploy a client application in Glassfish or Tomcat out of the box.

    3.3.1 Building the project Select the File New Project menu option. Then choose a Web project and Web Application with Existing Sources

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 14

    Figure 19 Creating a new Web Project In the following dialog, enter the full path to the client application source code. The name of the project and the context, in which the application will be deployed, can be also set.

    Figure 20 Location of the client application source code Finally, NetBeans will ask for paths to different client application parts. It will suggest values according to the client application structure. To accept the suggestions just click

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 15

    the Finish button.

    Figure 21 Source and library folders The project application is now opened in the NetBeans IDE.

    Figure 22 The just created application project

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 16

    3.3.2 Starting up the application It is possible to start the application just by clicking in the project with the secondary mouse button and then selecting Run or Debug. NetBeans will deploy the client application in the Application Server and will start the application server if it is stopped. It will finally launch the internet navigator to use the application.

    Figure 23 Starting up the application By default, GlassFish is the application server selected by NetBeans but it is possible to change it to one of the Application Servers which are already installed.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 17

    4 How to connect with Server application 4.1 Connection with a C# Server (ASPListener.asp) An ASPListener.asp is a webpage that redirects XML requests from a User interface application to an Integranova server, and vice-versa. So that it is not necessary to install a proxy.

    Figure 24 ASPListener.asp connection

    COM+

    Integranova Server

    Integranova client

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 18

    4.1.1 ASPListener.asp source code

    Dim ServerName 'As String Dim Provider 'As Object Dim l_str 'As String

    ServerName = "AppSrvNS.XML"

    Session.Codepage=65001

    set stream = createobject("adodb.stream") stream.type=1 stream.open stream.write Request.BinaryRead(Request.TotalBytes)

    stream.position = 0 stream.type=2 stream.charset="UTF-8" l_str=stream.readtext stream.close set stream=nothing

    Set Provider = Server.CreateObject(ServerName & ".XML_Listener")

    If Not (Provider is nothing) Then Response.Write (Provider.XMLRequest(l_str))

    Else Response.Write "" Response.Write ""

    Response.Write " " Response.Write " " Response.Write "XMLListener could not connect with " & ServerName

    & " server." Response.Write " " Response.Write "" Response.Write ""

    End If

    Figure 25 ASPListener.asp file content Variable ServerName in the ASPListener.asp source code and coloured yellow is the server name invoked from the web page.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 19

    4.1.2 Virtual folder with ASPListener.asp webpage It is necessary to create a virtual folder in IIS (Internet Information Services) that includes the asp webpage. This virtual folder must have execution permissions as Scripts and Executables types. An example is shown in the following diagram:

    Figure 26 ASPListener properties In addition the access has to be configured:

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 20

    Figure 27 ASPListener properties

    Figure 28 Authentication properties

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 21

    4.1.3 Configuration of the JSF user interface application The user interface configuration needs to find the application server referenced in the ASPListener file. For this the connection string value must be the ASPListener.asp URL. The URL format contains the server name where the ASPListener.asp webpage is located, the name of the virtual folder in IIS and the name of the *.asp.webpage.

    connectionStringhttp://host:port//ASPListerner.asp

    Figure 29 Connection string configurations in JSF user interface application The connection string value can be modified in the web.xml file located in WEB-INF folder.

    Figure 30 File location where edited connection string

    4.2 Connecting with an EJB Server In order to connect with an EJB Server, JBoss server or any other server, it needs to be started in the same way as explained in section 4.1 (4.1 Startup application) of this document and shown in the following diagram.

    Figure 31 Start the JBoss server

    4.2.1 HTTP Connection After that the JSF User interface will be configured to point to the EJB Server. This configuration consists of an URL composed by the applications server (host), EJB ServerName Integranova application with the xml string at the end, and the invocation

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 22

    servlet. The following may be an example: http://host:port/xml/invxmlThis URL will be introduced in the connection string param value of the web.xml file from the JSF User interface:

    connectionStringhttp://host:port/xml/invxml

    Figure 32 web.xml file content

    4.2.2 JNDI Connection JNDI Connection is used to communicate only with Integranova EJB servers. The JNDI connection is configured by a property file located in the JavaSource folder of the client application that is named jndi.properties after a java naming convention, so the JVM can find it and override its own default settings.

    Figure 33 jndi.properties file location There are two ways of using the JNDI connection:

    1- Client and server application within the same Application server.

    2- The client in one Application Server and the server in a different one.

    Figure 34 JNDI Communication

    Server App

    JNDI Server

    ApplicationServer

    Application Server

    Client App

    Application Server

    Server AppClient App

    JNDI Server

    http://host:port/xml/invxml

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 23

    Same Application Server This is the easiest way of using the JNDI connection. Typically the JNDI server will be the same application server publishing the applications, so the jndi.properties file can be edited to hold the proper information, or simply removed so the JVM uses the default settings to locate the JNDI server.

    Different Application Server In this case there are two things that have to be done before deploying the application.

    Edit the jndi.properties file to point the JNDI server holding the server application. Copy the RemoteAPI.jar file from the server build folder with

    the other application libraries (see section Setting application libraries). The RemoteAPI.jar file can be obtained by running the BuildRemoteLib target in the ANT Script file from the server application.

    Figure 35 RemoteAPI.jar library destination

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 24

    5 Setting up JBoss for listening in a public IP address

    By default the server is listening for requests at the address 127.0.0.1 (localhost) in the port 8080, so it is not accessible from any computer other than the one holding it. To change this default configuration, the JBoss AS with the -b option needs to be started followed by the server IP address. There are several ways to do this:

    1- Execute the JBoss start script with the mentioned option:

    C:\[JBOSS_FOLDER]\bin>run.bat b 192.168.0.1

    2- Modify the JBoss start script in order to use the new option:

    [] echo ======================================================================= echo. echo JBoss Bootstrap Environment echo. echo JBOSS_HOME: %JBOSS_HOME% echo. echo JAVA: %JAVA% echo. echo JAVA_OPTS: %JAVA_OPTS% echo. echo CLASSPATH: %JBOSS_CLASSPATH% echo. echo ======================================================================= echo.

    :RESTART "%JAVA%" %JAVA_OPTS% "-Djava.endorsed.dirs=%JBOSS_ENDORSED_DIRS%" -classpath "%JBOSS_CLASSPATH%" org.jboss.Main b 192.168.0.1 %* if ERRORLEVEL 10 goto RESTART []

    3- If the JBoss is to be launched from Eclipse, modify the server launch configuration.

    a. Open the JBoss Server Configuration

    Figure 36 Opening the server configuration

    b. Edit the host name and address information.

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 25

    Figure 37 JBoss Eclipse configuration

    c. Finally add the new argument in the dialogue displayed when pressing the Open lunch configuration link.

    Figure 38 JBoss arguments

  • How to build a JSF application / UIT_JSF

    Integranova, S.A. 2011 26

    6 Setting up a client application to work with URL rewriting

    The JSF client applications are able to work in an application server that is configured to append the session ID in the URL by using URL Rewriting, but a little configuration work has to be done. This is due to problem in the Ajax4JSF library. The Ajax4JSF library does not append the session ID to the linked JavaScript file.

    Instead of:

    To force the code to correct this issue, change the value of the URLRewriting context parameter in the web.xml file:

    URLRewriting true

    The possible values are:

    true If the URLRewriting capabilities of the AS will be used. false If the URLRewriting capabilities of the AS wont be used.

    When the application is configured to use this feature, the browser may inform that a JavaScript error occurred. This happens because the Ajax4JSF framework does not append the session ID to the linked script, so the application server is unable to find it, but the code links the correct script using the session ID in the link, so it will perfectly work.

    1 Document purpose1.1 What is the use of this document?

    2 Environment configuration2.1 Folder structure2.2 Environment variables configuration

    3 How to deploy an application with an IDE3.1 Common steps3.2 Eclipse Europa3.2.1 Building the project3.2.2 Application server installation3.2.3 Starting up the application

    3.3 NetBeans 6.03.3.1 Building the project3.3.2 Starting up the application

    4 How to connect with Server application4.1 Connection with a C# Server (ASPListener.asp)4.1.1 ASPListener.asp source code4.1.2 Virtual folder with ASPListener.asp webpage4.1.3 Configuration of the JSF user interface application

    4.2 Connecting with an EJB Server4.2.1 HTTP Connection4.2.2 JNDI ConnectionSame Application ServerDifferent Application Server

    5 Setting up JBoss for listening in a public IP address6 Setting up a client application to work with URL rewriting