free web page hit counter
Tuesday Dec 13, 2005

Creator Tip: Using CSS Layout Technique

Some Creator customers have asked if the page-fragments can be placed such a way that a single page can be subdivided in to 4 parts:

  • The first part is the top of the page where the user puts the application name and application's logo.
  • The second part comes after the top part and uses 20% of the screen width in the left side. In this part, user would like to put a tree view component representing the menu of the application.
  • The third part is the place where user wants to launch the page (customer form for example). This part is resides besides the second part and uses 80% of the screen width.
  • The final part is the place below the 2nd and 3rd part where user puts the page footer.

The best approach is to provide a Layout Component to lay out the components added to it, may be using a <table> element. In the absence of such a component, let us see how this can be done. Here is a hint on how to achieve this using CSS Layout Technique.

Let us use three page-fragments for header, footer and side navigation bar. For the middle let us use a LayoutPanel with Grid-Layout so that user can set the components in absolute layout mode. Now do the following

Page Fragment1

  • Set the width 100%
  • Set the height as 10% or 100px

Page Fragment2

  • Set the width 20% or 150px
  • Set the height as 500px or 100%

Page Fragment3

  • Set the width 100%
  • Set the height as 10% or 100px

Note: Percentage works fine in Firefox but fails in IE6. So better to use pixels than percentage at least for Page Fragment height, to support correctly in IE. The height and width can be set using the property sheet of each page fragment.

The components can be added to the page fragments in the usual manner. I've added StaticText with some text that displays location of the page-fragment and the Layout Panel.

Add the following to the resources/stylesheet.css

.top{ 
  background-color: #ccccff; 
  bottom: auto; 
  height: 10%; 
  left: 0; 
  position: fixed; 
  right: 0; 
  top: 0; 
  width: 100% 
} 
.left{ 
  background-color: #ffffcc; 
  color: #000000; 
  height: 80%; 
  left: 0;  
  position: fixed; 
  top: 10%; 
  width: 20%; 
  overflow : auto 
} 
.bottom { 
  background-color: #ccffcc; 
  bottom: 0; 
  height: 10%; 
  position: fixed; 
  right: 0; 
  top: auto; 
  width: 100% 
}

Now add the three page-fragments to a page. When each page-fragment is added  an enclosing <div> is added for each page-fragment in the page. This is visible in the outline. Select the <div> in the out line and unset the style property on each of the <div> (Note: This is import other wise settings in the style property takes precedence. Now set the styleClass of each page-fragment as top for header , left for navigation, bottom for footer.

Add a LayoutPanel to the page. Set its style property as

background-color: #abaaed; position: absolute; width: 80%; height: 80%; left: 20%; top: 10% 

If you deploy the application you should see something like in the picture below. Try resizing the page in the browser and see the results. If percentage is used, the resizing of the page fragments will be much more fluid (works well in Firefox). 

PS: I've tested this only with Firefox and IE 6. Firefox is more accurate in positioning the page-fragments  using %. IE has some overlap and shrinks to fit the page fragment content . Experiment with pixels (ex. height=500px instead of 100% for left navigation page fragment) to get better results uniformly on all browsers.

Comments:

Hi Winston,

What kind of panel do you mean as the LayoutPanel (Grid Panel or Group Panel)? I've problems with both of them to set the StyleClass. I put the Group Panel on the Page Fragment and try to set the StyleClass.

Is't possible to set various background css styles such as;
background-color: #052756;
background-image: url(resources/robes_vision.jpg);
background-repeat: no-repeat;
background-position: top right;

I want to get an image at the top-right site even when the browser window size is changing.

Maybe you can help me,
Thanks,
Rob

Posted by Rob on January 21, 2006 at 05:22 AM PST #

You should find the Layout Panel in the final release of Creator. Take a look at Adventure builder application http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/adventure_builder_ex.zip - Winston

Posted by Winston Prakash on January 26, 2006 at 06:30 PM PST #

Hi, Winston, I tried your method. When I deployed the application, I noticed that the footer page fragment always sit almost immediately below the header, and the left page fragment is just a very thin slice between the footer and header. I tried using px rather than % in their style, to no avail. However, in the design view, everything looks fine, it's just after deployment, the component are overlapping each other. I am using Creator 2 update 1 and IE. Do you have some idea what is happening? Many thanks. Xiaoyan

Posted by xiaoyan on July 14, 2006 at 07:51 AM PDT #

Hi Xiaoyan, As I mentioned in the notes above, IE6 has some bug that causes height=80% to fail. Instead you should use something like height=500px (or what ever height you desire). BTW, I would suggest you to look at another technique I blogged about http://blogs.sun.com/roller/page/winston?entry=template_creation

Posted by Winston Prakash on July 14, 2006 at 09:49 AM PDT #

Hallo Winston, I would like to position a footer page fragment box relative to a table component which gets its data from a database and therefore varies in height. I used the following css code to achieve this: .positionFooter { position: absolute; left: 0%; bottom: 0%; margin-left: 8px; margin-top: 8px; width: 764px; height: 72px; } however, the page fragment box overlaps the table component, do you have any idea how to fix this? Kind regards, Annet.

Posted by Annet Vermeer on December 11, 2006 at 10:18 AM PST #

Actually, the technique I explained above works well with Firefox, but fails on IE. I have used another technique in my blog (take a look at the attached project) http://blogs.sun.com/winston/entry/template_creation In this blog, I used flow mode with Panels for the center region. Since the Grid Panel, expands with dynamically sizable components such as table, the footer always remains at the bottom, no overlapping.

Posted by Winston Prakash on December 11, 2006 at 08:45 PM PST #

Winston, thanks for your reply. I did have a look at the project /template_creation, however this doesn't solve my problem, because, when I use a Layout Panel with grid layout the ajax auto complete text field I'm using falls apart, its pop up list is positioned outside the Panel, instead of right below the text field. Isn't there a way to get the tables top-left corner position, get its height, add the two together and base the footers position on the outcome? Kind regards, Annet.

Posted by Annet Vermeer on December 12, 2006 at 07:09 AM PST #

True, this technique fails on IE6, but it does work on IE7 AFAIK.

Posted by Jeff Daily on March 28, 2007 at 01:25 PM PDT #

I suspect the reason it doesn't work in IE6 is due to the use of the css style "position: fixed", which (from what I've googled) isn't supported. To get this working, I changed a few things. First, there were "unnecessary" extra DIV tags caused by the JSP page wrapping the JSP include directive and an extra one wrapping the content of the JSP fragment itself. So I removed the DIV tag that wraps the include directive. I think as a side-effect, you can no longer see the contents of the include on the JSP page you're editing. Is this a problem? Well, that depends. You can quickly "Preview in browser", but the visual editor breaks almost completely minus your original layout panel. Second, I changed all of the "position: fixed;" css styles to "absolute" instead. Now that the three DIVs (top, left, and bottom) are immediate children of the FORM (also the layout panel is an immediate child of the FORM), they are all positioned correctly. Any other crazy alternatives? Did this help anyone?

