Saturday, August 18, 2012

When Seam's bijection fails for < h:selectManyCheckbox >

For simple object reference, Seam's Injection saves you from having to type the getter and setter methods.   When a form input is selected, JSF goes through the process of conversion and validation.   If validation fails, the form input is not submitted and you get the conversion error.  Therefore, when you were injecting and outjecting an object of your design, you have to use if you are using as your option choices or you have to take care of the conversion in the code.  With the annotations like @Factory and @In @Out, Seam's binary injection has eased us from having to write extra steps of code.

However, this does not work with tag.  There is a couple of ways one could run into the problem with .  There were so many times I had trouble with validation errors for because the rendering of is different from those of other JSF tags.  And one other problem that I came across is Seam's injection does not work well for .

For example, you have a select many check box where you want the user to select at least one or more bank account.  So, you have an entity called Bank Account.  Technically, you should be able to do it easily via the following code:


In the Stateful Bean,

    @In(required=false, create=true)
    @Out(required=false)
    private List selectedAccount;


In JSF code,
        <h:selectManyCheckbox value="#{selectedAccount}"
                        layout="pageDirection">
            <s:selectItems value="#{bankAccountList}" var="b"
                            label="#{b.accountName}" />
            <s:convertEntity />
        </h:selectManyCheckbox>


If you do so, you will get the conversion error, JSF complaining that you can't convert an array of string to an array of your object, in this case is List.  Since is there, you would image that the conversion should automatically happen.  But this is not the case, as you do not know how exactly Seam implemented @In and @Out.  So, the work around is to use getter and setter method instead as below:

In the Stateful Bean,

    @In(required=false, create=true)
    @Out(required=false)
    private List selectedAccount;

    public List getSelectedPartners() {
        return selectedAccount;
    }

    public void setSelectedPartners(List selected) {
        selectedAccount = selected;
    }


In JSF code,
        <h:selectManyCheckbox value="#{nameOfYourBean.selectedAccount}"
                        layout="pageDirection">

            <s:selectItems value="#{bankAccountList}" var="b"
                            label="#{b.accountName}" />
            <s:convertEntity />
        </h:selectManyCheckbox>
   
Using the getter and setter method make sure that, a new array list of BankAccount objects are created every time the form is submitted.  So, it ensures that nothing unexpected happens.  From my experience with Seam, annotations are good, but hiding the complexity to ease the programmers exposes us to another layer of debugging the framework and making sure it works as intended.  In a lot of cases, getters and setters solve the problem that you have with @In and @Out.

Happy programming!.




           

Saturday, August 11, 2012

Arequipa, the white city

Arequipa, a city that is the second most populous, is very much different from Lima.  It immediately reminded me of those small cities out in the country-side.  The roads are narrow, and dusty.  Tallest buildings are of 3 or 4 stories.   One cannot see the appeal of Arequipa until one reaches the central location, Plaza De Amas.  

My friends told me that tPeruvian cities are set up in a way that, there is always a central plaza, which is the main plaza.  Then, a church and the resident/office of the mayor of the town will be situated right across from the plaza.  Peru, being a very religious Christian country, has several churches.  

It was a little bit before 9 A.M when the taxi driver dropped me of at the town center.    I am staying at Los Andes Bed and Breakfast, an establishment that is obscured from the street had one not notice the hostel's sign or pay attention to the address.   For $28 a night, the room is spacious and definitely better than the ones in Miraflores. Not to waste any time, I freshened up and left to get some food.   El Turko I was within 15 minutes walking distance from the hostel.  They served chicken kebab.  I didn't think food was superb, but it was relatively cheap.  After that, the first top is Monastery of Santa Catalina, as it was recommended as a must-see.

