JSF xmlns URI not registered in IntelliJ IDEA - jsf

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

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
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.
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.)
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.
Click OK and let IDEA index the resource.
To Edit or Set via IDE Settings
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
In the Project Settings section, find the Schemas and DTDs node.
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.

A probable issue could be that the "Java EE: Java Server Faces" plugin is disabled. You can enable it by browsing to
Settings > Plugins and on the Installed tab search for Java Server Faces.

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.

In IntellijIDEA 2022 we need to add Plugin Jakarta EE: ServerFaces(JSF)

If you are using "IntelliJ Idea", please open the "Project Structure" dialog by clicking Ctrl+Alt+Shift+S, look for the JSF not found in the artifact (some thing like that) error notification, please click the fix it option and change the JSF scope to provided. It fixed my problem.

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.

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

you could also add "urn:import:<url>"
example:
xmlns:d="urn:import:com.mypackage.mylovelycode"

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

Related

JetBrains PhpStorm 2018.2: Error while fetching external resource (xmlns, schemaLocation, xsd)

I want to use autocompletion at my typo3 fluid templates for some viewhelpers i.e. vhs, but PhpStorm could not fetch the external resource. It only works, if I download the xsd schema file and "manually setup external resource". It would be very nice, If the program could do this.
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
v:schemaLocation="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers https://fluidtypo3.org/schemas/vhs-master.xsd">
<!-- my code -->
</div>
Not sure why your schemaLocation doesn't work, but try replacing the XSD URL with one you get from https://viewhelpers.fluidtypo3.org/ and re-download the schema from there. You'll have to pick a specific version, though.
The schemas there are generated fresh with a couple of fixes to the XML source they contain. Nothing that I expect would affect the download.
One thing though - both those URLs are served with a multi-hostname SSL certificate which means the version of openSSL you use must be at least I think it was 0.94.4 in order to be compatible. If your OS is very old it might help to update the openSSL library or do an OS update. But in all cases it should work if you use a browser to download since all current browsers understand SNI.

Edit XHTML of a deployed JSF project in glassfish

I have a web application I'd like to edit while it's already deployed.
The part I'd like to edit is inside ...applications/myapplication/WEB-INF/classes/META-INF/*.xhtml.
I have a tool that I use to generate these XHTML files and insert them into the aforementioned directory. In a production environment actually these XHTML files are part of a jar project included as a dependency in the main web application.
But what I need is to make hot deploy during development.
I can do it by removing the jar dependency and adding the XHTML in the directory mentioned above. But updating it later doesn't do the job.
Any idea?
If you're using IntellijIDEA, just go to the configuration of glassfish server and select "Update Resources" on "Frame Deactivation".

Unable to find resource css, style.css [duplicate]

This question already has answers here:
How to reference CSS / JS / image resource in Facelets template?
(4 answers)
Closed 5 years ago.
I created a Java JSF application in NetBeans 8.02 with GlassFish 4.1. One of the web pages created as a facelet contains the following tags:
<h:head>
<title>Address Book: Add Entry</title>
<h:outputStylesheet name="style.css" library="css"/>
</h:head>
When I run the application I get the error:
Unable to find resource css, style.css
I look in the Web Pages/ resources /css folder in my project and style.css is present. If I add the style.css folder from another project, everything works fine.
What do I need to do so that either style.css is automatically placed in the correct folder instead of me manually having to do it --- or is there something missing in how I set up my project or wrote the xhtml tag?
Seems to me that you are not using the correct /resources folder, you should use the /resources directory in the root of your web application as mentionned by Tiny's comment (subfolder of WebContent), And not the resources folder which contain your java classes. Here is an example:
However, you are not correctly using the h:outputStylesheet, you should better use it like this:
<h:outputStylesheet name="css/styles.css" />
A detailled answer regarding the JSF resource library was provided by BalusC: What is the JSF resource library for and how should it be used?
I had the same problem with NetBean 8.1.
I solved this problem by writing
h:outputStylesheet name="resources/css/default.css"
h:outputStylesheet name="resources/css/cssLayout.css"
I did not change the location to the style files:
the path to the stylesheet files in the project view of NetBean 8.1
This seems to be an issue with Netbeans 8.1. However, version 7 generates the template page correctly.
Try replacing h:outputStylesheet tag with one below:
<link href="./resources/css/style.css" rel="stylesheet" type="text/css"/>
Try this:
I had the same problem but easy to solve if You aware of the attribute library to get the default path for Me.
The default location for css StyleSheets is "./resources/css/yourcss.css"

Is it possible to have Liferay SDK in different location than the source codes?

