CiphorBlog

Welcome to Ciphor

by on Apr.02, 2010, under buzz


We seek passion, we collect thoughts, we take practice. Who are we? We are programmers.
We are building a satellite that receives great thoughts and practical methodologies from productive and pragmatic minds.
Leave a Comment :, , , , , , , more...

ExtJS Tree Recursive Checking

by on Dec.20, 2010, under dev

For a tree widget with checkbox on each tree node, the expected behaviour while the node’s checked status changes is as follows:
a. The current node is checked or unchecked.
b. If the current node is to uncheck, its parent’s node is supposed to uncheck, too.
c. If the current node is to change the status, its all its children are supposed to follow the change recursively.
d. if all the children nodes are checked, their parent node is checked as well.
ExtJs
Except the default behavior (a), which all javascript framework can do, the other three expected behaviours have to be done all by ourselves at all time. In this post, I am going to provide the functions that can solve the problem with ExtJs TreePanel widget. The version of Extjs I am using is 3.3.

Of course, no bother to talk about the behavior (a), let’s start from (b). If we wanna recursively uncheck the parents, we may do so like:

/**
 * Function to uncheck parent nodes if any of the child nodes is unchecked.
 *
 * @param node
 *          the selected node.
 * @param checked
 *          the checkbox status.
 * @return
 */

function recusriveCheckingParents(node, checked) {
  if(checked == false) {
    var parent = node.parentNode;
    if(parent && parent.attributes.checked == true) {
	  parent.attributes.checked = checked;
	  parent.ui.checkbox.checked = checked;
	  recusriveCheckingParents(parent,checked);
    }
  }
}

For behavior (c), If the current node is to change the status, its all its children are supposed to follow the change recursively. do the following:

/**
 * Recursive function to check the child nodes when the parent is selected.
 *
 * @param node
 *          the selected node
 * @param checked
 *          the status of checkbox
 */
function recursiveCheckingChildren(node,checked) {
	node.expand();
  if(node.hasChildNodes()) {
    var allChecked = true;
    if(checked == false) {
      node.eachChild( function(child) {
        if(!child.attributes.checked) {
          allChecked = false;
        }
      });
    }
    if(allChecked) {
	  node.eachChild( function(child) {
        child.attributes.checked = checked;
        child.ui.checkbox.checked = checked;
        recursiveCheckingChildren(child,checked);
	  });
    }
  }
}

Again, the behavior (d), d. if all the children nodes are checked, their parent node is checked as well.

/**
 * Function to check the parent node if all the children are checked.
 *
 * @param node
 *          the selected node.
 * @param checked
 *          the checkbox status
 * @return
 */

function recursiveTestingSiblingChecking(node, checked) {
  if(checked == true ) {
    var parent = node.parentNode;
    var allSilblingChecked = true;
    if(parent) {
      parent.eachChild( function(child) {
        if(child.attributes.checked == false) {
          allSilblingChecked = false;
        }
      });
      if(allSilblingChecked) {
        parent.attributes.checked = true;
        parent.ui.checkbox.checked = true;
        recursiveTestingSiblingChecking(parent,checked);
      }
    }
  }
}

All the three functions work well in most circumstances with the ExtJs tree widget. you can call them in the listener config option with “checkchange” event:

...
listeners: {
        'checkchange': function(node, checked) {
          recursiveTestingSiblingChecking(node, checked);
          recursiveCheckingChildren(node,checked);
          recusriveCheckingParents(node, checked);
          self.isValid();
        },

        'afterrender': function(tree) {
          tree.getRootNode().expand();
        }
      }
...

Now, go and run your page to see the magic.

1 Comment :, , , , , , , , more...

Tweak Java Home in Mac for Oracle Habits

by on Aug.03, 2010, under dev

Some guys like me faced some odd issue when they are installing jDeveloper in Mac box, it is that the Oracle guys doesnot recognize the Apple java home : /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/. It’s weird and become Invalid Java Home bla bla.

Well, the good news is you may find some explanation in its release note which is telling people who are mac users that a simple tweak can resolve the issue.

cd /SystemLibrary/Frameworks/JavaVM.framework/Versions/1.6.0/Home/
su root
mkdir jre
cd jre
mkdir lib
cd lib
ln -s ../../../Classes/classes.jar rt.jar

