Categories
Software development

JSF Richfaces best practice: drop down and data scroller

Reading Time: < 1 minute

drop down box
Clear a list for selectionOneMenu every time, got burned by this in a “page number” drop down for Richfaces data scroller. And some other places.

Use validator
keep in mind it will overwrite the required = “true”, if the user does not select a valid value from drop down, it will give error message during Save method.

Assign 0 to “–select–” ?
Yes or no. Add 0 means 0 is a selectable option, so if one wants to enforce user to select something using required=”true”, it will pass this check. Thus comes in the validator, in which one can say “0” is not valid.

Page number for data scroller
1) t:saveState if we can not have session scope for dataBean;
2) the drop down tip above;
3) When “adding or deleting rows” and it cause the total number of pages changes, make sure set the correct page number in the “action” (save) methods.

Categories
Software development

Oracle, Java etc.

Reading Time: 2 minutes

The following was written more than a year ago…

======
Got opportunity to work on those two technologies recently due to job change. Had some gotchas as I transform from C++, CAD programming to this new program paradigm.

Data problem vs. coding error
In CAD world, sometimes there is problem with the data (CAD file) itself. But most of the time I focus my effort debugging the coding error in my own code, not trying to debugging the data itself. In Oracle/Database world, I found it more often that the data itself could complicate problem. Because the relational database has relationship between table, sometimes we can not add/delete/update table at will due to dependencies (data integrity). This also bring about the second topic I want to discuss.

C++ vs. Java
Java is not as flexible as C++. For instance, how to pass data back from a function, so far I found one way: using the return data. In C++, I used the pointer and reference quite a bit. The wiring of inheritance and interface (implementation) could also got a bit complicated: basically one needs to draw the relationships on a paper to better understand all those.

Eclipse vs. Visual Studio
Eclipse (the free Java IDE) is quite powerful, actually. It’s also highly configurable, with so many plug-ins, e.g., this subclipse integrates Eclipse with Subversion. I remember I could not do such things inside Visual Studio (for Perforce).

Categories
iPhone app

Steve Jobs

Reading Time: < 1 minute

Stanford commencement speech (2005)

Macintosh 1984 commercial

Steve Jobs and Bill Gates in 1983 Apple event

My other post on Steve Jobs.

Walt Mossberg on Steve Jobs.

Categories
Software development

Dirty flag java script, dynamic drop down

Reading Time: < 1 minute

Dirty flag on a HTML form is much trickier than I thought, that is, it is tricker when I started to programming for dirty flag.

Saw this javascript snippet. It works great except in my case, I was generating dynamic drop down (selection menu), and in a lot of cases it behaves as opposite to expected (i.e., it shows the form is dirty when it is not, and vice versa). Found out there are couple things came into play.

1) The default selection (type “0”), or select “nothing”, I forgot to set the value “0” (string type).

2) Second, I forgot to clear some of the derivative selections when I make selection the primary selection menu (basically it will dynamically generate other drop downs based on the primary selection).

3) Third, allow type “0” has other effect, I had to remove required=”true” validation from the selection menu, and validate it manually. Also, after I made this optional (removed required=”true”), the actionListener will get triggered when I make selection type “0”, previously it was not entering it, and caused other rendering issues.

4) Last but not least, I added a “validator” to the primary selection menu (basically it will give error if I select “0” type), and it will not trigger the actionListener again. Madness. So basically I have to do the validation somewhere else.

Categories
iPhone app

Did Apple change iTunes App store ranking algorithm lately?

Reading Time: < 1 minute

It looks like it. Obviously my observation could be quite limited. But here is the background, in the good old days, Apple ranks app mostly by the download number in a given amount of time, and the ratings/reviews. So basically the popular the app, the higher the rank. This process could reinforce itself. Apple realized this approach probably has its limitation, one example being a fairly popular app Facebook (by usage) is not ranked the 1st. So Apple changed its algorithm a bit, it not only ranks by the download number, it also monitors the usage. By “usage” I assume Apple measures mostly by network activity, my reasoning being if an app just does its thing locally, Apple has no way to know it.

