Wednesday, January 19, 2011

trying to get full control over xPage auto generated html

I know xPage is great especially for RAD but I feel bad when I see how Domino generates HTML for xPage's application and dojo why it loads even if I do not want to use it? yea, I know that most of xPage's controls use it but anywhere I want to keep control over each html-tag. I want nice html. I want to know what is going on with my html. I'm sure all of you saw what html we get from xPage, and I want to repeat once again "I'm not fan of that".
Here are couple steps for those who want to get some more control over xPage. I will show example with new application that has only one xPage.

so let's start. we created new application and created new xPage, let's call it 'index'. Open it in browser. what do you see? My Domino generates already lot of staff.

1. included dojo.
2. included css.
3. created form and put there ~6 fields for some reasons. I do not know why.
4. html, head, title, body tags and !DOCTYPE

So instead to display empty page, Domino generated ~1Kb of some data we did not ask.

1-st step: disable default dojo in xPage.
You can disable the loading of the default Dojo, for example in order to use a more recent version of Dojo. In the Package Explorer in Domino Designer open your database and find the WebContent/WEB-INF/xp.properties file.
Edit the file and addxsp.client.script.libraries=none
Switch to Java perspective and Package Explorer there by default, so go there and make update. Save and check results. 2 line disappeared.

2-nd step: disable CSS.
create new Theme and remove extends="webstandard" and add this Theme in application properties as one we want to use. check hmtl source again - 3 lines with css went out.

open our index xPage and go to properties, tab Basic and set CreateForm = false. Save. Check. 
nice! we are quite near :)

4-th step. get empty blank xPage.
I do not know yet the way how correctly suppress rest of these tags and how to change doctype, so next time when I found solution I will update article.

Funny, while I was looking for solution for 4-th step, I found absolutely similar article from Chris, so you can read more older one This is an xPage.

8 comments :

Jeremy said...

The content you see in your image #2 is required if you want to use any of the partial refresh functionality within XPages, its also [part] of the reason for the 6 fields you mention, etc. I understand at times you need to have such strict control over the HTML, but stripping down to the level you have pretty much gutted all the functionality XPages brings to the table. You might as well develop in a different platform like rails.

Domino Interface said...

If you eliminate everything that XPages does then what is the point of use XPages.

Dmytro said...

point is xPage still has SSJS and more easy way to use Java + I did not say I will not use dojo etc, I just want to add it when it is necessary, f.x. if I have static homepage and no js is needed - why i have to load dojo? but ofc I will load it on page where it is necessary.

Henning said...

Richard posts an interesting question. The reason why I do this is
- XPages is all that Domino offers. There is no real alternative
- Almost all my applications need scoped variables and sessions. You only get this with XPages.
- The ability to run code in servlets than in agents and SSJS.
So you do not eliminate everything but a lot. Unfortunately I can confirm that people are following Jeremy's suggestion too. The concept of XPages is a runaway for many experienced web developers but probably a real help for others.

Paul S Withers said...

If you look at xspClientDojo there are a whole host of functions that are crucial to standard XPages functionality. There's no way that I know of to prevent that loading, which in itself causes problems if you want to use a different Dojo version for a specific application rather than the whole server.

If you want a very basic HTML page without all the extra stuff XPages adds, is there any reason for not using a Notes Page/Form? in my experience the only challenge in combining traditional web and XPages in the same application is it can take a bit of time to make the look and feel identical.

Andriy Kuba said...

4th step could be solved by this way:
http://quintessens.wordpress.com/2010/12/30/q-how-to-use-an-xpage-as-xml-source-rss/

Unknown said...

This seems like a lot of work just to have clean HTML.

The way I approach this same situation is to use agents.

In the agent:
1. Use the MSXML parser to generate validated HTML.
2. Use a function to output your own headers, then newline-ify your html, print it.

Ultimate control and validated clean tags.

Ashley said...

This was lovely thanks for sharing this