Wednesday, June 30, 2010

How to prepopulate an email message with subject and body

Today I learned about how to populate an email message on client-side.

I think most people know about how to create an email link in html. It can be easily done by using
<a href="somebody@mail.com>Mail Somebody</a>
But what if you want to partially pre-populate the subject title and message body?

After googling for the answer, I found out that you can easily get the job done by using
<a href="mailto:somebody@mail.com?subject=Hello There&body=Line 1%0ALine 2%0ALine 3>Mail Somebody</a>

Since I'm calling the method from jsf tag, instead of using <a href>, I can use h:outputLink since h:outputLink produces html links. Also I've read people complaining about the html link not working if you put space in the subject or body. You can simply solve the issue by putting '%20' instead of space.

Click Mail to try out.

If you also want to know how to include cc and bcc recipients, here's a great page:
http://www.pageresource.com/html/mail2.htm

The complaint I have regarding this is that I cannot use other jsf tag to get the same performance. I would like to use a menu item (for consistency) instead of a link. I tried it in many different ways and it is just not feasible. Also, please note that you will need to have an email client(i.e Outlook Express etc. ) set up for this to work.

Monday, June 21, 2010

Android's Very Basic

So after learning some Android basics using Note Pad tutorial, I decided to write a simple program on my own. Note Pad was a great tutorial, but I always feel that the best way to master a programming language by trials and errors. So, I began to write a simple Hello World program (Yep, hello world again..) which greets according to the name users type in. So, if you type in Paras, it will display "Hello, Paras".

So, for my program, I need a button, a text field input and a text output. I've always been confused about layout for Android. I know that for each layout, you are supposed to write an xml file and put it under /layout folder in the project. The file strings.xml under /values folder hold all the key value pairs. So, for example, if I want to put a button that says "Say Hello", I put button in the .xml file under /layout folder. The button name will have to be specified in strings.xml. I know this is a very confusing way of doing GUI. However, thanks you a blog post I found using Google, I found DroidDraw(http://www.droiddraw.org/). It's beta version, but it is useful. You can generate layout xml codes using DroidDraw. However, you will still need to modify strings.xml file on your own.

If you have learned a little bit of Java Swing, you will find Android very similar to it. They used same concepts such as Action Events.

Instead of posting the whole code, I'll just state the important ones. When you launched your android application, you will have to do set up and this is done inside onCreate() method. onCreate() methods is from Activity package which has to be extended in every Android application. Each application can have one or more activities. For example, launching the application is one activity and pressing a button can be another activity but doesn't have to be.

Then you can set your layout by writing
setContentView(R.layout.main);

R.layout is the default for all application and main is the name of your layout file. In my case, my layout file is named main.xml.

Next thing is you want to say hello, when user click the button. So, like Swing, Android uses event listeners. We have button objects and event listeners are set to those button objects. We need to get a reference to our button object first. To do this, we say
button = (Button)findViewById(R.id.sayHelloButtonId);

The layout file, main.xml has a button tag and the tag will have an id reference. We're using that id to find our button object. So, the last steps is displaying hello,


button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sayHello();
}
});

Sunday, June 20, 2010

Android won't be able to catch up Apple OS

I downloaded the Note Pad tutorial that is provided on android website. I'm on tutorial #2 and it is about how to add and delete a note.

After my first helloWorld program and Note Pad 1 tutorial, I feel very frustrated about the way Android programming works. You need a bunch of xml files for positioning, creating activities and providing values on the objects.

So, at the end of the 2nd tutorial, I was running and testing the application. I realized that there's a piece of code that stateed about deletion of a note. I was very confused because I did not see Delete Note on my apps. I tried many different ways but the Delete button is no where to be found. And then, I tried to read the code carefully and noticed that Delete Note button is added when a Conext Menu is created. Honestly, I'm a bit confused about what a Context Menu is since I didn't read all the fundamentals line by line. Then I realized that I didn't try pressing too long on an existing note. And I tried it and the Delete note appears!

At the same time, I realized that that might be how the copy function works on android. When I got the phone first time, I was upset because I had to manually enter numbers to copy contacts. But that's how copy works too, you have to press on a text field for a long time for a context menu option to show up. Why can't they program in a simple and more straight forward way. Most users are not tech savvy and they will need to cater to those people. With the way that they are going, I don't think Android will be able to catch up with the popularity of IPhone OS anytime soon...

Sunday, June 13, 2010

My Experience With My First Android App

So, I've been wanting to join this mobile app business and finally started to learn to develop my first helloworld android apps. At this point, I'm not fully there yet because I ran into problems using android SDK. But I'm almost there..

As with most mobile app, you need an emulator to test your android app. I'm still a little big vague about this keystore thing that android apps require. But I'm sure I'll figure out once I try to release my app. For now, I'm good with using emulator.

