Thursday, January 15, 2009

Task 4 – Customize Eclipse for Tapestry 5 template editing

As there is no initiative, at least to my knowledge, for Tapestry 5 support in Eclipse, we will have to manage with some manual tweaking.

First bring up a preference dialog (Windows/Preferences). Then type cont in the filter area to narrow down preferences which we are looking for. Click on Content Types under the General node. On the right side of the dialog find Text/HTML node and select it. All file associations for HTML content type are listed in the area just bellow.

We have to add Tapestry’s templates to be associated with HTML content type, so click on Add button and type *.tml in the input field and click OK.

You should see another entry in the File associations list - *.tml. Now confirm the addition by clicking on an OK button.

From now on a HTML editor which comes with Eclipse WTP is the default editor for tml files. This editor unfortunately does not handle formatting of the source code (tml in our case) very well.

If you are a one man band and don’t care about indenting the tags by some rules then you can safely skip this screencast bellow.

For others, who might have questioned themselves if there is a way, I will show you how you can make your templates look better in the editor and most importantly – with fewer conflicts if two or more designers are working repeatedly/in sequence with the same set of templates checked-in in some source control system like subversion and using the same formatter.

The screencast is best viewed in full screen mode.


A link to the plugin http://eclipsetidy.sourceforge.net

Below are the tags that I was talking about in the screencast that should be copied into the Eclipse Tidy preferences. It is just a quick first proposition – like monkey sort (not at all tested)

inline tags:
t:actionlink, t:addrowlink, t:ajaxformloop, t:any, t:checkbox, t:datefield, t:delegate, t:eventlink, t:gridcell, t:label, t:output, t:passwordfield, t:outputraw, t:removerowlink

block level tags:
t:beandisplay, t:beaneditform, t:beaneditor, t:errors, t:exceptiondisplay, t:form, t:formfragment, t:forminjector, t:grid, t:gridcolumns, t:gridpager, t:gridrows, t:if, t:linksubmit, t:loop, t:pagelink, t:palette, t:propertydisplay, t:propertyeditor, t:radio, t:radiogroup, t:renderobject, t:select, t:submit, t:submitnotifier, t:textarea, t:textfield, t:textoutput, t:unless, t:zone

I was also talking about DOCTYPE. If you want to know more go here (http://www.w3.org/QA/Tips/Doctype).

In the screencast I made a template. Here it is for you to copy/paste if you want:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
Insert title here
</title>
<link rel="stylesheet" type="text/css" href="${asset:context:css/MY-STYLESHEET.css}" />
</head>
<body>

</body>
</html>

If you look at the source code in the browser of the school application (Index page), Firefox 3 shows:


We can modify AppModule.java (method contributeApplicationDefaults) in a way to tell Tapestry not to compress white spaces,

configuration.add(SymbolConstants.COMPRESS_WHITESPACE, "false");

so the output is more readable:

It is not perfect, but good enough to eye scan the sources.

One more quick tip. Maybe you have noticed, you have to press F5 (refresh) on a running project (jetty:run) for some changes you have made to take effect. There is an option in the Preferences which can save you from pressing the button again and again.

Next time we will learn how to create java code templates to speed up Tapestry 5 web application development.




Reblog this post [with Zemanta]

6 comments:

  1. Hi, Sorry for the question, It's not pretty much related with your post, I hope You can help me. I develop with tapestry since version 3, I have some proyects that has two or more applications in one WAR developed in Tapestry 3, when I tray to do the same in Tapestry 4.1 I had multiple errors running it. My doubt is in Tapestry 5 may I have many applications in one WAR?

    ReplyDelete
  2. Hi,

    I think you can not have multiple apps in one war in T5. See https://issues.apache.org/jira/browse/TAPESTRY-1888.

    Also http://www.nabble.com/more-than-1-tapestry.app-package-to19138593.html#a19138593

    Can you describe the use case you are having? I think you can redesign your apps to be in separate packages.

    ReplyDelete
  3. Hi Borut,

    In Tapestry 3 I had many application files p.e. app1.application, app2.application each one defines its pages an componets. In the other side, in my web.xml I had one servlet tag per application file and finaly I had one security-constraint tag per servlet. Each one of the servlets has diferents security constraints. Everything was fine until I tried to do the same in Tapestry 4.1, this version caused unexpected exceptions when two persons try to open diferents applicatios. I don't want deploy to many war files as applications, currently I had 20 wars in my application server if I had to divide my aplications, I could reach 40 wars.

    ReplyDelete
  4. Do You think that I could have a solution in Tapestry 5, I can redisign some applications but I want to keep the same behaivor. Thanks for your time.

    ReplyDelete
  5. what plugin is used to get those colors (and code completion?) inside Eclipse?

    ReplyDelete
  6. Normal Eclipse EE Edition brings in the HTML editor which can colorize the tml. Just make sure you register tml extension with HTML editor in preferences.

    ReplyDelete