HTML doctype getting removed in JSF - jsf

My <!DOCTYPE html> declaration is getting removed from my JSF pages, and it's messing things up.
This same question has been asked a bunch of times:
HTML doctype declaration in JSF
DocType is not showing in the rendered output from JSF
JSF template: rendered page missing DOCTYPE
Trouble is, this Jira entry says the bug has been fixed. Apparently not. I'm using the most recent version:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.0-m07</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.0-m07</version>
</dependency>
For reference, here are my pages:
test_layout.xhtml:
<!DOCTYPE html>
<html xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:insert name="content"/>
</body>
</html>
test_content.xhtml:
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
template="test_layout.xhtml">
<ui:define name="content">
bunch 'o content
</ui:define>
</ui:composition>
Anybody got a workaround?

I upgraded to 2.2.0-m08 and the problem went away.

Related

JSF Primefaces 10: How to set p:datePicker's maxdate attribute to tens years from now, dynamically?

Am using Java 1.8, Primefaces 10.0.0 on Tomcat 8.5.55... Am fairly new to JSF UI programming. Have a custom date JSTL tag where I need to dynamically set the maxdate to be 10 years from now when using the calendar widget (p:datePicker) - this is generic so that's why I can't place it inside a custom bean. It needs to be set declaratively inside my input.xhtml file (see below):
pom.xml:
<properties>
<primefaces-version>10.0.0</primefaces-version>
<primefaces-extension-version>10.0.1</primefaces-extension-version>
</properties>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>${primefaces-version}</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>${primefaces-extension-version}</version>
</dependency>
input.xhtml (custom taglib located inside ..src/main/webapp/WEB-INF/tags/input.xhtml):
<ui:composition xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:d="http://www.mycompany.com/jsf/facelets"
xmlns:ui="http://java.sun.com/jsf/facelets">
<p:datePicker id="#{id}" value="#{bean[property]}" rendered="#{rendered}"
disabled="#{disabled}"
pattern="MM/dd/yyyy"
required="#{required}" requiredMessage="#{requiredMessage}" timeZone="#{timeZone}"
mindate="1/1/2011"
maxdate="#{LocalDate.now().plusYears(10)}"
mask="99/99/9999">
<c:if test="#{not empty event}">
<p:ajax event="#{event}" update="#{update}"/>
<p:ajax event="dateSelect" update="#{update}" oncomplete="#{oncomplete}"/>
</c:if>
</p:datePicker>
</ui:composition>
My mindate works - I can not go before 1/1/2011 in my calendar widget.
But I can go well past 2031 inside my calendar widget.
How can I set the maxdate to 10 years from now only in the input.xhtml file?

Primefaces ContentFlow does not render the full content

I'm trying to use the Primefaces JSF component called contentFlow, which is demonstrated here: http://www.primefaces.org/showcase/ui/multimedia/contentFlow.xhtml
I added two images to the backing bean. They both can be displayed without using contentFlow, so they are available and at the right place. The problem is, that the contentFlow only shows the currently selected image. The expected behaviour is, that it displays all other images, too.
I googled alot and also found the documentation of Primefaces components to verify my XHTML. I also changed the JSF log level to see all debug messages, but JSF keeps telling me that everything is fine.
I've done nothing more than the showcase says, except for the configuration of the project. Here is a summary of my setting:
I'm using Apache Tomcat 8.0.39 on Windows x64
Firefox 50.0.2 and Chrome Version 55.0.2883.75 m (64-bit) are showing the same results (only the currently selected image is visible)
I'm using Java 8
And these are the project's dependencies
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0.RC4</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
This is my backing bean:
package de.schuettec.jsfquestion.contentFlow;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
#ManagedBean
public class Images {
private List<String> images;
#PostConstruct
public void init() {
images = new ArrayList<String>();
images.add("img-01.png");
images.add("img-02.png");
}
public List<String> getImages() {
return images;
}
}
This is my XHTML page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:contentFlow value="#{images.images}" var="image">
<p:graphicImage name="/images/#{image}" styleClass="content" />
<div class="caption">#{image}</div>
</p:contentFlow>
</h:form>
</h:body>
</html>
I've created a minimal reproducing example, which is available via GitHub here https://github.com/schuettec/jsf-question. This is a full Maven project that reproduces this issue.
I would appreciate if someone of the JSF/Primefaces experts can have a look at this issue. I like JSF and the Primefaces components and really want to understand whats wrong here.
Thank you in advance!
Your code is right. I think it's a bug or a feature.
add 2 pics -> shows 1 pic
add 3 pcis -> shows 3 pics
add 4 pics -> shows 3 pics
add 5 pics -> shows 5 pics
And you can use the final version from primefaces.
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0</version>
</dependency>