Everything in Arequipa is within walking distance.  And the volcano, El Misti, will sure to follow you whichever direction you are headed. Santa Catalina Monastery is famous for its vividly painted walls.  The monastery was highly popular in the 17th centuries   It was a very prestigious thing to become a nun at the monastery.   Originally, the nuns were asked for a certain amount of endowment in order to live there, however, this practice was forced to abolished by the Pope later on.  Currently, there are still about 30 nuns living the monastery, however, the rest of the monastery are open to the public.  During the tour(for 20 soles), the tour guide led us around the monastery, through different rooms and quarters, which displayed a variety of artifacts.  


 The next stop in Arequipa is Catholic University's Museum of Andean Sanctuaries (Museo Santuarios Andinos), which houses Mummy Juanita, a well-preserved frozen body of an Incan girl who was believed to be killed as a sacrifice to the mountain gods.   The museum also displays the belongings of Juanita, named after her discoverer, as well as the belongings of two other mummified bodies, a young girl and a young boy.   The museum is situated right across from the hostel and it was a small museum.   Like everywhere else in Peru, the tour guides led us through the big room with a projector where a documentary about Juanita was shown.

The documentary shown how Juanita traveled to Mount Ampato, where she was killed by a blunt trauma to the head.  It was sad to see how a young girl was offered as a sacrifice in such a disgusting manner.  And I can't stop wondering how or what she must have felt while embarking on such a journey.   Did she not have a choice?  Did she believe that she would be helping her people by offering herself as a sacrifice?  Seeing her frozen body, in an enclosed case under a dim light, I wonder what kind of curse she is under, to be still under public display and be widely discussed and researched even after her death.  I left the museum with a heavy heart, wondering IF the universe has really been created by this unknown supernatural entity and that everything is believed to happen for a reason, what does it really want the humanity to learn from all of this?  One cannot help, but wonder...right?

I have been wanting to try the famous Peruvian dishes, Cuy and Alpaca.  People told me that Lima has the best seafood and that I should wait to try other traditional dishes in the mountain side.  So, the first day in Arequipa, I decided to go to a restaurant that serves traditional Peru food.  The first choice was Zig Zag, but after reading the review where a tourist couple, coming out of Zig Zag, took a cab and got kidnapped and robbed of everything.  Even though it is true that this does not happen very often, it got me spooked and I decided to try on a different restaurant.  This restaurant has a menu with typical Peruvian food and I decided to try Alpaca.  It was a bad choice as the meat has a certain smell and has a texture that is not suited to my taste. 

 The next day, we decided to travel to Yanahuara province, which is about 30 minutes from where we were at.  Supposedly, there is a look out where the whole Arequipa can be seen.  It was a nice place to sit down and enjoy Arequipa and of course, a few more pictures..