Who can tell me why oracle is always doing a bit ‘evil’ to developers, ha?

1 Comment :, , more...

Subclipse with Eclipse Helios on Snow Leopard

by on Jul.28, 2010, under dev

Newly installed eclipse 3.6 (helios) popped up a error that says “unable to load default SVN client”. In the svn preference panel: Team>SVN, there is a select option for default svn client, the selected option is  JavaHL.

eclipse preference panel for svn

eclipse preference panel for svn

I checked my svn version with :

$ svn --version

it is

svn, version 1.6.5 (r38866)
compiled Oct 16 2009, 02:54:10

thus it was not on account of the wrong version since the subclipse did require of subverion 1.6. So, where is my JavaHL? Having checked it out througt javahl faq wiki: http://subclipse.tigris.org/wiki/JavaHL, I thought I should reinstall subversion binary dmg again from openCollabNet.

Well, it works after installing was done. it installed all the stuffs under /opt/subversion now. Perhaps you may want to replace the /usr/bin/svn to the current location.

5 Comments :, , , , , , , , more...

Resolve Error Installing MySql Gem in Snow Leopard

by on Jun.25, 2010, under dev

Ruby on Rails surely brings nice experience and excitement to programmers. The agile process we are engaged in while developing keep indulges us. The whole procedure should have been smooth all along, yet error occurred using mysql gem with rake db:migrate command.  What was going on? and Let’s fix it now.

After issue the common command:

sudo gem install mysql

and then

rake db:migrate

The abnormal error uninitialized constant MysqlCompat::MysqlRes poped up in the following command line with plenty of lines of information.

My developing environment is comprised of Ruby 1.8.7, rails 2.3.8, mysql gem 2.8.1, Snow Leopard 64. and finally the following command fixed the problem.

sudo gem uninstall mysql

sudo env ARCHFLAGS="-arch x86_64" gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config

let’s test it again with rake db:migrate, at this moment, here comes the right result.

6 Comments more...

BLOB Image Storage with Spring Hibernate and Struts2

by on Jun.11, 2010, under dev

In Today’s post I wanna talk about storage of images in database with BLOB(Binary Large Object) data type. Though I am still considering the performance issues on BLOB images, yet I am going to share the steps I followed to implement the process. You still have no idea what the BLOB is? it’s all right.

What is BLOB?

A blob (alternately known as a binary large object, basic large object, BLOB, or BLOb) is a collection of binary data stored as a single entity in a database management system. Blobs are typically images, audio or other multimedia objects, though sometimes binary executable code is stored as a blob. Database support for blobs is not universal. —- From Wikipedia.
We often store unstructured data into a LOB field in database, and LOB is normally known as BLOB(Binary) and CLOB(Character).
The LOB datatypes BLOB, CLOB, NCLOB, and BFILE enable you to store large blocks of unstructured data (such as text, graphic images, video clips, and sound waveforms) up to 4 gigabytes in size. They provide efficient, random, piece-wise access to the data. Oracle Corporation recommends that you always use LOB datatypes over LONG datatypes.—- Oracle Docs. (continue reading…)

6 Comments :, , , , , , , , more...

How to Build Dynamic Tree with ExtJS

by on Jun.10, 2010, under dev

Background

In my previous post I mentioned how to build a dynamic tree with DWR and Dojo for a web application. Today I am writing this article to introduce the solution about building a dynamic tree with ExtJS component and our familiar frameworks like Hibernate, Spring and Struts2. In most web applications we always see the demand for the tree-based category management or display, for some kind of reason like product catalogue, department structure or so. Well let’s see what we can do by our toys here. (continue reading…)

12 Comments :, , , , , , , , , , , more...

OpenSessionInView with DWR

by on Apr.06, 2010, under dev

