It’s been a long time since I wrote my last post here. Okay, it’s 2010, start fresh. Lately, I’ve been concentrating with oneFace research in reeqSolution. Quite an enjoyable moment. Who has imagined that the simple script i wrote back then grows and become a full web framework and intensively used by reeqSolution. Then, lemme share the taste of oneFace. Currently, oneFace support both java and php.

Using persist for direct db manipulation:

$p = new Persist($DB_OBJ);
$p->setTable("tableName");
$p->set("column1",e("request_param1"),"datatype");
$p->set("column2",e("request_param2"),"datatype");
$p->insert();

“datatype” is either “s”,”i”,”d”,”b” (you should familiar with mysqli datatype);

“request_param” is usually the name of the input in form. this handles $GET, $_POST, $_SESSION and $_FILE (file handling will be discuss in next topic)

Persist provides lot of function. Some of inportant function :
getList(), get(), getPagedList(), referCode(), insert(), update(), delete(), getJoinList(), create(), execute(), loadShift() …etc, etc..

Usually in oneface, persist is coupled with ofaction class

typical ofaction for user CRUD

include "_set";
include PERSIST;
include DBCONFIG;
include ONEFACE;

$p1 = new Persist($DB_OBJ); // form-table mapping
$of = $req->getFace(); // oneFace propagator

$p1->setTable("tbl_user");
run($p1,$of); // entry point

// required for of-action class.
function populate(){
$p1->set("usr_id",e("txt_id"),"s");
$p1->set("usr_name",e("txt_name"),"s");
$p1->set("usr_nric",e("txt_nric"),"s");
$p1->set("usr_dob",e("txt_dob"),"s");
$p1->set("usr_pic",e("file_pic"),"b");
$p1->set("usr_address",e("txt_address"),"s");
$p1->set("usr_postcode",e("txt_postcode"),"s");
$p1->set("usr_city",e("txt_city"),"s");
$p1->set("usr_state",e("txt_state"),"s");
$p1->set("usr_email",e("txt_email"),"s");
$p1->set("usr_phone",e("txt_phone"),"s");
$p1->set("usr_date_added",e("txt_date_added"),"s");
}

// required : will be run if action parameter is "add"
function add($p1,$of){
$p1->insert();
$of->closeTab();
$of2 = addTab("user_view.php?id=".$p1->getAutoId());
$of2->focus();
}

// required : will be run if action parameter is "delete"
function delete($p1,$of){
$rv = $p1->delete();
if ($rv){
$of->closeTab();
}else{
$of->notify("Failed to delete data!");
}
}

// required : will be run if action parameter is "update"
function update($p1,$of){
$rv = $p1->update();
$of->notify($rv?"Data Successfully updated!":"Failed to delete data!");
}

// required : left empty for no validation. this method intercept further action.

function validation($p1, $of){
if (e("txt_name") == ''){
$of->message("txt_name","Name cannot be empty!");
}
// other validation
}

as you can see ofaction (OneFace Action Skeleton) provide a controller-like layer. ofaction provides oneface function and persist to deal with oneface front-end. Sometime oneface and persist coupled without being assist by ofaction class, or maybe i should say, can be embedded in front-end. For example, is dynamic datagrid.


$query = e("q");
$p1 = new Persist($DB_OBJ);
$p1->setTable("w_user");
$userlist = $p1->getList($query);
$of = $req->getFace();
$header = array("usr_name"=>"Name",
"usr_age"=>"Age",
"usr_phone"=>"Phone");
$of->setList($userlist, $header);
$of->populate();

There are numbers of oneface Face functions. Some of them are:

addTab(), closeTab(), go(), notify(), activate(), setMasterFaceInfo(), propagateUpdate(), litebox(), forceLogout(), forceRedirect(), addTrigger(), removeTrigger(), setTreeView(), updateTreeView(), pilot(), etc, etc...

So, we have persist dealing with back-end, ofaction become a controller and oneface Faces deals with front-end. From other view, this could be seen as MVC. The different is just, everything in oneface is ajax. You code addTab in server-side, but an optimized  javascript to add new tab and retrieved content via ajax will be sent. New feature as in v3.5 like notify(), forceLogout(), forceRedirect() is using ajax-push thingy (though I don’t really understand how, i know this action is triggered serverside, without the client have to initiate anything.

How to start using oneface?

you have to define oneface region in your page first. Normally I do this:

of_obj = {
"of_trigger" = "div_id",
"of_tabpane" = "div_id",
"of_view" = "div_id",
"of_treeview" = "div_id",
"of_strict_option" = false
}
oneface = new OneFace(of_obj);

Well, for most of oneface-ready template out there, you just have to change of_strict_option to true since most of the region is well defined. The example above is minimal oneface region target just to make it works.

Oneface covers mostly everything from access control, screen for reference code, reporting, admin page, templating, i18n with small blueprint. It’s crazily optimized for performance and speed without affecting the flexibility.