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

Uniface frontend templating part 2 - preparing the USP

Direct link http://www.udev.info/uniface/uniface-frontend-templating-part-2-preparing-the-usp
Written by -GHAN- // Tags: template uniface html entry plate layout loader

Welcome to part 2 of the Uniface frontend templating series. Although this part is a bit delayed, I hope it will help you to get along with Compuware's Uniface Server Pages and unleash the capabilities of this component.

Be sure to have checked to previous part Uniface frontend templating part 1.

In this part we will be a bit more practical and do put some code together. We start off with a layout, that will represent the result of our code. As this is only a container for our output, it consists of only a very few things which takes us to our first chapter.

1. HTML: making a layout file

This is how the master looks like
This is how the master looks like
Open your texteditor and start doing some HTML. I just did so and decided to have the following basic stuff in my server page:
- a message frame (using the plate !USP_MESSAGE!)
- a content part (using the plate !USP_CONTENT!)
- a title (using the plate !USP_TITLE!)

All this together could look like the following example:
The HTML Template SOURCE CODE
Sorry- ... please log-in or register to get this!

The message frame will let us inform the user about what happened or just to broadcast messages out of Uniface and into the browser.
The content part is, what will be changed all the time. You could compare it to a DSP CONTAINER and though it is filled by our USP instead of any other component. The content may vary as different things has to be shown.
Finally the title part is used to give our output some uniqe titles, which lets the user "feel" a difference in the page. Search engines like this very much btw. It's not a killer layout, but it will do ;)

Finished with that? Ok, then save it to a directory, where Uniface can "lfileload" it. As this is our master container with the layout, name it "master_template.htm".

The next thing to do is to make some smart functions to our upcoming Uniface Server Page. You can copy and paste those functions into a new component and complete the component bit after bit. We will head on with a template loader for our master container.

2. UNIFACE: building a template loader with Uniface

As we want to reuse this layout file again and again, we could use the fileload statement and load it permanently in every routine we create. But since we want to be a bit smarter than that, we do create a tiny code to do this for us on demand.
Uniface entry SOURCE CODE
Sorry- ... please log-in or register to get this!


3. UNIFACE: Adding plates to the content

We have already those three plates called !USP_MESSAGE!, !USP_CONTENT! and !USP_TITLE!. The content part will be dynamic as we choose to change it depending on what kind of request comes in. But also there, we need fields to be placed. So we will point out a little ruleset for plates:

1) Plates start with a "!" and end like this again. The formula for a plate is "!" + plate name + "!"
2) if we use multiple entities in an output, then we need to append the entity name to the plate which changes the formula to "!" + plate name + "." + entity name + "!"
3) Custom plates which not belong to the entities can be marked with a prefix like "NDB_" ("!" +"NDB_"+ plate name + "!")
4) and finally: plates are ALLWAYS assumed to be UPPERCASE

As we want to obey to the rules, we will make Uniface lists with commands like:

putitem/id vPlates,"!PLATENAME.ENTITY!","my value goes in here" or putlistitems/occ vPlates,"SALES"

The lazy bastard in me doesn't want to do this by hand all the time, when we use whole occurences. So here comes a tiny code that manages this for us:
String = en_occ2web(_plates,_suffix,_prefix)
Uniface entry SOURCE CODE
Sorry- ... please log-in or register to get this!

This definitly makes live a bit easier. Lets say we have an entity and the current occ needs to be available for display in the html page.
Uniface proc code SOURCE CODE
Sorry- ... please log-in or register to get this!
How easy can it be?
Now we have to put those rules alive and we will do so with another Uniface entry called
String = en_template_render(_plates,_template)
Uniface entry SOURCE CODE
Sorry- ... please log-in or register to get this!


3. Summary for now

We are reaching the end for this part of the Uniface frontend templating series. With these tools we can start to get the content up and running. I've prepared some lines to let you play with this ...
Uniface EXEC trigger SOURCE CODE
Sorry- ... please log-in or register to get this!

First we load our layout into a String that we name vhtml. Within that String you'll have one plate (!USP_CONTENT!) you easily can replace with any content. Please note, that we don't have to use WEBGEN or WEBGET anywhere!

Next part of the series will build on these functions and expand our Server Page. As we have summer and my next vacation is not that far away it could take some time as I don't expect to find to much internet access in the fjords of Norway :)

As usually the new contributions will be announced. If you run into trouble while testing this, just let me know by adding a comment here! I will reply to that and help you out.


/EDIT: Fixed some spelling and Code

Links:
- Uniface frontend templating part 3 - The Uniface Entity Lister

Comments

953 view(s) / 2010-06-27 12:44:20 / LAST UPDATED: 2011-07-13 16:11:00