Java 带有 facelets (jsf) 和 xhtml 的 Eclipse 自动完成(内容辅助)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2136218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:00:31  来源:igfitidea点击:

Eclipse autocomplete (content assist) with facelets (jsf) and xhtml

javaeclipsejsffacelets

提问by Bozho

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.

如何使用 facelets 在 .xhtml 页面中为 JSF (1.2) 标签激活 eclipse (3.5, WTP) 内容辅助?它适用于 .jsp 文件,但不适用于 xhtml。

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

我谷歌了很多,在很多地方(包括 MyFaces wiki)都说 - “Eclipse 不能使用 xhtml 和 facelets”

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

由于这适用于 .jsp 文件,因此我假设可能存在某种机制来激活该内容辅助。

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)

(我问这个问题是为了验证是否有人没有找到解决这个问题的机智方法 - 否则我知道这是不可能的)

采纳答案by Bozho

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)

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 .tldformat (<h:and <ffor example) works. Facelets, and facelets-only tags still don't work. Their .tldequivalents should be added somewhere in the projects. Facelet's tld can be found here.

使文件被视为jsp文件。因此,当它们与JSP编辑器中打开,即在其定义的任何标签库的自动完成.tld格式(<h:<f例如)的作品。Facelets 和 facelets-only 标签仍然不起作用。它们的.tld等效项应添加到项目中的某处。Facelet 的 tld 可以在这里找到。

Another, a bit more complex solution is described here.

此处描述另一种更复杂的解决方案。

回答by Michael Balint

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.

你有没有想过MyEclipse?它不是免费的,但它是一个非常好的工具。当我使用 JSF 进行开发时,它有很大帮助。

回答by kpolice

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.

使用 JBoss 工具,这是我用于 JSF+Facelets 项目的工具。如果您需要使用这项技术,这是您能得到的最好的结果。

http://www.jboss.org/tools

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.

我建议使用最新的候选版本 CR1,因为它与 Eclipse 3.5 兼容,最终版本应该很快就会发布,但 CR1 坚如磐石。

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

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

回答by mist

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

Eclipse Indigo (3.7) 中,将 *.xhtml 添加为 jsp 不起作用。

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.

右键单击项目 -> Preferences -> Project Facets -> 单击“JavaServer Faces”,版本很可能是 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.

然后它要求一个库,您可以单击“禁用...”,因为很可能您已经配置了 jar。我没有我的图书馆,所以我忽略了那部分。

Screenshot: enter image description here

截屏: 在此处输入图片说明

回答by Teifi

Suggestion: in eclipse Indigo(classic) and working with mavenprojects

建议:在eclipse Indigo(经典)和maven项目中工作

as the picture you can see bellow, can't find Project Facetsselection that @mistsuggested (because am haven't installed any plugins but m2eI guess).

正如您可以在下面看到的图片,找不到建议的Project Facets选择@mist(因为我还没有安装任何插件,但m2e我猜)。

enter image description here

在此处输入图片说明

so, I did this to solve that issue:

所以,我这样做是为了解决这个问题:

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

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

this work not so well (content stoppage).

这项工作不太好(内容停止)。

回答by Shekh Akther

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

检查您是否包含了 primefaces 命名空间!所以你的 html 标签可能如下所示:

<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.

我一直在 Eclipse Luna 和 primefaces 5 中使用。

回答by RyuImperator

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+spaceand when "Editing JSP Source".

如果没有任何效果,您必须转到首选项->常规->键然后搜索“内容辅助”,如果只有一个“内容辅助”用于“何时”“编辑Java源”,请复制此命令。并在“编辑 JSP 源”时将绑定设置为ctrl+space和。

回答by ChaitanyaBhatt

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.

如果您已经安装了 JBoss 工具,但仍然存在此问题,请卸载 JBoss 工具。重启日食。确保您的已安装组件列表中没有任何 JBoss 工具。

Now go back to eclipse market.

现在回到eclipse市场。

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.

只需安装:JBoss 工具集中的 JBoss JSF、JBoss Richfaces 和 JBoss Visual Page Editor。不要下载包含 30 多种工具的整个软件包。它是一个臃肿的包,会减慢 Eclipse 和不必要的膨胀你的 Eclipse 实例。

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

使用最新的 JSF 实现库启用 JSF facet。我建议您直接从 JSF 官方网站上下载这个 jar。

Close eclipse.

关闭日食。

Open eclipse and create a new workspace.

打开 eclipse 并创建一个新的工作区。

Import the project back into the new workspace.

将项目重新导入新工作区。

This worked for me!

这对我有用!

回答by Magnilex

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 .xhtmlfiles. A solution not mentioned here is to choose Add JSF capabilities:

我安装了 JBoss Tools 并为我的项目(在 Eclipse Mars 中)配置了 JavaServer Faces facet,但仍然没有从我的.xhtml文件中获得任何内容帮助。这里没有提到的一个解决方案是选择Add JSF capabilities

Add JSF Capabilities

添加 JSF 功能

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

只需右键单击该项目,然后选择Configure-> Add JSF Capabilities

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

它看起来像上面的图片,但它会说Add JSF Capabilities而不是Remove JSF Capabilities。在上图中,我已经添加了 JSF 功能。

回答by Sandesh More

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.

我已经为 JSF 编码目的安装了 JBoss 工具。但在 *.XHTML 中,它没有显示 ManagedBean 的内容帮助......所以我做了以下对我有用的步骤。

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)右键单击项目-->配置-->添加JSF功能.. 分步过程(Vailaaa!!!问题解决)..转到Xhtml文件并尝试编码#{m^anagedBeans.HelloJSF( )} 其中 (^) 这是系统符号,您只需“Ctrl+空格”即可使用内容辅助。这里