Arequipa was a nice and quiet town.  Even though it has not so many things to do for tourists like I am(I'm not interested in seeing 5 churches), I still think that it is a nice town to visit.   It is definitely different from Lima, yet not as touristy and commercialized as our next stop, Cuzco.


Saturday, August 4, 2012

2 days in Lima - A foodie's paradise

When the flight landed in Lima, it was around 8pm.  The weather was very pleasant.  I can feel the cold breeze with a hint of freshness which I have been missing during all those time in New York.  There was a lot of taxi drivers with signs.  The hostel where I am staying arranged an airport pick up for 50 soles.  An old man named Agusto, was waiting there, holding a sign with my name.  

When I finally reached Hostel Porta, it was past 10pm.  It was about 30 minutes drive from the airport to the hostel.  The hostel has a curb appeal and a certain charm with its gated patio and orange colored wall.  

The next day, we walked to center of Miraflores along Avenida Jose Larco.  First businesses is to exchange money.  For $250, I got about 650 soles($1 = 2.62 soles).  And after that, I stopped at this cute cafe shop with lots of desert in the display.   Ordered a cup of Nescafe and churro.  Nescafe came in powder and warm milk.  It wasn't those ready-made 2-in-1 or 3-in-1 Nescafe.  It was different and very rich in flavor.  I wasn't really a fan of churro.  But those churro were the best I've ever had. 













After a fruitless effort with the sim cards, we walked to Punto Azul, a famous seafood restaurant as recommended by people in trip advisor.  Unfortunately it was closed.  Then we walked back to this vegetarian place that we ran across near Parque Kennedy. The food was delicious but the service was lukewarm at best. But their fruit juice was very fresh.  Then again, people do make fresh juice in Peru.  After that we took the cab to central Lima. Traffic in Lima was crazy. And people drive crazy too, especially the taxi drivers.  Took us about 30 mins to get to Plaza de Amas in historic center of Lima.


We walked around central Lima.  I came across this street side stand selling a drink.  It looked clean and I decided to try it.  The lady put a syrup from the bottle in the cup, some lime and ladled out herbal water from the pot.  It's a bit warm taste like a fruit juice and a little bit thick. She tried to tell me the name but I couldn't understand.  

Next stop we walked to Barrino China, Lima's Chinatown. The only thing that makes this area Chinatown is the usual arch you normally see in Chinatowns and a row of Chifa restaurants.  Chifa is a Peru version of chinese restaurant.   It sounded like chi-fan, which means eat in Chinese.  Here, I got to taste another famous Peruvian food, anticucho, a grilled cow's liver marinated with spicy sauce served over potatoes.  It was very good.
Later on Lia and Talia took us to Barranco area.  We tried the giant Peru corn, twice as big as any corn I've ever seen, and Moranda drink, which is made by boiling the purple maze and the pineapple.  It has a little bit of smell but it tasted good and very refreshing.  

It is time for check out the next day.  Since the bus ride was at 4pm, we had a half day to kill.  I left the luggages at the hotel and walked to La Comar shopping mall.  The location is great but the shopping experience is just so so. Then we walked down to the ocean side.  It was quite a steep down. And we came across this restaurant named Costa Verde.  It was very fancy restaurant situated right on the beach serving buffet.  And they gave us free Pisca sour! 

There was so much hype about Pisca sour, but I felt like it's just another drink with tequila and lime.   I would like to say that it tasted very similar to margarita but much stronger.   





Good thing about buffet is that you get to try all the traditional things at once.  Ceviche was good but there are a lot other Peruvian dishes which are more flavorful.  For instance I loved their Lomo Saltado, a fusion between Chinese and Peruvian, stir-fry beef with onions served on top of fires).  The dessert were also very good.  Flan was very thick and rich in flavor.  Their cheesecake was amazing too.  Peruvians know how to enjoy good food.   The bill came out $194 in total.  With the location and service like that I would say it was pretty decent.

After lunch, we headed back to our hotel. On the way back, we saw so many para-gliders.  It was fun to watch and definitely going to be on my to-do list.  

Cab drive from our hostel to Cruz del sur terminal was quick due to lack of traffic.   The cab driver was a bit antsy.  He wouldn't take a 20 soles bill that was torn in the corner.   (Fake bills are a big deal in Peru.  People won't accept any torn bills and there were so many fake bills and coins floating around.  Throughout the trip, we got a $20 fake bill and $5 coin.  So if you are planning to go down to Peru, it is something you should watch out).

Cruz del sur terminal was not big.  We had to retrieve tickets for the purchase voucher.  The terminal had 4 gates with a restaurant on site and bathrooms.  Bathrooms in Peru were weird.  This is the second place where we have seen that they took out the top lid of the toilet.  There was also no toilet tissue in the stall.  All the toilet tissues were outside.  

When on the bus, the bus attendant took a video record of every one.  It was funny and a weird security measure, but I guess it was reliable and safe as you have a recorded picture of everyone on the bus. . The bus was nice.  We got the cruzero suite for $48 each.  Those are the leather seats on the first floor of the double decker bus.  There are only 12 seats in this section. Each seat is reclinable and has foot rest.     It was a 15 hours bus ride to our next stop, Arequipa, the famous white city located in Southern Peru.