Get the content of an HTML input in a bean without using passthrough atts

I'm using a javascript that transforms a textArea in an editor (primefaces editor wasn't costumizable enough).
So I've this code:
<textarea name="editor1" id="editor1" rows="10" cols="80" >
</textarea>
<script>
CKEDITOR.replace( 'editor1');
</script>
I would like to get the content of the text area in a managed bean.
I didn't manage to make it work with the jsf tags for inputTextarea.
EDIT: I guess it's not working because the id isn't the same when using
<h:inputTextarea id="editor1"/>
this will result in an id like :
j_tid53:editor1
I also tried this :
xmlns:jsf="http://xmlns.jcp.org/jsf"
...
jsf:value="#{bean.property}"
but it will be null
Edit:
my xhtml namespace:
<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">
faces-config:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
and when the server start in the console:
Initializing Mojarra 2.2.9 (-SNAPSHOT 20141218-0939 https://svn.java.net/svn/mojarra~svn/tags/2.2.9#14083) for context
So how can I get the content of my textArea ?
The script wasn't working because the id was wrong. I just had to give the form an id as such:
<h:form id="form">
<p:inputTextarea value="#{newThread.title}" cols="98" rows="1">
<f:passThroughAttribute name="placeholder" value="#{miscellaneous.Title}"/>
</p:inputTextarea>
<p:inputTextarea id="sup"></p:inputTextarea>
<script>
CKEDITOR.replace( 'form:sup');
</script>
<p:commandButton value="#{miscellaneous.Submit}" action="#{newThread.sendNewThread}">
</p:commandButton>
</h:form>
The problem is that I didn't know how to get the value. So I switched to the primeface extension.
Those are the dependencies needed:
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>resources-ckeditor</artifactId>
<version>3.1.0</version>
</dependency>
then the namespace in the xhtml file:
xmlns:pe="http://primefaces.org/ui/extensions"
and here is a link that explains step by step.
If you are not using primefaces you can make it work by following the comment of w vd L

JSF-ViewScope bean reinstantiated in every request

I have seen this bug described in many places but always the causes are different. Post like this one states that the problem of re-instantiation only occurs, when you include a tag handler library on your page. However, I have an empty project with a page like the following
<?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:f="http://java.sun.com/jsf/core">
<head>
<title></title>
</head>
<body >
<h:form>
<f:view >
<h:commandButton id="otxMainPanelTextBt" value="click"
action="#{otherController.doSome}"/>
</f:view>
</h:form>
</body>
</html>
With the backing bean like this
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean(name = "otherController")
#ViewScoped
public class Other implements Serializable {
private static final long serialVersionUID = -6493758917750576706L;
public String doSome() {
System.out.println(this);
return "";
}
}
And the following dependences
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.0.2</version>
</dependency>
and every time I click on the button a different object is created. Apparently this page is as simple as possible and I have not triggered any of the possible causes of the bugs, so It always happen or am I missing something?
I tested changing the dependencies to 2.2.0 and it works as expected but unfortunately due to project restrictions, I need to keep the version 2.0.2 of JSF.
Any help would be highly appreciated.
Thanks!!
Actually, I have found that the instance remain the same. The problems was that when clicking the button I always saw different hashCodes printed in the toString of the method like this.
constructing the instance
de.controller.Other#118ea91
de.controller.Other#1e8f930
de.controller.Other#1a38f3c
and this led me to think there were different instances.
Although is the same instance, i believe this behaviour is incorrect because the hashCode of an object is not supposed to change during its lifetime.

Glassfish not display JSF components

On my index.xhtml I have Java Server Face components which are displayed correctly and use a managed bean. But if I link to any other page or even a page with the EXACT same code those pages will not display these components, only the text.
Suppose index.xhtml is like this and displays correctly:
<?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:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:inputText value="#{user.name}"/>
<h:commandButton action="#{user.submit}" value="Submit" />
</h:form>
</h:body>
</html>
If I add a link to any other page (even one with the same code) JSF components are not displayed for them. Is this because the other pages perhaps can't 'see' the managed bean? Or something else?
Thanks for your help.
It looks like the pages which you want to call are not processed by the Faces Servlet.
In the web.xml of your application you define the url-pattern of server requests that will be processed by this servlet. By default this is often /faces/*. This means that the link that you call must contain this pattern in order to be processed by the Faces Servlet.
If you create your project with Netbeans, the mapping usually looks like the following:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
So try to use links that contain this url pattern or use relative links instead.
If you use h:link instead of a:href, the url-pattern is automatically prepended:
<h:link value="My other page" outcome="otherpage" />
will be rendered as:
My other page

Resources