Oct 12

A better and updated version is maintained here (http://grprakash.googlepages.com/gwtwithejb).
In this post, I thought I’ll explain how to use GWT with EJB. GWT addresses the web layer and EJB the middle layer, its natural to use both of them to have a neat J2ee app.

I assume that you know how to create EJB project and Web project with Googlipse. For the second one, I’ve written a post here.

If you are an advanced EJB developer and have used GWT for a while, “Use the RemoteServiceImpl as a EJB client and continue in the as usual way”. If you are not, then the rest of the post is for you.

What we are trying now is to have a text box in the web page and a button. When you key in a person’s name there and press the button, it will show the age of the person.

The first step is to create a Stateless Session Bean. The Remote & Home interface will look like this:

public interface AgeServiceEjb
extends EJBObject, Remote {

public int getAge(String name);
}

public interface AgeServiceHome
extends EJBHome {
public AgeService create()
throws …;
}

The EJB looks something like:

public class AgeServiceBean
implements SessionBean {

//All EJB members here
public int getAge(String name){

int age;

if(name.equals(”Pranni”))
age = 18; //Pranni is always 18 :-) else if(name.equals(”Bill Gates”))
age = 51;
else
age = 40; // default value

return age;
}
}

I opted for a very simple implementation. Of course you have do the normal way of contacting the Data Layer. Use Entity beans or try plain JDBC or use Hibernate. Check whether name is null or not, throw a NameNotFound exception. Its the plain old normal EJB code. GWT never restricts anything here. If you already have some EJB, exposing it to a servlet or a swing client, very well, you can reuse that also.

Now let us create a Remote service in the Web layer.

The GWT’s RemoteService is very similar to the RemoteInterface of EJB:

public interface AgeServiceGwt
extends RemoteService {

public int getAge(String name);

// Other members Util, SERVICE_URI etc
}

The RemoteService’s Impl is the key which connects GWT and EJB:

public interface AgeServiceGwtImpl
extends RemoteServiceServlet
implements AgeServiceGwt{

public int getAge(String name){
Context ctx = new InitialContext();
AgeServiceHome hme =
(AgeServiceHome)ctx.lookup(”<JNDI name>”);
AgeServiceEjb ageService = hme.create();
return ageService.getAge(name);
}
}

You can do all the normal EJB client stuff here. Add parameters to create initial context, configure the JNDI name, cache the home interface, etc. If you have ever used JSP/servlets calling EJB code, think it in the same way. Treat the Impl class as a servlet (in fact it is!) and do the usual way.

Common problems:

  • How do I deploy the EJB in the GWT’s embedded Tomcat server?


You can’t. In fact you can’t deploy it even on an external Tomcat. Its just a web container. You need an app server like WebLogic or JBoss

  • How do I create a EAR file?


Create an EAR project and add these projects (EJB & Web) to it. Select File->Export->Export as EAR file

  • Can I deploy the application in an app server and still debug in hosted mode?


Yes. Look at “Deploying to an external server” in the GWT tutorial. Its the same way.

written by Prakash G.R.

Oct 12

ஒரு மாசமா டைபாய்டுன்னு சாக்கு சொல்லி, வீட்டுல நல்லா தின்னுட்டு, தூங்கிட்டு இங்க வந்தா ஒரே கடி. இங்க தனியா வேற இருக்கேனா, சண்ட போட கூட ஆளே இல்லாம, நானே சமைச்சு, அத நானே சாப்பிட்டு, ஹூம். என்ன தான் திட்டும், அடியும் வாங்கினாலும், அம்மணி நெனப்பு வுட்டு போக மாட்டேங்குது. இந்த மாதிரி பிரிவில தான் நல்லா கவித வருமாமே. செரி ட்ரை பண்ணிப்பார்போமேன்னு ஒரு வெண்பா எழுதினேன்.

கவித, கவித எங்க படி:

தரையில் ஒருமீனாய் என்னைத் திணறவிட்ட(து)
எங்கள் இருவர் பிரிவு

written by Prakash G.R.

Oct 11

இங்க இருக்கற வரிகள் எல்லாம் நான் எங்க இருந்து சுட்டேன்னு கண்டுபிடிங்க பார்க்கலாம்:

 

கோபம் கொள்ளும் நேரம்
வானம் எல்லாம் மேகம்
காணாமலே போகும் ஒரே நிலா

கோபம் தீரும் நேரம்
மேகம் இல்லா வானம்
பெளர்னமியாய் தோன்றும் அதே நிலா


உலகத்தின் கடைசியாய்
இன்று தானோ என்பது போல்
பேசி பேசி தீர்த்த பின்னும்
எதோ ஒன்று குறையுதே.


உப்புக்கடலோடு மேகம் உற்பத்தியானாலும்
உப்புத்தண்ணீரை மேகம் ஒரு போதும் சிந்தாது
மலையில் விழுந்தாலும் சூரியன் மரித்து போவதில்லை
நிலவுக்கு ஒளியூட்டி தன்னை நீட்டித்துக்கொள்கிறதே,
மேகமாய் நானும் மாறேனோ
அதன் மேண்மை குணங்கள் காண்பேனோ
சூரியன் போலவே மாறேனோ
என் ஜோதியில் உலகை ஆளேனோ


காற்றில் இலைகள் பறந்த பிறகும்
கிளையின் தழும்புகள் மறைவதில்லை
காயம் நூறு கண்ட பிறகும்
உன்னை உள்மணம் மறப்பதில்லை

 

கருப்பு-வெள்ளை காலத்துல “அத்தை மடி மெத்தையடி ஆடி விளையாடம்மா”-ன்னு அழகான வரிகளோட வ்ந்துகிட்டிருந்த தமிழ் சினிமா பாடல்கள் எங்கயோ போயி “எப்படி? எப்படி? நீ சமைஞ்சது எப்படி?”-ன்னு கேக்கற மாதிரி பாடல்களோட வர ஆரம்பிச்சிருச்சு. “இப்ப இருக்கற ஆளுகளே செரியில்லப்பா, எங்க காலத்துல எல்லாம்”-ன்னு ஆரம்பிக்கற பெரிசுகளுக்கு ஒரு இன்பர்மேசன்: மேல சொன்ன ரெண்டு பாடல்களையும் எழுதினது ஒரே ஆள் தான். அப்ப பார்க்கறவங்க தரம் கொறஞ்சு போச்சோ? நமீதாவோ இல்ல மும்தாஜோ வந்து ஒரு ஆட்டம் போட்டாதான் படம் ஓடுமோ? அப்படியும் இல்ல. தவமாய் தவமிருந்து கூட ஓடுதே. இந்த தமிழ் மக்களோட ரசனைய புரிஞ்சுக்கவே முடியலபா. என்னமோ போங்க.

ஸ்டேட்பாங்கில அக்கவுண்ட் இல்ல
டாஸ்மாக்கில கடன் வெச்சவன்

இந்த மாதிரி அட்டகாசமான பாட்டுகளுக்கு நடுவே நல்ல சில வரிகளும் எப்படியோ வந்துடுது. அப்படி நான் பார்த்த சில வரிகளத்தான் சுட்டு மேல குடுத்தேன். எந்தெந்த பாட்டுன்னு கேக்கறீங்களா?

    1. கண்ட நாள் முதலாய் - மேற்கே மேற்கே தான்
    2. வேட்டையாடு விளையாடு - மஞ்சள் வெய்யில் மாலை
    3. சாமுராய் - மூங்கில் காடுகளே
    4. 7ஜி ரெயின்போ காலனி - கண் பேசும் வார்த்தைகள்

முக்கியமா அந்த டாஸ்மாக் வரிகள் சொல்லாம விட்டுட்டானேன்னு திட்டுறவங்களுக்கு - ஆறு படத்தில “சோடா பாட்டில் கையில” பாட்டு 

written by Prakash G.R.

Oct 11

photos_025.jpg

This photo was taken during the valaikaapu (any translations in English?) function. Photo taken by my friend with his digi-cam. Usually I publish the photos taken by me only, but this one is an exception :-)

