Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Right Click on the ejb package and create a new Remote interface CountryCapital as shown in the figure





  2. Enter the fields as shown in the figure and select Finish.





  3. Add the following code as shown below
    Code Block
    titleCountryCapital.java
    borderStylesolid
    package ejb;
    
    import javax.ejb.Remote;
    @Remote
    public interface CountryCapital {
    	public String capitalName(String countryName);
    }
    
    Here @Remote is an annotation used to declare the interface as a Remote Interface.
  4. Similarly create a Local interface CountryCapitalLocal. Add the following code to the interface
    Code Block
    titleCountryCapitalLocal.java
    borderStylesolid
    package ejb;
    
    import javax.ejb.Local;
    @Local
    public interface CountryCapitalLocal {
    	public String capitalName(String countryName);
    
    }
    

...

In remote as well as local interface we have the declaration for only one Business method. So only this method will be visible to the application client. Methods other than capitalName if implemented in the Bean class will be private to Bean class and will not be visible to application client.

  1. Next step is to create a Bean Class which will implement the Business method to be executed. Right Click on the jsf package and create a new class.


    Image Added


  2. Enter the class name as CountryCapitalBean.


    Image Added


  3. Populate the bean class with the code as follows
    Code Block
    titleCountryCapitalBean.java
    borderStylesolid
    
    package ejb;
    
    import javax.ejb.Stateless;
    @Stateless
    public class CountryCapitalBean implements CountryCapital,CountryCapitalLocal{
    	public String capitalName(String countryName)
    	{
    		String capital=new String("No such country");
    		if (countryName.equalsIgnoreCase("India"))
    		{
    			capital="New Delhi";
    		}
    		if (countryName.equalsIgnoreCase("United States Of America")) 
    		{
    			capital="Washington DC";
    		}
    		if (countryName.equalsIgnoreCase("China")) 
    		{
    			capital="Bejing";
    		} 
    		
    		return capital;
    		
    	}
    
    }