I'd like to ask you for best practices with developing with Liferay SDK.
I have the SDK downloaded, I have Eclipse ready, it works, I can create new portlets and run local Liferay instance to test it.
Here is my situation - all the source code I have is in the Eclipse workspace, currently it is only portlets what I'm working on.
Liferay SDK I have in completely different location than workspace. Let's say ~/dev/liferay_sdk.
Eclipse workspace is located in ~/workspace.
At the beggining, it was not working like that. Eclipse from some reason can't find or use Liferay SDK. When I changed "Project validation" in Eclipse/Liferay configuration to "Ignore" the "Liferay Plugin SDK is not valid", it started to work without problems.
Next problem happend when it comes to need to build a WAR for example.
In the portlet directory in the workspace is present "build.xml" file. But inside it refers to another xml file, which should be located one directory up, and this one refers to more thing in relatively location and so on.
In short, it assumes that you have the portlets etc, inside the Liferay SDK.
Like "~/dev/liferay_sdk/portlets".
My question is, Am I wrong completely, or could you suggest me the best practices with this?
I don't want to mix SDK and the code, it sounds wrong to me.
Thanks for help!
I think, the best practice is still when your portlet projects are located inside the Liferay Plugins SDK directory. That way you can take all the advantages of the Liferay IDE plugin for Eclipse, for example. Because as far as I understand Liferay IDE will not allowed you to have portlet projects in another location. It's pretty easy to import projects to Eclipse from inside the Liferay SDK directory, and that's not problem.
But I also faced the same sort of problem when tried to save portlet project to the Git repository. Possible solutions with symbolic links didn't work correctly on every system. Thus I slightly modified the build.xml file to be able to run ant tasks from any directory. For portlets it was something like that:
<project name="your-portlet" basedir="." default="deploy">
<property file="build.properties" />
<property name="project.dir" value="${liferay.sdk.home}" />
<import file="${project.dir}/build-common-plugin.xml" />
</project>
Notice that you should define property "liferay.sdk.home" in build.properties and it should be path to the Liferay Plugins SDK.
As for other types of Liferay plugins (themes, hooks, etc.) you should import another build file for building that type of plugin. For example, for themes it will be:
<import file="${project.dir}/themes/build-common-theme.xml" />
Hope you'll get the idea. :) But think twice before doing something like that.
Liferay plugins are developed inside the Liferay Plugins SDK, its called SDK for a very good reason.
I don't find anything wrong with the plugins-SDK and the code tied togather, below are few reasons why:
If you see the liferay repository of plugins on github, you would find all the sample portlets and other plugins are stored in their respective folders inside plugins-SDK.
So if you want to develop liferay plugins (with or without IDE), the best practice (the only efficient way I think) is to have the projects created inside the respective folders of plugins SDK like portlet projects inside portlets folder, hook project inside hooks folder etc.
If you have used Liferay IDE when you create a plugin project (Liferay project) in this IDE you specify the SDK and the server runtime and what it does is it creates the project inside your Plugins SDK and copies the .settings, .classpath & .project file inside the project created. It does not create the project inside your workspace as eclipse normally does for other projects.
Hope I have managed explain it clearly and this was what you wanted.
I'm already quite happy with the other answers, this could have been distributed through comments at those, but a separate answer gives some more structuring options:
As Prakash says, it's not really bad to do that. In addition to his answer, you do not need to have your code in the workspace directory. Eclipse is happy to put it anywhere in the filesystem - thus while you work with Eclipse you don't even care where exactly your code is (and as you check it into version control - right? - you actually never need to care.
If you want to use Liferay's OOTB ant scripts: They are geared towards exactly the setup you describe: Work in the SDK directory. It's actually not bad, but if you don't like it, you just have to accept that you can't work with build.xml without changing it (like Artem suggests).
Another option is to use maven - this also bypasses the sdk (and the Liferay IDE integration), so you're again free to put your sourcecode whereever you like and let maven do the rest.
I can imagine some rather esoteric and rare issues with Artem's suggestion (like referring to custom parent themes when you imply some relative position) but I consider that as extremely minor, so if that works for you: Go ahead. Just keep in mind that you don't fulfill the basic assumptions that the SDK makes, so you might have to change things that violate the assumptions. I can't imagine this being too hard if you keep this in mind.
Of course, what you miss with that solution is the neat handling of including build.${username}.properties - you'll have to have your own build.properties that define ${liferay.sdk.home}. If you're not working in a team, that's ok. Otherwise you'll have to invent this yourself (and code it) or rely on global parameters to be configured with every team member.

where did this faces-config.pageflow.xml file come from?

I am migrating an application to jsf 1.2 and now out of the blue there is a new .metadata folder in the project root with a WebConent folder inside there with a WEB-INF folder still deeper and inside there we now have a super important looking faces-config.pageflow file.
I open it up and see it has references to all of my included files from other jsps.
What is the point of this file? Does it really need to be there? Is there a way to turn that crap off?
It's part of JBoss JSF Tools plugin for Eclipse (and probably also other Eclipse-based JSF plugins I am not aware of). No, you can't turn it off, just configure your IDE to hide it if it is bothering you somehow.

Resources