JavaServer Page

December 6, 2006

In addition to information about the platform, the

Filed under: OpenCms 6 — webmaster @ 1:37 pm

In addition to information about the platform, the info tag provides a wealth of information about paths and URIs and can be very useful for constructing links when the OpenCms link tag will not do. The img Tag The img tag is new in OpenCms 6.2. It provides the functionality of the HTML img tag, plus automatic path adjustment for the VFS (like the OpenCms link tag) and server-side image scaling. The image scaling feature can be very useful. You can reference full-sized images in the VFS and use the img tag to generate thumbnails. The code for the OpenCms img tag looks the same as the HTML img tag: The value of the src attribute is the image’s location in the VFS. OpenCms automatically re-writes this into the appropriate URL. The height and width attributes specify the dimensions of the image. OpenCms uses this information to scale the image. In the example above, the original image is 200 180. OpenCms will scale the image down to 130 120 before sending it to the client’s web browser. If the dimensions do not maintain the same aspect ratio as the original image, then the background of the image will be padded the image will not be stretched. That means you don’t have to worry about distorting the image when scaling it. The attributes of the regular HTML img tag, like alt, style, and border, are also supported by the OpenCms img tag. Here’s a piece of code that contains both the OpenCms img tag and the regular HTML img tag: Funny Head When this code is run, the output looks like this:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost mac Web Hosting services

When the above jsp is requested by the

Filed under: OpenCms 6 — webmaster @ 7:29 am

The property attribute determines which user information will be returned instead of the user tag. The available properties are name, group (or currentgroup), defaultgroup, firstname, lastname, email, street, zip, city, description, and otherstuff. The otherstuff attribute is not particularly useful. It is actually an unformatted dump of the contents of the java.util.Hashtable that stores extra user information. The info Tag The next tag in the OpenCms tag library that we will cover is the info tag, which returns information about OpenCms, the java VM, and the underlying operating system. Syntactically, it is almost identical to the user tag. Here is an example that prints out the vital information about the platform:

System Info:

The requested URL is

Currently, you are running OpenCms with the version on , ().

When this jsp is run, the client will see something like this:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost inexpensive Web Hosting services

When the above jsp is requested by the

Filed under: OpenCms 6 — webmaster @ 7:29 am

When the above jsp is requested by the client, it will produce a page that looks like this: We have seen how to create a jsp page and assign a jsp template to the page. Now, we will continue on and look at some other features of the OpenCms jsp tag library. The property Tag The jsp tag library provides some handy tools for providing information about resources within OpenCms. For instance, it is often useful to be able to get information about a particular file. The OpenCms tag library’s property tag gives us access to any of the properties associated with the file. For example, we can access the template property that we just set. To do this, we can simply add the following line above the final include in the jsp we created above:

This file uses the template

The property element will be replaced with the value of the template property in this case, the absolute path in the VFS to the template: /system/modules/ tv.alephnull.modules.templates/templates/example_template. In fact, we are not strictly limited to the file at hand. Here’s how we could grab the Title property from the index.html file in the same folder:

The index.html file has the title

In short, you can use the property tag to get the values of properties for files in the VFS.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost inexpensive Web Hosting services

When the above jsp is requested by the

Filed under: OpenCms 6 — webmaster @ 7:29 am

The link Tag Since we are referring to the index.html file anyway, we might as well provide a link to it. Linking within OpenCms could be very confusing. To write a link, you would have to know where the resource is in the VFS, whether the resource is served statically or dynamically, how tomcat is configured, etc. Fortunately, you won’t have to worry about these things. The OpenCms tag library provides a tag that handles this for you the link tag. The link tag is simple. It has no attributes and contains only the path to the file it will expand. For example: index.html This line of code generates the full path of the index.html file. The above example works because the index.html file is in the same directory as our jsp. But if the file is in a different location in the VFS, then you will need to use the full VFS path, like /sites/default/playground/index.html. For an example of this, take another look at the jsp template we created at the beginning of this chapter. To create a link to another file in OpenCms, you will need to create a hyperlink that looks something like this:

Go to

When the server processes these directives, it will send the client a piece of HTML that looks like this:

Go to My Playground

The URL in the href attribute now has an absolute path to the index.html file, and the OpenCms property tag has been replaced with the full title of the file. The user Tag Another useful tag in the OpenCms tag library is the user tag. We looked at this tag briefly before, but now we will examine it in a little more detail. The user tag provides access to information about the current user.