Posted by Jeff Daily on March 28, 2007 at 02:07 PM PDT #

dghd

Posted by 202.83.32.92 on May 08, 2007 at 02:27 AM PDT #

dghd

Posted by 202.83.32.92 on May 08, 2007 at 02:28 AM PDT #

How to get fragment object into javascript???

Posted by Runa on June 21, 2007 at 03:07 AM PDT #

How can we include the output of other page in middle layout panel now? can you please tell me the procedure to do it?

Posted by Ijaz on October 18, 2007 at 06:15 AM PDT #

Hi Ijaz, what you are asking may be about the Page Fragments - http://www.netbeans.org/kb/55/vwp-pagefragments.html

Posted by Winston Prakash on October 18, 2007 at 07:01 AM PDT #

What would be the procedure if we want to include a fragment at runtime in the Middle Layout Panel? or What would be the procedure if we want to include a fragment at runtime in a page?

Posted by Ijaz on October 19, 2007 at 02:46 AM PDT #

Page Fragment is an include in the page. It gets included at runtime. One Page fragment can appear in multiple pages. If you change the Page fragment, all pages reflect the changes.

Posted by Winston Prakash on October 19, 2007 at 07:34 AM PDT #

My Ajax AutoComplete Component is not working properly (Sugesstion List is displaying some where beneath in the form) with Tabsets and LayoutPanels even after doing lot much exercise from google. Kindly let me know if there is any solution.

Posted by Pardhu on November 14, 2007 at 05:12 AM PST #

Hi Parkash I want ask you that how to add images in image hyperlinks. I generate 5 image hyperlinks using for loop as follows:
ImageHyperlink navigationLink = new ImageHyperlink();
for(int i=0; i<5; i++){
navigationLink = new ImageHyperlink();
navigationLink.setImageUrl(/resources/images/abc.jpg);
}

But I got the following runtime error : duplicate component Id _image.

But when I run the for loop only once then the image is set on the image hyperlink and there in no problem. Please would you help me that how to set the image on image hyperlink in FOR LOOP for more than one times

Posted by Muhammad Ijaz on January 11, 2008 at 03:45 AM PST #

http://www.batteryfast.co.uk/gateway/bat0016.htm gateway bat0016 battery,
http://www.batteryfast.co.uk/gateway/m1200.htm gateway m1200 battery,
http://www.batteryfast.co.uk/gateway/m1300.htm gateway m1300 battery,

Posted by laptop battery on October 24, 2008 at 12:08 AM PDT #

hfhjhkj

Posted by 117.195.193.63 on June 15, 2009 at 05:43 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed