50

How to activate eclipse (3.5, WTP) content assist in .xhtml pages for JSF (1.2) tags, using facelets? It works in .jsp files, but not xhtml.

I google a lot, and in many places (including MyFaces wiki) it is said - "Eclipse can't work with xhtml and facelets"

Since this works with .jsp files, I assume there might be some mechanism with which to activate that content assist.

I started working on a project, which has already a large codebase, so changing the extensions is not an option. Additional plugins are aslo undesirable, but acceptable if nothing else works.

(I'm asking the question to verify if someone hasn't found a witty workaround to this issue - otherwise I know it's not possible)

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • are there any other answers that worked for this, as neither work for me, with .xhtml and rich faces. – f1wade May 12 '14 at 09:44

10 Answers10

70

Found the solution pretty quickly after asking the question (and an hour after I started attempting to solve it):

Window > Preferences > General > Content Types > Text > JSP > Add (xhtml)

Makes the files be treated as jsp ones. Thus when they are opened with the JSP editor, the autocomplete of any tag library that has its definitions in .tld format (<h: and <f for example) works. Facelets, and facelets-only tags still don't work. Their .tld equivalents should be added somewhere in the projects. Facelet's tld can be found here.

Another, a bit more complex solution is described here.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Maybe he was angry, that you answered your own question ;-) By the way, It worked for me as well! (+1) – Nils Schmidt Aug 04 '10 at 14:13
  • 3
    This worked me for Galileo but now switched to the latest version Indigo and I cannot get it work. Anyone luck with Eclipse 3.7 Indigo + Facelets? – Balázs Németh Jul 24 '11 at 14:41
  • 2
    For Eclipse 3.7 adding JavaServer Faces 2.0 facet to the project solved the issue for me. *.xhtml is already registered in the Preferences window under HTML. – Vítor E. Silva Souza Jul 30 '11 at 08:13
  • this doesn't work for me, i still cant get code assist on .xhtml files for rich faces. – f1wade May 12 '14 at 09:41
49

In Eclipse Indigo (3.7) adding *.xhtml as a jsp does not work.

Adding a project facet solves the issue:

Right click on the project -> Preferences -> Project Facets -> Click on "JavaServer Faces", version should most probably be 2.0.

Then it asks for a library, you can click on "disable...", because most probably you already would have the jars configured. I don't have mine as a library so I ignored that part.

Screenshot: enter image description here

mist
  • 1,853
  • 2
  • 19
  • 33
  • 5
    Bozho's solution didn't work for me at first. But your solution of adding a JSF facet to my project worked immediately. Merci Mihail – kiwifrog May 30 '12 at 15:28
  • this doesn't work for me, I still cant get code assist on .xhtml file. – f1wade May 12 '14 at 09:35
7

Use JBoss Tools, it is what I use for my JSF+Facelets projects. It is the best you can get if you need to work with this technology.

http://www.jboss.org/tools

I recommend using the latest candidate release which is CR1 as it is the one compatible with Eclipse 3.5, the final version should be out soon but CR1 is rock solid.

http://in.relation.to/Bloggers/JBossTools31CR1Released

