Featured Posts

Integrating GlassFish Application server with Apache... A typical production topology for GlassFish will be a front ending GlassFish with Apache for serving the static files. To integrate GlassFish Application Server with Apache web server follow the below...

Readmore

Some Java, JEE and WebSphere stuffs Rss

Hello World JSF with Eclipse

Posted by Albin Joseph | Posted in Eclipse | Posted on 03-04-2009

0

Hello World JSF with Eclipse

Again I am here with a Hello World program. This time I will be explaining how to create a Hello World program using Eclipse. This tutorial needs Eclipse with JBoss Tools installed. This program will accept the name as the input and print Hello Name as the output. To create your first JSF program using Eclipse, follow the below steps.

1. Click on File->New->JBoss Tools Web->JSF->JSF Project. Enter a name for your project and complete the new project wizard. The name I used for creating the project was HelloJSF.

new_project

2. Now go to the WEB-INF folder under WebContent directory and open the faces-config.xml. Make sure that you have opened the file with ‘JBoss Tools XML editor’.

2. Now right click on the editor and select ‘New View’

new_view

3. Enter the name of the new view you want to create.

jsp_process_view

4. Create another view with JSP name output.jsp. The first view will be used for accepting the input parameter and the second JSP (view) will be used for printing the message. After creating both the views, the faces-config.xml will look like the following diagram.

faces-config

5. Now we need to create the navigation rule. Click on ‘Create New connection’ icon from the palette.

new_connection

6. Click on the input.jsp and then output.jsp from faces-config.xml to create the new connection. The new faces-config.xml will look like the one below.

faces-config_with_connection

7. Now we need to create a managed bean for storing the data that we are inputting. Create a new java bean with a property ‘name’. The complete source code for new bean is given below.

package com.albees.jsf;
 
public class HelloBean {
	private String name;
 
	public HelloBean(){
 
	}
 
	public String getName() {
		return name;
	}
 
	public void setName(String name) {
		this.name = name;
	}
}

8. Click on the tree tab from the bottom of faces-config.xml editor.

9. Click on Managed Beans

10. Click on Add and browse for the bean we have created in step 7. Enter a name for your bean.

new_managed_bean

11. Click on Next. From the new window select the name property.

managed_properties

12. Click on Finish. The updated faces-config.xml with managed bean will look like the following figure.

faces-config_with_managed_bean

13. Now it’s the time to edit our JSP files.

14. Open the input.jsp and enter the following code.

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
 
<html>
	<head>
		<title></title>
	</head>
	<body>
		<f:view>
			<h:form id="frmHello">
				Enter your name : <h:inputText id="name" value="#{helloBean.name}" />
				<h:commandButton value="Submit" action="output" />
			</h:form>
		</f:view>
	</body>
</html>

Here value is the property of managed bean where we want to store our entered data. Action should be the name of the view we created for outputting the data.

For those who do not want to type all these code, you can drag and drop the form, inputText and commandButton components from Snippet view and edit the details using the properties window

snippet_view

16. Edit the output.jsp file. The complete source code for output.jsp is

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
 
<html>
	<head>
		<title></title>
	</head>
	<body>
		<f:view>
			Hello <h:outputText value="#{helloBean.name}" />!
		</f:view>
	</body>
</html>

We are done with our first JSF program. Add the project to the server and access the page using the URL. http://localhost:8080/HelloJSF/input.jsf. If you are getting a ClassNotFoundException for your managed bean, your output folder might be pointing to a wrong directory. To fix this right click on the project and select properties. Select Java Build Path and make sure that your default output folder points to HelloJSF/WebContent/WEB-INF/classes directory.

org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Log4JLogger does not implement Log

Posted by Albin Joseph | Posted in JBoss Developer Studio | Posted on 05-01-2009

2

I was helping my team to migrate an application that was running on WebSphere Application Server to JBoss. The web application was using struts as the framework. The application did not show any error message in the IDE. The IDE we were using was JBoss Developer Studio. However at the time of deployment we get an error message like this

INFO  [ContainerBase] Marking servlet action as unavailable
ERROR [ContainerBase] Servlet /XXXWeb threw load() exception
	org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Log4JLogger does not implement Log

This makes our struts framework unavailable to the application.

After doing some research work we found a solution to this problem. Remove bundled commons-logging.jar from web application. I.e., remove commons-logging.jar from WEB-INF\lib folder of your web application.

I am not sure about the reason for this behavior. Seems like a bug to me. May be a bug in JBoss, Eclipse or JBoss Developer studio.

Restoring workspace selector dialog box in eclipse.

Posted by Albin Joseph | Posted in Eclipse | Posted on 31-12-2008

3

Restoring workspace selector dialog box in eclipse.

Have you ever selected ‘Use this as the default and do not ask again’ checkbox of workspace selector dialog box? If you happened to select that checkbox, next time onwards eclipse will not ask you for workspace selection again.

To bring back the workspace selector dialog box once again, go to Window -> Preferences -> General -> Start up and Shutdown and select the ‘Prompt for workspace on startup’ checkbox.

reset workspace selector dialog box

WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property

Posted by Albin Joseph | Posted in Tomcat | Posted on 29-11-2008

16

Today I was trying to deploy a web application to Tomcat server. Publishing went smoothly with no errors. So I thought everything will work fine. But when I tried to access the application, page was not coming. On further study of the log files I could see a warning message in Tomcat console. The error message was

WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:AppName' did not find a matching property.

The solution to this problem is very simple. Double click on your tomcat server. It will open the server configuration. Under server options check ‘Publish module contents to separate XML files’ checkbox. Restart your server. This time your page will come without any issues.

java.lang.NoSuchMethodError “main” with Eclipse

Posted by Albin Joseph | Posted in Eclipse | Posted on 15-07-2008

0

java.lang.NoSuchMethodError “main”. This was the exception one of colleague got when he tried to run a simple java application from within Eclipse. The java file that we were trying to execute had a main method and its syntax also matches with what Java wants.

For resolving this issue we tried to execute the file using different options like Run, Run As Java Application…. None of these methods helped us in resolving the issue. Then we thought its some problem with classpath and we couldn’t see anything wrong in our classpath settings.

Then we thought something wrong with our .metadata directory. We just closed our Eclipse and deleted the .metadata directory and started Eclipse again. Eclipse started with no projects. Since these projects were already in we just imported the projects using ‘Import existing project’ option of Eclipse. This time when we run the program, Eclipse was able to find the main method without any issues.

Yes there was something wrong in his .metadata directory and I still don’t know what it is.