views:

62

answers:

2

Hi,

I am using eclipse to create my jsf project.

I created my own components, and I don't want the other programmers to be able to use jsf regular components like h:inputtext etc.

How can I do it in eclipse, that if the user adds specific tags like h:inputtext he will see errors in the page and also when trying to run it?

+3  A: 

That is not Java, that is JavaServer Faces.

You cannot - on a general principle - make that happen for other developers. They will circumvent it if needed.

What you can do, is to have a policy enforced that your components are to be used instead of stock JSF ones, and then verify that when building. Either your source repository or your build server (preferred) should test for this and fail the operation. This will also allow a developer to use standard JSF if needed for debugging locally as long as it is not shared.

For checking a JSF page, you can take advantage of it being an XML document and use XSLT to validate all tags and attributes. My approach would be to check the name space on all tags and trigger failure if found in a blacklist.

Thorbjørn Ravn Andersen
I'm very much of in favour of this build-time approach, though it might delay verification until after the offending code is checked into source control.
McDowell
Do not restrict more than necessary. You _will_ need the flexibility some day.
Thorbjørn Ravn Andersen
@Odelya, let us know how it goes.
Thorbjørn Ravn Andersen
A: 

I guess you could write an Eclipse WTP validation plugin to verify your view files. I'd check for the presence of the http://java.sun.com/jsf/html namespace.

An easy way to ban these tags would be to make them blow up at runtime. You can do this by redefining the concrete components to a component that throws an exception on instantiation. For example, to replace the commandButton implementation you would define a component type of javax.faces.HtmlCommandButton in a faces-config.xml. If you're writing custom controls, you probably already have a fair understanding of this area. This will require adding a library to the application(s).

McDowell