written by Prakash G.R.

Oct 11

I can eat idly with curd or chappathi with rasam or even the so-called “Butter Paneer Masala” prepared by my wife. But I can’t eat the typical Bangalore Sambar.

Grrrrrrrrrrr

written by Prakash G.R.

Oct 10

The earlier UI of Google Reader was not usable at all. Now this version is little better. Still there could be more improvements:

 

  • The subscribed blogs are shown in the left pane in the tree view. It would be really nice if items could be drag-n-dropable
  • The Manage Subscriptions page is another mess. By default it shows all the subscribed feeds. No one is going to pay attention if more than 20 items are listed. And I’ve around 100 feeds! Scrolling also becomes slower with more items
  • I thought there should be some way to search for tags I want to manage. The search button was hiding in right corner. When you have all the items displayed, it better be in a better visible place
  • When you click “Add Star”, there is a visual indication on the star and the text becomes “Remove Star”. Same for “Share” and “Add Tags”. But when I clicked “Mark as read” nothing happened. The text didn’t change and there was no visual clue. It took me some time to realize that there was a visual clue. The box right before the text is a check box and there is a tick box. First the box itself very small and the tick happens to be in the same dull gray color. The UI should be consistent - it would be better if the text changes to “Mark as unread” and the tick mark appears in a brighter color as in other things
  • When you add a feed thru Firefox, first it asks for whether to add it to Google Personalized home page or to Reader. It asks for everytime. There could be a preference for “add to this by default” or similar
  • The feeds added from Firefox always gets added to the root. There should be a way to put it under a folder while adding.
  • The Feed Settings Menu has just one item - UnSubscribe. May be they have plans to add more items, but for undelete, how about a Thrash Can symbol under the tree and items and the items drag-n-dropped into it will get deleted?
  • The sharing is little weird. Instead of some number based URL, they should do a think of something else. BTW, try this URL: http://www.google.com/reader/shared/00123456789012344567
  • I was doing some thing and suddenly the left panel disappeared. I didn’t know how to bring it back. No button to restore. I closed the tab and opened reader in a new tab and discovered that I’ve accidentally pressed ’u', which happens to be the shortcut for Full screen view. I’m a great lover of keyboard shortcuts, but there should be a way to use the mouse and switch between the normal and Full Screen views.

written by Prakash G.R.

Oct 09

For those who were wondering why I didn’t post anything for a month or didn’t reply you mails, I was down with typhoid. I called up my PM and conveyed the message and went back to my native village - the great “cyber palayam”. Almost every family in my village, including mine, has a member affected by chi-kun guinea fever. I thought I’m going to get affected by it in my one month’s stay there. Luck was on my side. I escaped. So what was I doing for one whole month? Nothing! With no cellphone signal or internet, I just spent all day lazing around. Can’t watch TV as for every fifteen minutes, there will be a 5 min power down. The worst thing is that during that 15 mins, mostly will be ads and the main program will be during the time where no power. It was tough for a guy like me to sit simply and do nothing. So the best I can do is gardening. Whenever I go to Pollachi for a check-up, I’d buy some plants. Finally now my home has all sort of plants from Rose to Jasmin and from Pomegranate to Papaya. Not sure how it will be maintained in my absense.

Its election time and I read every line in the Dina Malar. Pretty much interesting to see the statements by our “great” leaders. Esp Captain, Thirumavalavan and Karunanithi. Add our Election Commision to that list.

When I came back to Bangalore this morning, I’d thousands of mails, both personal and official. Sorting out and reading them is really a challenge. Still doing it. Got to read the blogs and newssites to see what has happened in this one month. Few things I noticed:

  • The all new Google Reader. Finally they got a decent UI. Will post about it later.
  • The new iPod Shuffle. I didn’t like this model.
  • My previous post is topping up in the results for the search GWT tutorials :-)

written by Prakash G.R.