how to set skin for primefaces 1.1 - java

could you please explain how to set the skin for primefaces 1.1 ..

you can try to add
<h:head>
<link type="text/css" rel="stylesheet"
href="#{request.contextPath}/themes/redmond/skin.css" />
</h:head>
to your page and
<context-param>
<param-name>primefaces.skin</param-name>
<param-value>none</param-value>
</context-param>
to web.xml

From http://www.primefaces.org/themes.html:
Installing Themes
Applying a theme from Theme Gallery to
your PrimeFaces project is very easy,
you just need to download the theme
jar, add it your classpath and
configure PrimeFaces to use it.
1) You can either download the theme
manually from this page or using maven
via;
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>aristo</artifactId>
<version>1.0.0</version>
</dependency>
2) Next step is setting
primefaces.THEME parameter with the
theme name, you can also use an EL
expression for dynamic themes. view
plaincopy to clipboardprint?
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>aristo</param-value>
</context-param>
That's it!
I'm currently facing a problem like this, bhut have no real solution for that yet...

Related

Can I use webjars in IntelliJ without building the project?

Is it possible to reference webjar dependencies during compile time in IntelliJ? Imagine I'm playing with some CSS or HTML and making some little adjustments.. I don't want to clean -> rebuild project each time I change font-size or color or etc. I just want to preview them on the fly, in IntelliJ.
Assuming you have webjars Maven dependencies:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>${bootstrap.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>${jquery.version}</version>
</dependency>
You could refer to your resources by putting the following code in your templates within <head></head>:
<link href="webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" rel="stylesheet" media="screen"
th:href="#{/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}"/>
<script src="webjars/jquery/3.2.0/jquery.min.js"
th:src="#{/webjars/jquery/3.2.0/jquery.min.js}"></script>
Attributes href and src will be used in compile time, while attributes th:href and th:scr would be used by Thymeleaf in run time.
In the same way you could use your own stylesheets or scripts:
<link href="../../static/css/app.css" th:href="#{css/app.css}" rel="stylesheet" media="screen"/>
<script src="../../static/js/app.js" th:src="#{js/app.js}"></script>

Eclipse can't find JSF 2.2 taglibs

I am using JSF 2.2 taglibs but Eclipse is displaying the following warning message:
Can't find facelet tag library for uri http://xmlns.jcp.org/jsf
What bugs me is that I've faced this issue before and it was related to classpath JARs, but now it is only affecting JSF 2.2 tag libs.
Taglib xmlns:h="http://xmlns.jcp.org/jsf/html" is working fine, the warning is shown to JSF 2.2 specifics like "/jsf" and "/jsf/passthrough". Here is an image showing warnings for JSF 2.2. tag libs, but prior namespaces are loaded correctly.
I have tried to solve the issue with help of posts like this but none of the procedures (clean, restart, close/open, validate, etc) have worked for me.
Dependencies for JSF (derived from WildFly 10.1 pom.xml):
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.13.SP1</version>
<scope>provided</scope>
</dependency>
Eclipse info:
Version: Neon.1a Release (4.6.1)
Build id: 20161007-1200
Update
After looking into the taglib files I found no "passthrough" or "friendly markup" reference. So there is no surprise Eclipse won't find it...
There is no file under com.sun.faces.metadata.taglib for Friendly Markup and Passthrough, for both Glassfish and JBoss implementations.
The question now is where should these files be?
Update: opened issue WFLY-9579
It seems that the taglib files are missing from the implementation JARs, for both Glassfish and JBoss projects. I hope to be wrong but I found no other explanation.
I've posted a thread so this behavior can be investigated.
https://developer.jboss.org/thread/274046
Workaround
To stop the IDE from warning simply create empty taglibs files and associate to the web.xml. Files should go under /WEB-INF/ and have the appropriate extension taglib.xml.
The JSF implementation will behave normally and should process the facelets correctly.
friendly_markup.taglib.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<facelet-taglib xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://xmlns.jcp.org/jsf</namespace>
</facelet-taglib>
passthrough.taglib.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<facelet-taglib xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://xmlns.jcp.org/jsf/passthrough</namespace>
</facelet-taglib>
web.xml
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/passthrough.taglib.xml;/WEB-INF/friendly_markup.taglib.xml</param-value>
</context-param>
Here is what it looks like. Now the warnings are gone (and my OCD is calm again). I would like to try and make JAR dependency for it, if I find some spare time.

Spring boot webjars: unable to load javascript library through webjar

I have a spring boot (I use Thymeleaf for templating) project where I want to use some jQuery libraries.
Unfortunately, the webjars aren't loading at all. I have tried many configuration but all of them failed.
Here is the code snippet of my HTML page:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<title>JAC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="http://cdn.jsdelivr.net/webjars/jquery/2.1.4/jquery.js"
th:src="#{/webjars/jquery/2.1.4/jquery.min.js}" type="text/javascript"></script>
<script src="http://cdn.jsdelivr.net/webjars/jquery-file-upload/9.10.1/jquery.fileupload.js" type="text/javascript"
th:src="#{/webjars/jquery-file-upload/9.10.1/jquery.fileupload.min.js}"></script>
<link href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.5/css/bootstrap.min.css"
th:href="#{/webjars/bootstrap/3.3.5/css/bootstrap.min.css}"
rel="stylesheet" media="screen" />
<link href="http://cdn.jsdelivr.net/webjars/jquery-file-upload/9.10.1/jquery.fileupload.css"
rel="stylesheet" media="screen" />
</head>
I have added them in the pom file:
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.5</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery-file-upload</artifactId>
<version>9.10.1</version>
</dependency>
But when calling the page I got a 404 on jquery.min.js and jquery.fileupload.min.js.
GET http://localhost:8888/webjars/jquery-file-upload/9.10.1/jquery.fileupload.min.js
2015-09-21 02:02:04.059 home:9
GET http://localhost:8888/webjars/jquery/2.1.4/jquery.min.js 404 (Not Found)
You are referencing jquery library correctly. Maybe you are missing resource handler configuration.
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
Or if you use JavaConfig
#Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
Webjars documentation
If this will not work, please check if you have webjars on classpath (open your application JAR in 7Zip and check if webjars resources are inside it.)
After inspecting the webjar for jquery, I got this working by adding a "dist" subpath.
<script src="webjars/jquery/2.1.4/dist/jquery.min.js" type="text/javascript"></script>
Additional answer found on one blog:
When using Spring Framework version 4.2 or higher, it will
automatically detect the webjars-locator library on the classpath and
use it to automatically resolve the version of any WebJars assets.
In order to enable this feature, we’ll add the webjars-locator library
as a dependency of the application:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.30</version>
</dependency>
In this case, we can reference the WebJars assets without using the
version; (...)
if you use servlet 3.x just add :
1- using java config :
#Configuration
#EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/webjars/**").addResourceLocations("/webjars/").resourceChain(false);
registry.setOrder(1);
}
}
2- or xml config :
<mvc:resources mapping="/webjars/**" location="/webjars/">
<mvc:resource-chain resource-cache="false" />
</mvc:resources>
The webjars dependencies should be available on the spring boot classpath, so you should try referencing the webjars using the src attribute like so:
<script src="webjars/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
<script src="webjars/jquery-file-upload/9.10.1/jquery.fileupload.min.js"></script>
<link href="webjars/bootstrap/3.3.5/css/bootstrap.min.css"
rel="stylesheet" media="screen" />
<link href="webjars/jquery-file-upload/9.10.1/jquery.fileupload.css"
rel="stylesheet" media="screen" />
I ended up doing a mvn clean install (from cmd prompt) to get the target cleaned and all the lib/jars populated correctly. I am using Spring boot with Intelij.
After inspecting the webjars for jquery, I got this working by adding a "THE VERSION OF JQUERY LIBRARY USED IN POM.XML FILE"
<script src = "/webjars/jquery/3.1.0/jquery.min.js"></script>
(in my case I used 3.1.0 version, used that version only that you are using).
Make sure if you have updated the version of bootstrap or jquery when you are adding the dependencies, you should update the URL's in the jsp's or html's with the correct version of bootstrap and jquery.