Also keep in mind the rating and reviews also play a role in the ranking, my understanding is if all things equal, higher rating or favorable reviews will push the rank higher.

More recently, it seems Apple started to give usage more weight. This is just from my own observation, I have 2 little apps, both are standalone (no network features), and one does fairly well last few month, until recent, it totally went down cliff. I did not know why until I did keyword search, in the past, it ranked 2 or 3, not it fell out of top 25. I tried to rescue such as free download for a limited time. After the free period, download number drops back, and this thing fell out top 25 again 🙁

I think from product lifecycle management (PLM) point of view, this app thing is not as good as traditional software revenue model 🙂

Categories
iPhone app

Create a timer on 2nd thread using Grand Central Dispatch GCD

Reading Time: 2 minutes

(Update 06-24-11) Last night I found “More iPhone 3 development” (by Dave mark and Jeff Lamarche) chapter 14 deveoted full chapter to multithread including timer.

(Original) As of iOS 4, Apple made blocks and Grand Central Dispatch (GCD) available. Previously it was available on Mac.

Some pre-requisite or recommend readings
WWDC 2010 video session 206: Introduction to Blocks and Grand Central Dispatch GCD (you need to be a registered Apple developer to download this).

Or if you read the nice intro “guide to blocks and grand central dispatch by Cocoa Samurai (Colin Wheeler).

The problem I attempt to solve
I have couple buttons waiting for the user to touch, and the buttons can not wait there forever, they wait for 2 seconds if a user does not touch any of them, and a new set of button will display at that time.

I thought about this problem for a while, thought about using NSNotifications which is essentially a callback mechanism (see “love to be notified” by Cocoanetics for more info). I need more, essentially I need a second thread which is a timer, to notify the main thread (which does display and handles touch) when 2 seconds is up.

I found fieryrobot’s Watchdog timer in GCD which meets my basic need for timer. But I need to return from timer to the main thread. Quote Fieryrobot:

…If you needed to return results to your main thread, you can just use dispatch_async to execute the code on the main queue (dispatch_get_main_queue() as we’ve seen in previous posts…

I am sure there is ways using blocks (callbacks) to do that, but I don’t know on top of my head. So I used Notification instead. Here is what I did in ViewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(twoSecondsNotification:)
name:@"TwoSecondsReached"
object:nil];

In the timer, I post notification when it’s time to go back to main queue (thread).
// Hey, let's actually do something when the timer fires!
dispatch_source_set_event_handler(_timer, ^{

NSLog(@"WATCHDOG: task took longer than %f seconds",
timeout);
// ensure we never fire again
dispatch_source_cancel(_timer);

// pass control back to main queue
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"TwoSecondsReached" object:nil userInfo:nil];
});

last but not least, the “TwoSecondsReached” function
- (void)twoSecondsNotification:(NSNotification *) notification
{
// clean up the timer here
if(timer != nil)
{
[timer invalidate];
[timer release];
}

// do things you want to do here.
}

One more thing
In my code, I initialize timer and release timer in different methods, and I found it’s easy to lose tack of timers and have multiple timers. One phenomena I saw is multiple timers fire at the same time, and make the app go crazy. I am thinking use a singleton pattern for the timer at this time.

Categories
Business iPhone app

Going east: China iOS app dev companies and potential market

Reading Time: 3 minutes

(Update 05-10-2014) I saw the IPO of China based Cheetah Mobile in the news, not too impressed or confident of their apps though, although I know they make money. Cheetah was a subsidiary of Kingsoft (and King still has a big stake after IPO). I also noticed the WSJ article about China app market. I know a lot has changed since I last wrote about this, which is 3 years ago. From my personal observations, smartphone especially iPhone is saturated.

(Original 05-29-2011) I prepared the following summary for 360 iDev conference this fall at Denver. The talk did not make into the agenda, but I think it may be interesting to some western iOS (mobile) developers. After all, the market has great potentials.