In my one previous post, I provided the solution on how to enable lazy-fetch in hibernate by annotation with Spring OpenSessionInView Filter. However some readers gave me the feedback that they encountered the problem using lazy with dwr on the basis of the solution above, which causes exception during the request of DWR ajax request. In other words, the DWR does not trigger the filter to deal with it in the very long term session. A simple patch to this exception according to my  un-fully-tested experiments, a *.dwr url-pattern should be mapped in the filter configuration in the web.xml.

     <filter>
          <filter-name>hibernateFilter</filter-name>
                  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
          <init-param>
              <param-name> </param>singleSession</param-name>
              <param-value> </param>true</param-value>
          </init-param>
    </filter>
    <filter-mapping>
          <filter-name>hibernateFilter</filter-name>
          <url-pattern>*.html</url-pattern>
      </filter-mapping>
      <filter-mapping>
          <filter-name>hibernateFilter</filter-name>
          <url-pattern>*.dwr</url-pattern>
     </filter-mapping>
2 Comments :, , , , , , , , , more...

Howto – Enable Lazy Fetch using Hibernate with Spring | 延迟加载

by on Apr.02, 2010, under dev

You may easily see the convenience developing java web project with hibernate using lazy-fetch while mapping other tables in the current model object. half the time, in some kind of listing view, it’s unnecessary to fetch and map all related objects, single for each row or even referenced collection of objects. Thus LAZY feature helps us a lot dealing with the normal performance demand.
There are two ways configuring the Hibernate ORMapping, xml based and annotation driven. Since Java 5 afterward, annotation over xml configuration is widely used in project developing context. So the code below occurs all over the corners in over mapped model objects using hibernate:

@ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)

take the code below for example:

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
        @JoinColumn(name="COMPLEX_ID",  insertable = true, updatable = true)
	public FsComplex getFsComplex() {
		return fsComplex;
	}

	public void setFsComplex(FsComplex fsComplex) {
		this.fsComplex = fsComplex;
	}

To make the LAZY magic happen, you need to add a OpenSessionInView filter into the web.xml

    <filter>
          <filter-name>hibernateFilter</filter-name>
                  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
          <init-param>
              <param-name>singleSession</param-name>
              <param-value>true</param-value>
          </init-param>
    </filter>
    <filter-mapping>
          <filter-name>hibernateFilter</filter-name>
          <url-pattern>*.html</url-pattern>
      </filter-mapping>

*.html indicates that I am using struts2 and use html as my page extension.

It seem easy and all things are done for readonly transactions. However when you do a saving action, you will face an exception that says :

Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition.

In the service layer of your project, another annotation solves the problem:

@Transactional(readOnly= false

which should be added to the non-read-only transactional method.
Stop here, now, you can have lazy fetch feature as well as saving without exceptions.

In addition to the solution above, according to the spring official document here, you can also

turn this filter into deferred close mode, by specifying “singleSession”=”false”: It will not use a single session per request then, but rather let each data access operation or transaction use its own session (like without Open Session in View). Each of those sessions will be registered for deferred close, though, actually processed at request completion.

A single session per request allows for most efficient first-level caching, but can cause side effects, for example on saveOrUpdate or when continuing after a rolled-back transaction. The deferred close strategy is as safe as no Open Session in View in that respect, while still allowing for lazy loading in views (but not providing a first-level cache for the entire request).

3 Comments :, , , , , , more...

Howto – Resolve the loop of Microsoft Office Setup Assistant

by on Mar.26, 2009, under buzz

out of the reason that my daily job needs exchange mailing, my first thing to do to make my whole new MacBook pro fit the situation is to find and install the office for mac, thus, I choose the Office 2008 for mac. In my Chinese environment, I encountered the problem that it says it cannot find software to install, which has been resolved by changing the language to English the same as the installation package. Having accomplished the installation procedure, the final step, setup assistant, informed me to get updated to the latest version, during which I was informed of 1210 and 1215 updates. Then I myself downloaded the seperated independent installation pack of above two updates. After the two updates was installed, microsoft office setup assistant shows over and over again while every launch of office applicatins,such as word, excel, powerpoint, etc.  It was really irritating.

After google it, it is invalid key that causes the issue while installing the office. To resolve the problem, move the following files to the Trash:

/Users/username/Library/Preferences/Microsoft/Office 2008/Microsoft Office 2008 settings.plist

/Applications/Microsoft Office 2008/Office/OfficePID.plist

After you complete these steps, open any Office application, and then use the product key that is included with your original installation disk to complete the installation. The product key is located on the back of the Office 2008 for Mac DVD sleeve or on the back of the Install Guide.

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...