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

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"

Related

Issues Migrating Liferay 6.1 theme to 7

I've been following these instructions, in an attempt to migrate a theme from our 6.1 portal to Liferay 7. The initial issue I seem to be having is getting the imported and upgraded theme to use vm as the template extension. I've added a look-and-feel.xml file containing the correct template-extension element to the 6.1 theme before importing/upgrading, but I am still receiving a "portal_normal.ftl not found" error after applying the theme.
Additionally, after importing and upgrading the theme into the Liferay 7 toolkit, the theme seems to only contain the child-specific theme files, and not the "compiled" set that would include the parent files (as it would had it been generated by the old sdk).
Any help resolving these issues would be greatly appreciated!
Liferay DXP/7 support freemarker. So your template files should be .ftl not .vm.You have to migrate template files into freemarker manually.
Regarding CSS: once you migrated theme, you will find a folder named 'src', you should make changes in files, placed here. Once you will find another folder over here named 'build'here you will find theme like we had in webapps in older versions.
Hope it will help

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

How can I build YUIDoc with offline resources?

When you build & run YUIDoc it gets some of his resources from http://yui.yahooapis.com/.... These resources include the stylesheet and yui.min.js.
How can I download and use these resources offline?
The reason for this is because we run our docs on a HTTPS server. The YUIDoc serves his files always over HTTP protocol.
I had the same problem and I really don’t understand why the don’t have a valid certificate for yui.yahooapis.com. Here’s what works for me (with YUIDoc 0.5.0):
Create a custom theme
First of all, you’ll need to create a new theme that overrides some parts of the default theme.
Create the following folder structure:
my_theme
├── assets
│   ├── css
│   └── yui
└── layouts
Modify the main layout
To avoid loading the remote CSS and scripts, you need to alter the main layout.
Copy the file called main.handlebars from the original theme to your my_theme/layouts/ folder. If you installed YUIDoc via node, the original file is located in node_modules/yuidocjs/themes/default/layouts/. Alternatively, you can grab it from the yuidoc GitHub repo.
Make the following changes in that file:
1.) Replace the link tag referencing the remote stylesheet:
<link rel="stylesheet" href="{{yuiGridsUrl}}">
<link rel="stylesheet" href="{{projectAssets}}/css/cssgrids-min.css">
2.) Replace the script tag referencing the remote YUI library:
<script src="{{yuiSeedUrl}}"></script>
<script src="{{projectAssets}}/yui/build/yui-base/yui-base-min.js"></script>
Add a local copy of the remote assets
1.) Fetch the CSS from Yahoo’s CDN
Download cssgrids-min.css from the Yahoo CDN and put it in your my_theme/assets/css folder.
2.) Download the YUI 3.9.1 library
Download YUI 3.9.1 from http://yui.zenfs.com/releases/yui3/yui_3.9.1.zip (Release Notes) and put the build folder from the archive to my_theme/assets/yui.
Build your docs
When building your docs, make sure you specify your custom theme:
$ yuidoc my_js_folder --themedir my_theme
Possible improvements
Since this adds a bunch of files to your project, it might make sense to dive a little deeper into YUIDoc and see which YUI modules are actually required and remove everything else. Also, combining the files would be desirable (the library served form Yahoo’s CDN does this and it should be possible to get this working locally as well).

JSF xmlns URI not registered in IntelliJ IDEA

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

Deploying theme and portlets in Liferay running on non root context

Our Liferay Server is setup on a non-root context. The portal context is setup as -
portal.ctx=/lportal
As a result of this the theme that we developed doesn’t work. The images css are not loading in the non root context.
Also, the custom css that the portlets have those are also not loading.
Any clues on how to fix this.
Regards,
Tina
We ran into the same problem, and we solved it by using a custom deployment descriptor for the application server.
We were using WebLogic, so we added a weblogic.xml file to the theme, with a context-root directive specifying the non-root context:
<?xml version="1.0"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<context-root>/foo/your-theme</context-root>
</weblogic-web-app>
Instructions for doing this with Tomcat or JBoss should be fairly similar.
And then you also have to specify the virtual path in the Liferay theme descriptor (liferay-look-and-feel.xml)
<?xml version="1.0"?>
<!DOCTYPE look-and-feel PUBLIC "-//Liferay//DTD Look and Feel 6.0.0//EN" "http://www.liferay.com/dtd/liferay-look-and-feel_6_0_0.dtd">
<look-and-feel>
<compatibility>
<version>6.1.10+</version>
</compatibility>
<theme id="foo-theme" name="Foo Theme">
<virtual-path>/foo/your-theme</virtual-path>
</theme>
</look-and-feel>
After redeploying the theme, the links to CSS, javascript etc will be working fine under /foo/your-theme.
Note that a theme always is deployed as its own web context - independent of Liferay. So when Liferay is deployed at http://www.example.com/lportal, your theme is deployed at http://www.example.com/my-theme and should reference images from there.
If Apache is generating your 404 error, make sure that it's forwarding the request to your appserver. Typically, if you have mod_jk or mod_proxy or similar configured to forward /lportal to Liferay, you also need to forward /my-theme.
If that doesn't help, please give some more information, like version and sample css that doesn't work, including what it generates.

Resources