JSF xmlns URI not registered in IntelliJ IDEA

2019-01-18 04:42发布

Here is the start of my JSF file:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ace="http://www.icefaces.org/icefaces/components"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core">
<h:head>
</h:head>
<h:body>

However, http://www.icefaces.org/icefaces/components and http://java.sun.com/jsp/jstl/core are highlighted in red with error URI is not registered. This causes many other subsequent tags to appear in red with errors element 'x' is not allowed here. Here is an image showing what I mean:

xmlns and tags appear in red

Attempted solutions:

When searching for a solution, it appeared some others with the same problem solved it by doing "Fetch External Resource". However, this didn't work for me. For the icefaces xmlns xmlns:ace="http://www.icefaces.org/icefaces/components" I get the error: Error while fetching http://www.icefaces.org/icefaces/components. And for the jstl xmlns xmlns:c="http://java.sun.com/jsp/jstl/core" I get the error: No XML at the location: http://java.sun.com/jsp/jstl/core.

I also found some people solved it by deleting the IntelliJ IDEA metadata file workspace.xml in the .idea directory. This does seem to work temporarily... but then it seems the problem comes back after a while. I also have to reconfigure several project settings which I would like to avoid.

Any help would be appreciated.. I'm not really familiar with the xmlns stuff and still a beginner to web app development. Thank you!

Update:

As per Mark Vedder's answer, I manually added external resources to my project and the problem has not resurfaced thus far.

7条回答
▲ chillily
2楼-- · 2019-01-18 05:21

I had the same issue... but in my case, the problem was that by mistake I saved file with extension ".xml". Changing it into ".xhtml" solved the problem

查看更多
你好瞎i
3楼-- · 2019-01-18 05:26

I tried every thing suggested here to get intellij to recognize the correct version of my jsf. At the end I discovered that I didn't have a direct reference in my web project maven dependencies to jsf-api. In other words, adding

<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>2.1.29-08</version>
  <scope>provided</scope>
</dependency>

to my pom, fixed it. The confusing thing is that intellij was able to resolve a subset of the jsf symbols, which makes you think that the jar was being seen by it, albeit a wrong version of the jar.

查看更多
再贱就再见
4楼-- · 2019-01-18 05:29

With unregistered resources, the first solution is to use the "Fetch External Resource" quickfix. If that fails, as it has for you in this case, (usually because the "location" is in name only) you need to manually configure it.

To Manually Configure

  1. If the resource (i.e. the .xsd, .dtd, etc.) exists in one of your library jars, skip to step 2. Otherwise, download a copy of the resource. Put it somewhere convenient on your system.
  2. In IDEA, with your cursor on the error, open the Quick Fix / Intentions menu by typing Alt+Enter and select "Manually Setup External Resource". (If you do not have this option (based on IntelliJ IDEA version) go to the next section for instructions.)
  3. If the resource is in a jar, select the Schemas tab and select the resource from the appropriate jar. If you downloaded it, select the Explorer tab (may be named Finder in Mac) and navigate to and select the file you downloaded.
  4. Click OK and let IDEA index the resource.

To Edit or Set via IDE Settings

  1. Open the settings Dialog via Ctrl+Alt+Enter or File > Settings.
    • To configure for all future new projects so this schema is avaiable, open the similar dialog via File > Other Settings > Default Settings
  2. In the Project Settings section, find the Schemas and DTDs node.
  3. Configure the desired schema. There are add, edit and delete icons in the upper right. Like above, you can select a file within a library via the Schemas tab, or your file system via the Explorer tab.

UPDATE

The various JSF Taglib definitions (for JSF 2.x and above) can be found in the com/sun/faces/metadata/taglib directory of the com.sun.faces:jsf-impl jar. The jsf-impl JAR file can be downloaded from maven central among other places.

查看更多
孤傲高冷的网名
5楼-- · 2019-01-18 05:29

This error happens when you do not attach the library of JSF Mojarro. Download and add that library in the project.

File> Project Structure> Library 

add JSF the library.

查看更多
该账号已被封号
6楼-- · 2019-01-18 05:31

you could also add "urn:import:<url>"

example: xmlns:d="urn:import:com.mypackage.mylovelycode"

查看更多
乱世女痞
7楼-- · 2019-01-18 05:32

I was having same issue with icefaces resources.
One way to fix this is to give the project (again, if you already did not) the IceFaces framework support (right click on project name).
In my case I was using 3.3.0, then I set download in the Add Framework Support form.
Intellij downloaded 3.1.0 and the IDE recognizes the resource immediately after. Later I set again the 3.3.0 version.
So, I think is enough to re download the framework again, and the resources will be downloaded in META-INF folder.

Regards.-

查看更多
登录 后发表回答