Friday, April 19, 2013

Sencha app upgrade from 2.0.1 to 2.1.1


Sencha has changed the way the application gets launched. 
In 2.0.1, the app.js is new an object:
new Ext.Application({
    launch: function() {
        new Ext.Panel({
            fullscreen: true,
            dockedItems: [{xtype:'toolbar', title:'My First App'}],
            layout: 'fit',
            styleHtmlContent: true,
            html: '<h2>Hello World!</h2>I did it!'
        });
    }
});

while in 2.1.1, it just calls a method
Ext.application({
        launch: function () {
            Ext.create('Ext.Panel', {
                fullscreen: true,
                html: 'Hello World!'
            });
        }
    });

If you take a Sencha 2.0.1 app and upgrade it to 2.1.1, then you will need to update the related code to make it work properly.

Tuesday, April 2, 2013

ASP.NET oData tutorial with Web API

Microsoft finally realizes it needs to provide some clean and simple functions to support developers, instead of leaving everything in developer's hands. To see a sample of this, just opening the IIS manager, the 40+ icons will make you feel you need to be a pilot in order to drive a car.
Web API is in the right direction to make things simple, and hope it can keep what it promised. The following are some steps for me to make the ASP.NET Web API oData tutorial work.
1. Install Visual Studio 2012 profiession.
2. Apply Visual Studio update 1
3. Apply Web Tool for Visual Studio 2012.2
4. Get Microsoft ASP.NET Web API OData NuGet package by console command (Why no a GUI tool, is console back in fashion?): "Install-Package Microsoft.AspNet.WebApi.OData"
5 In ProductsController.cs add using System.Web.Http.OData;
6. In WebApiConfig.cs, add using System.Web.Http.OData.Builder;
Now you should be able to build the project. From browser, navigate to the following link to show the sample data.
http://localhost:58478/oData/Products


Sunday, March 3, 2013

Add arbitrary data to ios uiWebView or any other object

Usually if you need to add arbitrary data to an ios object, you will use subclass and add the arbitrary data to the derived class.
However, for uiWebView, the document from Apple mentioned the class should not be subclass. There is a Tag property in UIView, but it can only store integer value, and can not be used to store NSDictionary or NSArray.
The rescue are objc_setAssociatedObject and objc_getAssociatedObject methods, which allow to associate any arbitrary data with another object, including uiWebView object. These methods may make the structure of your application difficult to understanding, but they are the only way to add arbitrary to an object if subclass is not available.

UIWebView thread issue

When using ios UIWebView control, few thread related issues need to be kept in mind to avoid errors.
1. executeJavaScriptWithReturnValueInternal can only be caused from main thread, and it will block the main thread
2. If the caller of executeJavaScriptWithReturnValueInternalis already in main thread, like the call is triggered by a button click, (ios ui event is handled in main thread), then it can be called directly. If the caller is in background thread, the method needs to be called by performSelectorOnMainThread to switch to main thread.
3. Although uiWebView is single threaded, it can send multiple async xmlhttpRequests, including the cachedResponseForRequest

Friday, February 1, 2013

Run existing tomcat installtion from eclipse and command line

1. When starting tomcat from eclipse, usually a separate tomcat instance configured by eclipse will start. If you want to run the existing tomcat instance with all web apps in it, you will need to double click on the tomcat item in server tab, and then select Server location to "Use Tomcat installation". Notice that the server path below will point to the existing tomcat you already installed before.
Start the tomcat from eclipse, you will see all you existing web app are there.

2. When run tomcat from mac from command line, you will need to update the file permission to make it work as below:

chmod 755 /Users/i826633/Documents/SMP/apache-tomcat-7.0.57/bin/*

./startup.sh
./shutdown.sh

3. the role name for tomcat user are case sensitive, so "administrator" is different from "Administrator"

Monday, November 26, 2012

Automatically map XmlhttpRequest post data to MVC action partameters

After converting a html Form to a xmlHttpRequest post request, the MVC action method can no longer get the mapped parameter value sent from client. The post data string is the exact between the two cases.

It turns out it is caused by not setting the Content-Type header in xmlhttprequest  object, and it is reasonable that server action method will not try to map the parameter value from post data, as with post request, the post data may be binary, json or any other formats.

So in order to fix the issue, the only required change is setting the content type explicitly for the request:

req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

And the server action method just stars to work again.

Monday, November 5, 2012

Install iso file on Windows 7 with WinRAR

The Virtual CD application provided by Microsoft no longer supports Windows 7, so it cannot by used to install iso file. If you do not want to burn the iso file into a real DVD, or using third party application to mount  the iso file to a virtual driver, you can just unzipped the iso file using WinRAR, which is a well known safe application to install on Windows 7.
After it is unzipped, just start the setup file (setup.exe), it should work as if it is installed from a DVD. Certainly, this will not work if you need to boot the box from the iso file.