Originally, I was trying to develop the app with Eclipse by installing ADT plugin. I successfully downloaded it. However, as the tutorial stated, if I go to Eclipse-> Preference, Android should be there. But it wasn't. I tried researching it and some suggested that I needed Aptana plug-in. I installed it and it still didn't work. Meanwhile, the new plug-in(Aptana) was messing with my Eclipse configuration. Since I needed Eclipse to be in the current state(i.e. I don't want to re-install and re-configure for my project), I decided to give up on the idea of using an IDE for development. So, I've been using command line tools for the first app.

Another problem that I ran into was trying to install my app onto the emulator. The tutorial said I needed to use adb command. But, when I first used it, it gave me no device found error. I had the emulator running and even when I typed in adb devices command, it's showing me empty device list. It's not showing no device so it is detecting but not connecting to my emulator. After some search and a few commands tries, I had to kill adb server and restart it and it worked.

I'll continue my tests and tries and I'm really excited to see my first android app on the emulator.

Saturday, June 12, 2010

Adding path variable in Mac OS

Every day is a learning experience for me. I learn from work. I learn from my activities. So, today I learned how to set a PATH variable in Mac.

I know how to set a PATH variable in windows. That was easy. I'm finding it hard to get a solution that will solve my problem. Because Mac is based on Unix and there're so many different version of Unix out there, the answers that I found are not applicable to me. However, thanks to tech_recipes.com, I was managed to change my path variable.

So, I have to use export command. The format is
export PATH=
and then I can add any path I want at the end of that. So for example, I can do like
export PATH=/user/bin
to set my path variable to /user/bin. This is only for one path. If I want multiple paths, then I have to separate it with a colon. Also, notice that you cannot have any space except between the key words export and PATH.

To see what is your system's current PATH variable, you can type env command. However, if there're existing PATH and if you type in export PATH=/user/bin, the original path will be overwritten. So, you will want to append the path at the end of the existing path. The way to do is that to use $PATH variable. For example, you can do
export PATH=$PATH:/user/bin
. That will add /user/bin to the path variable on top of the original paths.

Wednesday, June 9, 2010

Entity Manager Vs. Entity Manager Factory

For those who are confused between entityManager and entitymanager factory, here is a short and simple explanation. An entity manager is an instance inside a persistence context that manages entities. An entity manager factory is an interface that is used to obtain the application managed entity manager. An entity manager factory can create entity manager(s).

There are two types of entity managers : container managed entity managers and application managed entity managers. If you use container managed entity managers, you don't have to worry about a lot of things. The containers that you use(for example I use Seam) will take care of everything. The application managed entity manager is the other way round. There'll be certain situations in which you might want to control you entity manager instead of having a container take care of it.

Monday, June 7, 2010

Calling Seam managed entity manager from a servlet

I've been spending a majority of my time for the past week trying to figure out what seemed like an unsolvable problem. Again, as usual, this is related to the PDF applications.

So, we have the following process flow in our system :
1) Users print the application, which is partially filled with data collected from the system.
2) Then, users can fill in more information (as government applications ask for very minute details of information).
3) Then, users can click 'Save' button provided on the form so that those additional filled data are being stored as fdf file on our server.

Now, users want to download those data files within a given date range. My original work flow didn't involve any database interaction. But now, I have to store data regarding each fdf file so that those data can be used in the download process. However, it requires a database interaction and we use Seam managed persistence context for persisting data in the database.

When the 'Save' button is clicked, before a fdf file is created on the database, it has to create a row in the table so that we know which day fdf file is created and other information. I'm stuck at this step since I can't get the existing entity manager in our application scope from a custom servlet call inside a pdf file.

I've been trying and today I made slight progress. I managed to obtain an entitymanager object from a servlet call. However, I still need to figure out how to do additional processing by using that entitymanager. I'll post the code if I succeed to do what I need to do.

Saturday, June 5, 2010

Batch PDF processing

The weather has become uncontrollably hot in New York City. My AC in the room is not cool enough and I got a free portable AC. I'm not sure how people will go through this summer given the fact that we had an extremely cold winter and our body temperature has been so adjusted to the cold weather.

I am working on my project on a Saturday, and closing the tickets. Sometimes, I wish people to be less demanding or technology to be more advanced so that I don't need to solve problems like the following.

We have different applications in pdf format. We allow them to print those different pdfs in packages, that is they can select two different pdfs to be printed at once, and it will be returned as a single pdf file. Working with pdf applications is not easy. I won't be where I'm at with PDF processing without help from websites like planetPDF.com. Now, the problem is when they print out those PDFs, since not all PDFs come in the same format, when combined together, some landscaped-style PDFs are cut off. And they don't want that to happen.

Right now, I absolutely have no idea how to deal with this issue. For one, they can print out PDFs one by one, and those batch printing is just an option to better save time...