Thursday, March 31, 2011

Autocompletion of JSF/CDI Managed Beans in JBoss Tools

Jboss-tools-managedbean-cdi

Current JBoss Tools 3.2 (Eclipse IDE plugin for developing Java EE web applications) is not yet able to show JSF 2.0 managed beans annotated with @ManagedBean.

For example, the code below will load just fine with JSF 2.0, but JBoss Tools will "ignore" it:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="refillManager")
@SessionScoped
public class RefillManager {

When you type the following in the Facelets XHTML template editor, you will not get a code assist hint for refillManager bean :

<h:dataTable value="#{refillManager.refills}">

However there is an alternative, which is actually a better one anyway. (hint: why use JSF-only Managed Beans when you have CDI beans that you can use everywhere?)

Use CDI's @Named annotation :

import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@SuppressWarnings("serial")
@Named("refillCdi")
@SessionScoped
public class RefillCdi implements Serializable {

Now this CDI bean will be detected by JBoss Tools and will show up in autocompletion popup.

To activate CDI (Java Context and Dependency Injection) in a Java EE 6 web application, create an empty file named WEB-INF/beans.xml and you're done. :-) JBoss Tools also has excellent support for CDI.

Thursday, March 3, 2011

JBoss AS default Administrator username & password

As of JBoss Application Server 6.0.0.Final, the default administrator password is :

Username: admin
Password: admin

You can access JBoss AS admin console from:

Define the Datasources (persistence databases) with JNDI Names in: Servers > JBoss AS 6 (default) > Resources > Datasources > Local Tx Datasources.

How to Set Context Path of Java EE/Web Application in JBoss App Server

If your web application is packaged as a WAR file then you can create jboss-web.xml under WEB-INF folder of WAR file and specify the context-root in jboss-web.xml like this :

<jboss-web>   <context-root>MyWebAppContext</context-root> </jboss-web>

If your application is packaged as an EAR file then you can specify context-root in META-INF/application.xml of EAR like this

<module>     <web>       <web-uri>MyWAR.war</web-uri>       <context-root>MyWebAppContext</context-root>     </web>   </module>
Source: http://stackoverflow.com/questions/2046604/context-path-in-jboss