JSF 2.1.13 custom component not found: Tag Library supports namespace: <namsepace> but no tag was defined for name: <compositecomponent>

Problem
I am using JSF 2.1.13 to create a prototype to demostrate the benefits of JSF over our current webapp built with JSP and struts 1.1. I following code using works with JSF 2.2.6, but I had to down grade once I found out that Oracle Weblogic 12c doesn't support JSF 2.2 yet. When running the code with 2.1.13 I receive the following error:
/pages/sites/tab-details.xhtml #27,90 <ccc:codedType> Tag Library supports namespace: http://java.sun.com/jsf/composite/ccc, but no tag was defined for name: codedType
Googling only pointed me to a bug about nested composite components, but that isn't something I'm doing.
Code
Excerpt from pom.xml
<!-- JSF Dependencies -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.13</version>
</dependency>
Composite Compontent: webapp/WEB-INF/resources/ccc/codedType.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<ui:component xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface shortDescription="Renders a CodedType">
<cc:attribute name="value" required="true"
shortDescription="Instance of CodedType to be properly rendered"
type="company.prototype.uireplacement.presenter.CodedType" />
<cc:attribute name="includeCode"
shortDescription="Whether or not the rendeder type should include the code"
type="boolean" default="false"/>
</cc:interface>
<cc:implementation>
<span id="#{cc.attrs.id}">#{cc.attrs.value.label}<ui:fragment rendered="#{cc.attrs.includeCode}"> (#{cc.attrs.value.code})</ui:fragment></span>
</cc:implementation>
</ui:component>
Page using composite component: webapp/pages/sites/tab-details.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:ccc="http://java.sun.com/jsf/composite/ccc">
<ccc:codedType value="#{siteControllerBean.selectedSite.type}" includeCode="true"/>
</ui:composition>
After more digging I found what caused my error. Note the location of my compontent: webapp/WEB-INF/resources/ccc/codedType.xhtml. The appropriate location should be webapp/resources/ccc/codedType.xhtml (root vs WEB-INF). In JSF 2.2, they allowed the location to be configurable and I had the following in my web.xml:
<context-param>
<param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
<param-value>/WEB-INF/resources</param-value>
</context-param>
which is why things worked in JSF 2.2.
The fix for my situation was to remove javax.faces.WEBAPP_RESOURCES_DIRECTORY since it isn't used in JSF 2.1 and move the resources to the root.
I recently got this error:
Make sure you put your template at location src../META-INF/resources/myFolder
and refer it using xmlns:tp="http://java.sun.com/jsf/composite/myFolder">
This helped me resolve the issue.

Java RestFull WebService: JAX-RS implementation with Jersey 2.3.1 libraries

I am trying to run a simple "Hallo World" application Jersey 2.3.1 REST service on JBoss jboss-eap-6.1 AS. In web.xml i have disabled restEasy library. During deployment i am getting the error:
JBWEB000289: Servlet
com.sun.jersey.samples.helloworld.resources.MyApplication threw load()
exception: java.lang.NoSuchMethodError:
javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
In POM i put these dependencies:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
This is my web.xml with restEasy tags disabling:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>com.sun.jersey.samples.helloworld.resources.MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.sun.jersey.samples.helloworld.resources.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
<servlet-mapping>
<servlet-name>com.sun.jersey.samples.helloworld.resources.MyApplication</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
And my resource config java class:
package com.sun.jersey.samples.helloworld.resources;
import org.glassfish.jersey.server.ResourceConfig;
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("com.sun.jersey.samples.helloworld.resources");
//super(HelloWorldResource.class);
}
}
Someone have any idea to solve it?
thanks in advance,
Roberto
NoSuchMethodError usually means you are having two different versions of the class on your classpath. As the javax.ws.rs.core.Application class does have the getProperties() method in its JAX-RS 2 version, but not in JAX-RS 1.x, I would guess that somehow you are combining the old 1.x Jersey (or old REST api) with the current (2.3.1) one.
Also the package you are working in (com.sun.jersey - the 'old' Jersey package) points a bit towards this direction (although just placing your code into that package itself cannot cause the mentioned problem), you obviously started with the Jersey 1.x example as a base (there are samples in Jersey 2 as well, see helloworld-webapp on Jersey GitHub).
Is it possible, that restEasy (also definitely containing the javax.ws.rs.core.Application class) is not completely switched off and somehow defaults to JAX-RS 1.x version?
I would start with inspecting your pom file, look at the effective pom (if your project descriptor has some parent) and check carefully what is on your classpath - I believe there is a 1.x version of javax.ws.rs-api somewhere. Also try to clean all the compiled stuff and rebuild from scratch.
Speaking of dependencies, if your list is exhaustive (regarding Jersey), you will most likely have to add jersey-common (2.3.1) dependency, as already during the initialization, the ResourceConfig.packages() method calls the PackageScanner constructor, which contains call to ReflectionHelper - and this is not a part of the server jar any more.
Hope this helps.
I faced same problem recently. I thought share my steps for you. As the other answers state, the problem is mainly because of having two different versions of the same class on your classpath. So when you add maven dependencies in your pom be careful.
These kind of problems are normally called as Jar Hell. You can use jhades API for investigate the classes overlap one another. Here is the simple steps i have followed.
Add jhades dependency into your pom.
<dependency>
<groupId>org.jhades</groupId>
<artifactId>jhades</artifactId>
<version>1.0.4</version>
</dependency>
Show the report
Call new JHades().overlappingJarsReport(); in your main method, it will output to stdout.
Sample Output:
file:/Users/justin/.m2/repository/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar overlaps with
file:/Users/justin/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.0/javax.ws.rs-api-2.0.jar - total overlapping classes: 55 - same classloader ! This is an ERROR!
Remove one of overlap maven dependency in your pom.
Also you can use another approach like maven's dependency exclusions.
Source: Blog post on jhades
Hope this will help someone :)
Just got this working on JBoss EAP 6.1.1 - Jersey 2.3.1.
The usual things don't seem to work/are not enough on their own:
disabling the jaxrs-subsystem in standalone.xml/domain.xml
or, excluding the jax-rs modules in jboss-deployment-structure.xml
Additionaly you need to disable the loading of the jax-rs 1.1 API completely by modifying module.xml in
jboss-eap-6.1/modules/system/layers/base/javax/ws/rs/api/main/module.xml like this:
<module xmlns="urn:jboss:module:1.1" name="javax.ws.rs.api">
<resources>
<!-- Disable the next line -->
<!-- resource-root path="jboss-jaxrs-api_1.1_spec-1.0.1.Final-redhat-2.jar"/ -->
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jaxrs" services="export"/>
</dependencies>
</module>
Please note that this will disable the jax-rs implementation of JBoss (RestEasy) for all other applications as well (as does disabling the jaxrs subsystem in standalone/domain.xml).
This is a Jersey version conflict problem. I had the same problem. Here is how it is resolved:
See your package dependencies "mvn dependency:tree"
If there is a library dependency that depends on an old Jersey version, you could add an exclusions section in the dependency tag for that library in pom.xml
Using mvn dependency:tree (thanks for suggestion above) I was able to identify that the culprit (in my case) was: javax.ws.rs:jsr311-api:1.1
Removing this dependency solved my problem.

Categories