Some background
iPhone officially came to China late 2009, but iPhone 1G came to China shortly after the US launch in Summer 2007. The first Apple store opened in Beijing July 2008. According to Steve Jobs Sept 2010 music event and Apple Q4 2010 earning report, greater China is the fastest growing market. Chinese costumers are snapping up iPod, iPhone, iPad and Macs quickly. How about apps? In this talk, we will discuss the China iOS app development companies (some have their apps featured by Apple), the current status of China iOS apps and the potential of iOS app markets (both consumer and enterprises).

Xujiahui

Some notable China based iOS development companies
139.me (Its Colorful Aquarium app was featured by Apple).
Rye Studio (featured article on San Jose Mercury News here).

Categories
iPhone app

A few iOS gotchas: NSDate copy, sleep and multitask

Reading Time: 2 minutes

I was working on a new app and this app has something to do with timing. Basically I need to record the time between a button being displayed and the time a user touches the button (note they are in two different functions).

NSDate and memory leak
To accomplish this, I am using NSDate class, I declared NSDate * start in the class,
and then in one function, I was doing
start = [NSDate date];

and in the second function, I was doing
NSDate *methodFinish = [NSDate date];
NSTimeInterval intervalTime = [methodFinish timeIntervalSinceDate:start];

But the code above crashes immediately. After some research I believe this has something to do with memory, if we copy (retain) the NSDate as suggested by this thread in iphonedevsdk.com. It worked.

NSDate* now = [NSDate date]; // unretained
start = [now copy]; // retained

Sleep

Categories
iPhone app

Distribute Ad Hoc Application over the air OTA: some tips

Reading Time: < 1 minute

(Update 08-29-2014) As of iOS 7, this functionality needs some tweak. See this thread on stack overflow and this post. The gist of the change is Apple disabled http, it needs https now.

(Original 05-14-2011) I was following John Muchow’s tutorial “Distribute Ad Hoc Applications over the air OTA“. It worked as expected until the last step, when I click the link on my iPad 1, it says “can not download the app…”.

Did google on this, found one relevant discussion on stackoverflow. I was using my web hosting company web interface uploading the file, so I switched to ftp, changed to binary mode. Same results.

I realized my iPad 1 was still at iOS 4.2.1, while my Xcode was building 4.3 target. So I changed the target to 4.2 (in Xcode => Project Setting => build target), and repeated relevant steps in the tutorial (mainly to create the .ipa and .plist). Things worked after I made the change.

Btw, I found Xcode 3.2.6 build-in capability to share and distribute (submit to app store) is cool.
Xcode build and archive

Categories
iPhone app

Apple iTunes Connect Financial Report

Reading Time: 2 minutes

If you are iOS developer who has sold app (or ads, in-app purchase) on iTunes App store, the iTunes connect Financial Report is no stranger to you. Personally I published my 1st paid app to the App store last Sept, and I have since received financial report email notifications, and direct deposit. I did not pay much attention to the dates because the earnings are small amounts. I do understand Apple does things in its own fiscal calendar (developer can get it after log into iTunes Connect).

That is until recently, I found an interesting phenomena or glitch if you well. It took me a while to figure out the answer. Basically as of today I have not received the financial report for April, while I received the March earnings report on March 31. So I went to the “Payments and Financial Reports” section after log in iTunes Connect, and click the “Owed” tab, I noticed I received February Financial Report on March 18, and January report on Feb 18. See the patten here? Apple says it usually releases report 30 days after the month closes. Quote Apple (I got this answer from “Contact US”, then select appropriate topic:)

When/how will I receive financial reports?
Financial reports are distributed once a month and are available for download exclusively through the Payments and Financial Reports module of iTunes Connect. Financial reports are generally available for a given month by the end of the following month.

So this confirms my theory: Apple releases March report earlier than usual, which leads me to think it would release April report shortly after month closes. The usual time frame is around May 18.

Related question: when will I get paid?
Apple is quite consistent on this, it appears to me they do direct deposit 15 days after issuing financial report. This of course assumes:
1) A developer has set up the bank and tax information, agree with the contract (aka paper work);
2) Meets Apple’s threshold of $150 (it appears to me this rule is not strictly enforced).

Bonus question: why Apple release March report earlier?
hint: think about its fiscal calendar again 🙂