User Info

The current user is .

The current group is .

The name property will be replaced by the full name of the user, while the group property will be replaced by the user’s current group.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost inexpensive Web Hosting services

understand any of the XML-style jsp tags. It

Filed under: OpenCms 6 — webmaster @ 12:26 am

When we created the jsp template, we looked at the properties for a jsp page. While the Title property is useful (and will be used by the template), everything else can remain as the default specifies. But we are not ready to click Finish. We will need to use the Advanced button to edit one additional property for the jsp file. We will need to set the template that the jsp will use. Near the bottom of the Individual Properties list in the Advanced Properties page, there is a field labeled template. We need to set this to point to our new template: /system/ modules/tv.alephnull.modules.templates/templates/example_template. You can also access the Advanced Properties page for a file by clicking on the file’s icon in the explorer view, choosing Properties, and clicking the Advanced button in the lower-right corner. Click Finish to save the new file, and then open the file for editing. We want to create a very simple jsp page that uses our template. We will start by creating the basic framework for the page: < %@ page session="false" %> < %@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

This is a jsp page.

The page begins with the typical jsp declarations in which we import the cms taglib. We have already assigned a template to this document, and we have broken the template into three sections. Now, we can selectively access the elements in that template. The OpenCms include tags import the head and foot elements from the template. When this page is processed, these tags will be replaced by the contents of the head and foot elements. Since we are not accessing the body of a particular Page file, there is no need to import the body element from the template. Instead, I just added a paragraph of text:

This is a jsp page.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost mac Web Hosting services

understand any of the XML-style jsp tags. It

Filed under: OpenCms 6 — webmaster @ 12:26 am

As you can see, there are three template sections called head, body, and foot. Each of these sections can be called by name from an OpenCms include tag. When processing page files, OpenCms reads through the template file in order, applying each template as it is encountered. (This means that, if you defined the foot before defining head, the foot would be printed before the head.) None of the sections is added by default to a document of any other type besides Page. In a moment, we will look at the process of creating a jsp document that uses a template. In the process, we will see how this breaking up of the template can come in useful. Finally, there is no hard and fast rule about template sections. While it is a good idea to call them head, body, and foot and some other OpenCms applications might assume their existence, you can add others if you wish. For instance, I could define a template element called hello that contained a short message.

Hello!

While it would show up by default in any pages, it would be accessible to other jsp files with a separate include. This mechanism allows you to conditionally apply template elements in jsp pages that are automatically applied to page documents. Using Templates from a jsp Document Just as we can create page documents in the OpenCms file system, we can also create jsp documents in the file system. jsp documents can be useful for handling forms or displaying dynamic information. But using templates with jsp pages is different from using templates with page files. Now that our jsp template is complete, we can create a jsp document that uses it. We will create a jsp document called /playground/cms-info.jsp. Click the New button to create a new file, and choose jsp from the list of types. There is only one default parameter to set for a jsp file, Name, and we will set this to cms-info.jsp.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost mac Web Hosting services

understand any of the XML-style jsp tags. It

Filed under: OpenCms 6 — webmaster @ 12:26 am

understand any of the XML-style jsp tags. It ignores any tag that it cannot interpret. Consequently, XML-style tags that need path translation will be ignored. I will try to point out particular instances of this as we go through examples, and I will show examples of XML syntax when appropriate. But, if you choose to use the XML-style jsp syntax, be wary of tags that reference file-system paths. The remainder of this book will use only the old syntax. The OpenCms Tag Library The OpenCms tag library is a built-in component of OpenCms. It provides access to the data managed by OpenCms and provides basic functions for presenting OpenCms data in a template. To begin this examination of the OpenCms tag library, we will return to the jsp template that we created earlier in this chapter. Breaking a jsp Template into Sections The first OpenCms jsp tag that we will examine is the template tag. Our original template simply printed the title, generated a rudimentary navigation menu, and included the body of the requested page. This worked fine for our examples, but we can make the template much more versatile with a few extensions. Doing this can make it useful for other jsp pages, as well as for advanced pages. We want to break the template into pieces that can be identified and selectively used. In our first example, there was no way to address a particular part of the template. jsp pages that use a template need to be able to identify where the top (head) of the template should go and where the bottom (foot) should go. Here is our previous example partitioned into a header, body, and footer. < %@ page session="false" %> < %@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %> < !DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">

