http://www.udev.info
Mail/Login: Password : forgot my password!
[UPDATE MODE]
Back

HTML Basics part 2 - Getting Uniface involved

Direct link http://www.udev.info/uniface/html-basics-part-2-getting-uniface-involved
Written by -GHAN- // Tags: html uniface browser

Calling Uniface is an easy one. Basically we just put the address of the server page into the browser and wait for a response. At this point I don't know how the server pages were meant to be (ab)used but when you are out there and do web development, your code is capable of doing more than ONE THING at the same time.

As you might know, we can activate component operations in order to reuse the given code. Actually this also works within the USP :)

Let's say we have the server page "myusp". Calling it in the browser makes us see some html (or whatever it should show). Now we append another operation called "hello_browser". Using a normal activate would make it look like:
SOURCE CODE
Sorry- ... please log-in or register to get this!

... right? But we don't activate while using a browser. So to get that operation to run, we amend the address of the server page to "myusp.hello_browser". Try to make an operation with the following code:
SOURCE CODE
Sorry- ... please log-in or register to get this!

Have a look at the SetState trigger. If there is a Webgen then remove.

Press [CTRL]+[F7] (... compile) and check for errors. If everything seems fine, call it in your browser.

First call the server page in the normal way. It should show the hmtl code from the painted screen. Then change the address to "myusp.hello_browser". If this works for you, then you took the first step into a better server page.

Familiar with HTML or not?!

At this point you will have to decide for yourself if this is an option for you or just CRAP! It demands you to have knowledge in building HTML code. Failing here should let you hit the brakes and say "ok, I gave it a try!". But if it feels not that tricky, then just head on- there is much more to explore.
ince you read this line, I assume you want more- fine ... let's go deeper then ;)

Putting it straight: Code should be/is capable of more than one function.

Compuware bound us to let a server page have only one display functionality. This is because you must draw the layout of the server page in the component editor and have no option of doing more than one layout. Paint it, compile it- finished. Unluckily this didn't feed my needs so I started to live without it.

In the previous part of this how-to, I introduced a method to do so. I didn't mention, why this will do, so I better get it done now.

How the USP works