kpolice
  • 591
  • 3
  • 4
  • 1
    good. But is it certainly working with .xhtml extension? Anyway, my preferred solution is the non-additional-plugin one – Bozho Jan 26 '10 at 00:33
  • yes it works with xhtml out of the box and a lot more things that are useful if you do JSF development, including any tag library, even custom facelets tags. – kpolice Jan 26 '10 at 04:44
  • since I use SpringSource Tool Suite, it feels strange if I install JBoss's and SpringSource's tools in the same installation =)) I sure hope it will work. – Hendy Irawan Feb 18 '10 at 03:16
  • 1
    Adding a plugin should be for the plugin's own merits, not to add a functionality that Eclipse has on its own. – mist Sep 07 '11 at 12:58
  • Didn't work here, and it's really heavy (couldn't use if worked)... :( – The Student Nov 04 '15 at 12:36
2

I had JBoss Tools installed and had JavaServer Faces facet configured for my project (in Eclipse Mars), but still didn't get any content assist from my .xhtml files. A solution not mentioned here is to choose Add JSF capabilities:

Add JSF Capabilities

Simply right click the project, and select Configure -> Add JSF Capabilities.

It would look like the picture above but it would say Add JSF Capabilities instead of Remove JSF Capabilities. In the above picture, I had already added JSF capabilities.

Magnilex
  • 11,584
  • 9
  • 62
  • 84
  • what do you mean `in the place where Remove JSF Capabilities is located`? – ACV Mar 28 '16 at 20:15
  • @ACV Perhaps the answer was a bit unclear. In my case I had already added the capabilities, which is why the picture says _Remove JSF Capabilities_. If I had not done that already, it would say _Add JSF Capabilities_ instead. Thanks for the comment. – Magnilex Mar 29 '16 at 15:36
  • thanks. I could not solve the problem even though I had jboss tools :( – ACV Mar 29 '16 at 19:23
1

Have you thought about MyEclipse? It isn't free, but it is a pretty nice tool. It helped a lot when I developed with JSF.

Michael Balint
  • 2,255
  • 4
  • 25
  • 27
  • 1
    I haven't considered it for two reasons: 1. it's not free 2. the last time I evaluated it it was so buggy I had to reinstall eclipse in a while. True it was a long time ago, but stil.. – Bozho Jan 25 '10 at 23:51
1

Check that you have include primefaces namespace! So your html tag could look like following:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">

I have been using in Eclipse Luna and primefaces 5.

Shekh Akther
  • 713
  • 6
  • 13
1

If nothing work you must go to Preferences->General->Keys Then search for "content assist" if only one "content assist" for "when" "Editing Java source" exist copy this command. And set the binding to ctrl+space and when "Editing JSP Source".

Abhishek
  • 6,912
  • 14
  • 59
  • 85
1

If you already installed JBoss Tools and still have this problem then uninstall JBoss tools. Restart eclipse. Make sure you don't have any JBoss tool lingering in your installed components list.

Now go back to eclipse market.

Install just: JBoss JSF, JBoss Richfaces and JBoss Visual Page Editor from the JBoss tool set. Do not download the whole package which comes with over 30+ tools. It is a bloated package and will slow down eclipse and unnecessary bloat your eclipse instance.

Enable JSF facet with latest JSF implementation library. I'd recommend you to directly download it this jar from the official JSF website.

Close eclipse.

Open eclipse and create a new workspace.

Import the project back into the new workspace.

This worked for me!

ChaitanyaBhatt
  • 1,158
  • 14
  • 11
1

I have install JBoss Tool for JSF coding purpose.But in *.XHTML it was not showing content assist for ManagedBean..so I did following steps that's work for me.

For my project this steps worked.

1)Right click on project --> Configure-->Add JSF Capabilities.. Step-by-step procedure (Vailaaa!!! Problem Solve).. Go to Xhtml file and try to code #{m^anagedBeans.HelloJSF()} where (^) this is the sysmbol there you just have to "Ctrl+space" Content Assist will work.here

  • 1
    In my eclipse (luna) there is no option for adding JSF Capabilities. Instead in the `project properties` > `Project Facets` I have enabled *JavaServer Faces* at version `2.2`. But still no content asist in `xhtml` file – Mohammad Faisal May 28 '16 at 16:44
0

Suggestion: in eclipse Indigo(classic) and working with maven projects

as the picture you can see bellow, can't find Project Facets selection that @mist suggested (because am haven't installed any plugins but m2e I guess).

enter image description here

so, I did this to solve that issue:

Window >> Preference >> General >> Content Types >> XML >> Add file association (*.xhtml)

this work not so well (content stoppage).

Teifi
  • 713
  • 2
  • 12
  • 20