Mail/Login: Password : forgot my password!

GHANweb - Uniface web orientated service

Direct link
Written by -GHAN- // Tags: ghanweb ghanified workshop service foundation uniface usp cu2008 template

how data flows
how data flows

It seams, as if I blew the complete contrib here ... narf! ... Guess thats the price you pay while playing with some experimental contrib editor, as I did.
So... I will try to rebuild that one in the next days. And as promised in the latest news, there are important updates on the GHANweb service, which makes it faster, more flexible and efficient.
Until then, I simply will give you the parts of the component. In the bottom, you can download it, aswell as the Master Container.htm. This time, I will start it with an introduction.

What is GHANweb

GHANweb is a project in which I will try to open up on how to take Uniface to the web real fast and with max efficency. It is a normal Uniface service component but holds a lot of features used for the web. It wont destroy your normal web components or force you to skip DSPs (dynamic server pages). But it will help you to really make your USP (Uniface/Static server pages) amazingly dynamic. I presented the concept back in the days of CU2008 in Amsterdam, where I showed the effords of this development. Since then, many things in Uniface-Land have changed for me here. Server pages from now on don't have to look like 1990! They can have any shape and the limit is up to you (... or your design department)!
GHANweb will be your foundation in any of my future releases. And maybe it should be the foundation for yours aswell!


2011-09-19 : v0.2 - additional operations and features
2011-07-11 : v0.1 - initial release

What it is supposed to do

GHANweb takes care of several things. The most important is the templating. I've been using my template concent for the last ten years by now and it has evolved to a somewhat awesome thing (which of course is my personal opinion).
Templating is all about loading files, replacing (boiler)plates and put all of this together again. It's not rocket science, but more a set of techniques. I've made some operations which in a "normal" developement would reoccur in each serverpage:

- Operation template_load (load a template file by name X, mark it at will)
- Operation occ2web (convert (boiler)plates to replacement tags)
- Operation retemplate (replace those (boiler)plates / tags with the defined values)
- Operation rewebgen (make a complete HTML source, ready to be delivered to the web)

With v0.2 comes two more operations:
- Operation convert_date (convert a date to a formated string)
- Operation ulist2json (convert a Uniface list to a JSON-Stream)

I don't like to code things twice. If you someday then find a bug, then you will have to correct that on every damn code, where you inserted it! So, I reuse my code and with that service, all the server pages stay in a good shape!
The service can load the desired templates and connect parts with each other. Think of it as a set of tiles. All together make a complete picture. This is pretty fast!
These tiles (templates) are not defined within Uniface as we have detached them to a directory on your disk space.
I will run through the component with you.

What you dont need anymore

If you have been through my first contributions, then you know, that we strip the server page component to the bone! So many things, which are obsolete (look here). Delete every code from the GETSTATE and SETSTATE trigger! Don't use WEBGET and WEBGEN as we have GHANweb in control. Further you don't need to attach an real Entity the component. Just make it a dummy entity.


A fine place to define this is of course the ASN file. But for now, we place our global definitions in the define trigger of the service:
Sorry- ... please log-in or register to get this!

We simply define a root directory, in which we will deploy our external html templates, so the service knows where to find it. In my test setup, the TEMPLATE_DIR points to C:\temp\templates on the server machine.

With v0.2 there is more to set up here. I decided to place the name of the MASTER_CONTAINER in here. Found this to be reasonable as it's a pretty basic setting. Also a new define called MASTER_NAVIGATION. With that defined, GHANweb takes the HMTL ion the file and replaces the plate !NAV! with it! This make it pretty easy to define some navigation points. And finally a DEFAULT_DATE_FORMAT have been placed into the defines. The operation convert_date (available from v0.2) uses this as default if nothing else is given.

As you can see, the service and its setup is evolving.

Operation template_load

I've designed the component to have a bold use of entries, as they can be called more flexible that an "activate $instancename.x()". This makes the operation template_load and the entry en_template_load() a team. The operation calles the entry and returns its result. Along with this I've embedded an indicator param, which tells you, if it did work or we failed loading the template.
Operation template_load SOURCE CODE
Sorry- ... please log-in or register to get this!

The main code is as mentioned in the entry. Here we test for several things and mark the loaded template for information/debugging purpose. If your customer calls you and finds a "bug" in the web page, then you can easy tell him to pass-over the source of the page. And here the markings are your friend as they tell you, where to look.
entry en_template_load SOURCE CODE
Sorry- ... please log-in or register to get this!

But not enough with this! Back in the days, where the web evolved to get dynamic an you could tell the backend to load page X, the script-kiddies came up! They appended backslashes, dots and whatever into the params, hoping to malfunction your website or even take over control. We wont make our minds with that! Got better things to do and so we just cut out those values from the template name.

As you might have seen, with the V0.2 I've added another param so we can get a better overview in where we have to look for a template. While calling the operation, you just deliver the $componentname in the params. Then GHANweb knows where to look for the desired template file.

Operation occ2web

Look at this tiny source- so small a code but so much effect for the topic :) I really like that. So what it makes is pretty plain to see. We take every idpart of a list and put a "!" in front of and behind it. These are our placeholders/boilerplates in the html template.
operation occ2web SOURCE CODE
Sorry- ... please log-in or register to get this!

It is a horrible peace of work to turn a list to this over and over again! So I made this a companion as we do web with GHANweb. And as previously seen, the operation calls an entry
entry en_occ2web SOURCE CODE
Sorry- ... please log-in or register to get this!

Operation retemplate

The following code may seem pretty small, unimportant and not that overwhelming but the are the heart of the techniqe. The take all those (boiler)plates, which I from now on ONLY will mention as "plates", and replace them into the desired values. Not that difficult, but a lot of statements to be hand-written, I somebody needs to do so. I guess, there is not so much to be said about it.
operation retemplate SOURCE CODE
Sorry- ... please log-in or register to get this!

entry en_template_render SOURCE CODE
Sorry- ... please log-in or register to get this!

Operation ReWebgen

I decided to call it ReWebgen, as it does the same, as Uniface does with the webgen proc. We create a complete html source code out of the delivered lists. We have a master layout file (the MASTER_CONTAINER.HTM) and within that, we replace all Plates delivered in the params. Now this is not that much in my workshop template set. But in Community::ONE (my commercial back-end) there can be pretty much to do. How much this will be for your development is completely up to you. Take a look at the source:
operation rewebgen SOURCE CODE
Sorry- ... please log-in or register to get this!

Operation convert_date

In case you need to reformat a date field, then this operation is your buddy. You simply define an output format and it puts the date into shape. Further, as already mentioned, the defines hold a DEFAULT_DATE_FORMAT which is taken if you dont fill the param.
operation convert_date SOURCE CODE
Sorry- ... please log-in or register to get this!

As we need to put some of the date parts into a default size (two chars), it calls a little entry to get it done.
entry en_two_chars SOURCE CODE
Sorry- ... please log-in or register to get this!

An Example of a server page

After all those code blocks, here comes, how to use this. This is a fast and easy way on how to make a real effective web page. We simply tell,
- which html template we want to use,
- What plates we want to replace
- and finally put the result into plate !CONTENT! of the master container
Sorry- ... please log-in or register to get this!


Sorry- ... please log-in or register to get this!


3757 view(s) / 2011-07-11 14:25:29 / LAST UPDATED: 2012-04-25 11:54:06