The server page consists of three main things to do its job:
WEBGET, WEBGEN and $webinfo("output").
(Don't nail me for not mentioning header and input stuff as well as the other interesting buffers).
-WEBGET takes care of all parameters that comes in from the web (CGI - common gateway interface ... or just say web interface). Filling out fields in the browser puts the value back in your component fields. This voodoo is done by the webget statement in Uniface which also fires the triggers here and there. The idea of this is nice but doesn't work with more than one layout and neither will it fill out our own fields and containers.

-WEBGEN is the second part of this paint-and-be-happy construct. It takes the HTML from the painted fields and supplies it with the necessary Javascript code in order get this thing running. Fields are filled out and the complete code is put in the main buffer.

-$WEBINFO("output") is the (mentioned main) buffer that is transferred to the web. Everything in this buffer will reach the browser. It doesn't care about syntax, integrity or other stuff- it's just the output buffer.

So, what do we need to get going? Only the$Webinfo("Output"). The rest is obsolete! (... yes, forget about this! You won't need it) Doing so will save time and money :)

Instead of bugging around with the layout, just get used to store HTML layouts in external files or even the db (database). Then just load it, put it into $webinfo("output") and that's all. No layout will be disrupted, scratched or lost! Uniface will have no hands on that any longer.

Next let's have a look at the triggers. Uniface is definitely about triggers. We only want to look at the surface of that and skip all those triggers fired when using WEBGET (we don't want to use it, remember?).

The normal path through the server page looks like:
- GetState
- Execute
- SetState

The path is changed as we call an operation:
- GetState
- Operation
- SetState

Anything else is to be invoked by your code (e.g. retrieve -> read trigger). Please be aware of that no field triggers will be fired due to no WEBGET! This also impacts the format triggers and other stuff like that. But that's not as nasty as it sounds.

While working with data, we will need some entities for two reasons:
- To be able to compile (*doh*)
- To work with dynamic data in the entities

Let's declare an entity in the painting. Switch to the Source tab below and enter the following:
SOURCE CODE
Sorry- ... please log-in or register to get this!

Look at line 6- this is what we go for. Change the "myentity.model" to your desired entity and return to the component editor. Hit the refresh button in the bottom and suddenly your entity will appear. Make sure to modify its properties to ALL fields like in a service. This gives access to all possible fields and won't cause any headaches like "yak, I forgot to declare the field!".

Now you can work with the entity as you like. Be aware of that from now on, you are STATELESS- there is no hitlist any longer! No strings attached, no hidden catch- you are stateless! Retrieved data will be brought to you. If your retrieve profile results a 10.000 occs, then you get 10.000 occs!

Let's try it out! We will take your entity and let the contents of some fields pass through to your browser. Declare another operation in the previously started server page and let it look like:
SOURCE CODE
Sorry- ... please log-in or register to get this!

Finished with that? Fine! Hit [CTRL]+[F7] and RESTART your uRouter service! Since Uniface is a smart kind of software, its uServer buffers the loaded components from the last request (... that's why I call it the BUFFERHOG, hehe!) After having done that, reload the server page in your browser and try out the new operation.

A few words about the browser

The browser is your client in this game! It will get your html code and try to do the job for you. Be sure to do some well formed html code which applies to the standards! Doing so will let you forget about special code for browser x which won't work on browser y. Do it once and let it fit to the standard.

There are a bunch of fine browsers out there to aim at. Personally I group them into categories. Those may be "The good ones" and "the rest". Let me mention the group members for you.

The goods ones, who work fine and obey given standards, are:
-Mozilla (all sorts, all platforms)
-Webkit based (Safari, Chrome, Konqueror and again : all platforms)
-Opera

The rest at the moment just holds one name: Microsoft Internet Explorer!
- v5.x is scaring my pants off
- v6.x is creepy as hell (widgets are rendered in a strange way, fatally insecure)
- v7.x is at a level where you can say "ok ...!" (but still insecure)
- v8 will not be a 100% but do better than the previous ones

Hear my advice: Take your HANDS OF IE6 and below! They will tear you apart if your project gets complex! If you can avoid to use IE then do it! The alternatives are great but which browser you may choose is up to yourself!

Personally I use Mozilla Firefox 3.6 with the Firebug extension. To test my work with IE I use a virtual machine with the crappy IE6.

Finally I must mention that there are a lot of further browsers out there. These claim to be the fastest,
easiest and smartest because they can do "everything" and combine the features of the major browsers. Just skip those! They won't help you at all. Here comes some reason:
- Debugging is not, what they are best at! They will only let you surf!
- Companies won't use this! (They mostly use IE, then Firefox and perhaps Opera)
- Try to Google any errata concerning those browsers! There's not much to be found!

Conclusion

Congrats, you made it to the end of part 2! Try to fool around with the server page and see, how things behave with that!
We learned how a server page works and how to expand the capabilities of it (U7(!), U8, U9). Further we figured how to use entities and talked about browsers obeying standards while others don't give a damn ;)

comments appreciated :)

Comments

on 2010-05-04 14:24:47 -GHAN- wrote:

You are right- of course it has to be the userver process. But ending the userver after every request is not that good. You miss all the benefit of already buffered structures, which needs to be loaded every time. For testing, i prefer drop component from memory which works fine with serverpages as long you dont change its signature.

on 2010-05-04 08:55:56 RichardGill wrote:

For a buffered component, its not the urouter, but the loaded userver which is reused I guess. Try to put /maxidle=0s for the ust declaration in the urouter.asn : the userver will stop as soon as the USP made its job.

1047 view(s) / 2010-02-21 18:06:18 / LAST UPDATED: 2011-07-13 16:06:50