Menu

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost mac Web Hosting services

December 5, 2006

CmsjspActionElement cms = new CmsjspActionElement( pageContext, request, response

Filed under: OpenCms 6 — webmaster @ 5:24 pm

Next, we will explore the OpenCms tag library in more detail. Along the way, we will revisit some of the tags that we have used already, and we will discuss some new tags. More on jsp Tags We have looked at the basics of jsp and Scriptlets and even created a basic template using jsp tags. We will now look at jsp tags in more detail and at how they can be used within HTML documents. jsp Directives The jsp tag libraries use HTML-like (or XML-like) element syntax for including dynamic functionality in a document. Core jsp tags, or directives, are characterized by the percent sign, %. For example, the jsp page directive from the jsp template earlier in this chapter looked like this: < %@ page session="false" %> Core tags are used to provide information to the server about how the page is to be processed. So far, we’ve looked at the page directive, which provides the server with information on how to treat the page, and the taglib directive, which tells the server what jsp tag libraries will be used in the page. A jsp expression is a java statement that is converted to a string and automatically printed. jsp expressions also have a percent sign. The following jsp expression, for example, prints out the date and time:

Right now, it is < %= new java.util.Date() %>

New XML Syntax for Core jsp Tags Recent developments in jsp technology, especially in version 1.2, encourage moving from the original jsp percent-style tag format to an XML-compliant syntax. Core tags have been redefined to use XML namespaces, using the jsp prefix instead of the percent-style notation. The new XML syntax is not completely supported by OpenCms. While you can sometimes get away with using it, you might want to consider a potential drawback. In the Chapter 4, I pointed out that the FlexCache mechanism stores jsp pages in the real file system, as well as the VFS, so that those pages can be executed by the servlet engine. When these files are moved from the VFS to the local file system, OpenCms must replace VFS path information with absolute file-system paths. To accomplish this, OpenCms scans the jsp files, trying to replace paths in tags that need replacement. However, this scanning mechanism does not understand all of the jsp tags in particular, it does not

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost inexpensive Web Hosting services

CmsjspActionElement cms = new CmsjspActionElement( pageContext, request, response

Filed under: OpenCms 6 — webmaster @ 5:24 pm

< %@ page session="false" %> < %@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %> < !DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">

Menu

The div element is just used to set the navigation off from the rest of the text. In fact, the only functional change above is the addition of the OpenCms include tag that points to the elements/navigation.jsp file. If we view our test file again, it should have a navigation menu that looks something like this: Our simple template has now grown a bit.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost inexpensive Web Hosting services

CmsjspActionElement cms = new CmsjspActionElement( pageContext, request, response

Filed under: OpenCms 6 — webmaster @ 5:23 pm

CmsjspActionElement cms = new CmsjspActionElement( pageContext, request, response ); Once this object has been created, we need to get the navigation information from it. This is done in the next three lines: CmsjspNavBuilder navigation = cms.getNavigation(); List navItems = navigation.getNavigationForFolder(); Iterator i = navItems.iterator(); The first line gets a CmsjspNavBuilder object, which has all of the necessary information about navigation. We use the getNavigationForFolder method to get a list of all of the items in the current folder and store it in a variable called navItems. Once we have the list, we need an Iterator object that will allow us to walk through the list in order. Now we are ready to go through the list, one item at a time, and print out the navigation links: while( i.hasNext() ) { CmsjspNavElement navElement = ( CmsjspNavElement )i.next(); String link = cms.link( navElement.getResourceName() ); String title = navElement.getTitle(); out.println(”»” + title + “
“); } While there are more items, this code will: 1. Get the navigation element, which stores information about a particular file (line 2). 2. Create a link for that file (line 3). 3. Get the title of that file (line 4). 4. Print out a hyperlink that points to that file (line 5). Don’t get too distracted by all of the quotes and backslashes in the println method. The backslashes help java understand which quotes need to get written to the HTML output. That’s all there is to it. All we need to do now is add it to the template. The OpenCms documentation that comes bundled with OpenCms includes more documentation on working with the navigation objects. If you are interested in improving on this simple navigation script, you can start by looking there. Including the Scriptlet in the Template Now that we have a navigation scriptlet stored in the elements directory, how can use it in the template? A simple addition to our template will add navigation. Here is the template file, with the new addition highlighted:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost inexpensive Web Hosting services

« Previous PageNext Page »

Powered by Java Web Hosting