Since I have upgraded to WildFly 8 I have problems with my JSF custom components: the first time the custom component is loaded, an error is throw:
IllegalStateException: Component ID formDlgPesqPccs:pesqOcupacaoCC:pesquisaOcupacaoDlg:pesquisaOcupacaoDlgbuttonpesquisaOcupacao has already been found in the view.
After first time, the component is rendered normally. I'm using Mojarra 2.2.10.
The composite component (pesquisarOcupacao.xhtml):
<composite:interface>
<composite:attribute name="beanReference"
type="seb.sarh.pccs.PesquisarOcupacaoBean" required="true"/>
<composite:attribute name="updatePesquisa" required="true"/>
<composite:attribute name="pesquisaScrollHeight" required="true"/>
<composite:attribute name="estilo" required="true"/>
<composite:attribute name="estiloPesquisa" required="true"/>
<composite:attribute name="edicao" default="true"/>
</composite:interface>
<composite:implementation>
<div id="divWraperPesqOcupacao" style="#{cc.attrs.estilo}">
<p:panel styleClass="panelgrid">
<h:panelGrid columns="2">
<p:fieldset legend="Tipo da Pesquisa">
<p:selectOneRadio value="#{cc.attrs.beanReference.tipo}"
requiredMessage="Selecione o tipo de pesquisa.">
<f:selectItem itemValue="1" itemLabel="Cargo " />
<f:selectItem itemValue="2" itemLabel="Função" />
</p:selectOneRadio>
</p:fieldset>
<p:fieldset legend="Criterio da Pesquisa">
<p:selectOneRadio value="#{cc.attrs.beanReference.criterio}"
requiredMessage="Selecione o criterio de pesquisa.">
<f:selectItem itemValue="2" itemLabel="Código" />
<f:selectItem itemValue="1" itemLabel="Descrição" />
</p:selectOneRadio>
</p:fieldset>
</h:panelGrid>
</p:panel>
<div id="divPesquisa" class="reference" style="clear: left">
<p:fieldset legend="Texto a pesquisar" style="#{cc.attrs.estiloPesquisa} ">
<p:commandButton id="#{cc.id}buttonpesquisaOcupacao"
style="float: right"
update="#{cc.attrs.updatePesquisa}"
actionListener="#{cc.attrs.beanReference.pesquisarOcupacao}"
icon="ui-icon-search" process="#form" />
<div style="overflow: hidden; padding: 2px 15px 0 0; margin-right: 4px">
<p:inputMask id="cod" value="#{cc.attrs.beanReference.texto}"
mask="?99999" rendered="#{cc.attrs.beanReference.criterio == 2}"
style="width: 100%" />
<p:inputText id="desc" value="#{cc.attrs.beanReference.texto}"
rendered="#{cc.attrs.beanReference.criterio == 1}"
style="width: 100%" />
</div>
</p:fieldset>
</div>
<div id="divExpandPesqEstrutura" class="expand">
<p:fieldset id="#{cc.id}fldsetOcupacoesPesquisadas"
styleClass="expand-content" legend="Resultados da Pesquisa"
style="#{cc.attrs.estiloPesquisa}">
<p:dataTable id="datatable" styleClass="corner" emptyMessage=""
selectionMode="single" selection="#{cc.attrs.beanReference.selecaoPesquisa}"
value="#{cc.attrs.beanReference.listOcupacoes}" var="cargo"
scrollable="true" rowKey="#{cargo.hashCode()}"
scrollHeight="#{cc.attrs.pesquisaScrollHeight}">
<p:ajax event="rowSelect"
listener="#{cc.attrs.beanReference.onRowSelect}" />
<p:column width="10%">
<f:facet name="header">
<h:outputText value="Código" />
</f:facet>
<h:outputText value="#{cargo.codigo}" />
</p:column>
<p:column width="68%">
<f:facet name="header">
<h:outputText value="Descrição" />
</f:facet>
<h:outputText value="#{cargo.descricao}" />
</p:column>
<c:if test="#{cc.attrs.edicao}">
<p:column width="10%" style="text-align:center">
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<p:commandButton id="editarOcupacaoButton" icon="ui-icon-pencil"
style="width: 20px; height: 20px" />
<p:tooltip for="editarOcupacaoButton"
value="Editar Cargo/Função" />
</p:column>
<p:column width="10%" style="text-align:center">
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<p:commandButton id="excluirOcupacaoButton" icon="ui-icon-trash"
style="width: 20px; height: 20px" />
<p:tooltip for="excluirOcupacaoButton"
value="Excluir Cargo/Função" />
</p:column>
</c:if>
</p:dataTable>
</p:fieldset>
</div>
</div>
</composite:implementation>
The web.xml:
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>SARH</display-name>
<error-page>
<error-code>404</error-code>
<location>/xhtml/error.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/xhtml/error.xhtml</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/xhtml/error.xhtml</location>
</error-page>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>redmond</param-value>
</context-param>
<context-param>
<param-name>javax.faces.SERIALIZE_SERVER_STATE</param-name>
<param-value>true</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>/xhtml/selecionar_empresa.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<display-name>RelatorioServlet</display-name>
<servlet-name>RelatorioServlet</servlet-name>
<servlet-class>seb.sarh.util.RelatorioServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RelatorioServlet</servlet-name>
<url-pattern>/RelatorioServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
Related
I'm trying to make a project with primefaces but i can't make it work , the tags are not being rendered. Here is what i've got:
Problem :
welcome.xhtml :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title>Ejemplo</title>
<link rel="stylesheet" type="text/css" href="css/styles.css"/>
</h:head>
<h:body>
<center>
<h:form>
<div id="header">
<h1><h:outputLabel value="#{login.msg}"/></h1>
</div>
<div id="body">
<p:growl id="messages"/>
<p:menubar>
<p:submenu label="File" icon="ui-icon-document">
<p:submenu label="New" icon="ui-icon-contact">
<p:menuitem value="Project" url="#" />
<p:menuitem value="Other" url="#" />
</p:submenu>
<p:menuitem value="Open" url="#" />
<p:separator />
<p:menuitem value="Quit" url="#" />
</p:submenu>
<p:submenu label="Edit" icon="ui-icon-pencil">
<p:menuitem value="Undo" url="#" icon="ui-icon-arrowreturnthick-1-w" />
<p:menuitem value="Redo" url="#" icon="ui-icon-arrowreturnthick-1-e" />
</p:submenu>
<p:submenu label="Help" icon="ui-icon-help">
<p:menuitem value="Contents" url="#" />
<p:submenu label="Search" icon="ui-icon-search">
<p:submenu label="Text">
<p:menuitem value="Workspace" url="#" />
</p:submenu>
<p:menuitem value="File" url="#" />
</p:submenu>
</p:submenu>
<p:submenu label="Actions" icon="ui-icon-gear">
<p:submenu label="Ajax" icon="ui-icon-refresh">
<p:menuitem value="Save" actionListener="#{menuView.save}" icon="ui-icon-disk" update="messages"/>
<p:menuitem value="Update" actionListener="#{menuView.update}" icon="ui-icon-arrowrefresh-1-w" update="messages"/>
</p:submenu>
<p:submenu label="Non-Ajax" icon="ui-icon-newwin">
<p:menuitem value="Delete" actionListener="#{menuView.delete}" icon="ui-icon-close" update="messages" ajax="false"/>
</p:submenu>
</p:submenu>
<p:menuitem value="Quit" url="http://www.primefaces.org" icon="ui-icon-close" />
<f:facet name="options">
<p:inputText style="margin-right:10px" placeholder="Search"/>
<p:commandButton type="button" value="Logout" icon="ui-icon-extlink" />
</f:facet>
</p:menubar>
</div>
</h:form>
</center>
</h:body>
web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<display-name>JavaServerFaces</display-name>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
This is the warning that comes up : - Warning: The page /welcome.xhtml declares namespace http://primefaces.prime.org/ui and uses the tag p:commandButton , but no TagLibrary associated to namespace. Please check the namespace name and if it is correct, it is probably that your library .taglib.xml cannot be found on the current classpath, or if you are referencing a composite component library check your library folder match with the namespace and can be located by the installed ResourceHandler.!
The libs are properly imported. I'm using eclipse with Tomcat.
Just to close the post , #Balus C helped the problem was
xmlns:p="http://primefaces.prime.org/ui"
changed it to
xmlns:p="primefaces.org/ui";
In my jsf page there are search and insert functions.
However after I start insert process, I can start search process.
So I have to do firstly insert to search person otherwise search button doesn't work how can I solve this problem ?
public void search() {
getOsList(getUsername(), getSurname(), getTcidno());
System.out.println("osList : " + osList);
}
public List<KisiBean> getOsList(String ad, String soyad, String tckimlikno) {
Session session = null;
Transaction tx = null;
List<KisiBean> osList = new ArrayList<KisiBean>();
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
String sql = "select upper(k.ad),upper(k.soyad),k.temelkimlik.mernisno "
+ "from com.revir.domain.Kisi as k "
+ "where k.kisituru.kisiturid in (1,9,29,30)";
if (!ad.isEmpty()) {
sql = sql + " AND ((upper(ltrim(rtrim(k.ad))) like upper(:ad))"
+ " OR "
+ " (lower(ltrim(rtrim(k.ad))) like lower(:ad)))";
}
if (!soyad.isEmpty()) {
sql = sql
+ " AND ((upper(ltrim(rtrim(k.soyad))) like upper(:soyad))"
+ " OR "
+ " (lower(ltrim(rtrim(k.soyad))) like lower(:soyad)))";
}
if (!tckimlikno.isEmpty()) {
sql = sql
+ " AND upper(k.temelkimlik.mernisno) like upper(:mernisno) ";
}
sql = sql
+ " order by NLSSORT(lower(k.soyad),'nls_sort=xturkish') asc,"
+ "NLSSORT(lower(k.ad),'nls_sort=xturkish') asc ";
try {
Query queryObject = session.createQuery(sql).setMaxResults(100);
if (!ad.isEmpty())
queryObject.setString("ad", "%" + ad.trim() + "%");
if (!soyad.isEmpty())
queryObject.setString("soyad", "%" + soyad.trim() + "%");
if (!tckimlikno.isEmpty())
queryObject
.setString("mernisno", "%" + tckimlikno.trim() + "%");
System.out.println("SQL : " + sql);
List list = queryObject.list();
Object[] o;
for (Iterator it = list.iterator(); it.hasNext();) {
o = (Object[]) it.next();
KisiBean osBean = new KisiBean();
if (o[0] != null) {
osBean.setAd((String) o[0].toString().trim());
System.out.println("Ad : "
+ (String) o[0].toString().trim());
}
if (o[1] != null) {
osBean.setSoyad((String) o[1].toString().trim());
System.out.println("Soyad : "
+ (String) o[1].toString().trim());
}
if (o[2] != null) {
osBean.setMernisno((String) o[2].toString());
System.out.println("Kimlik No : "
+ (String) o[2].toString());
}
System.out
.println("----------------------------------------------");
osList.add(osBean);
}
tx.commit();
log.debug("KisiInfoProcess - getStudentList - End DAO and Process Work");
} catch (Exception e) {
log.error("KisiInfoProcess - getStudentList - Error");
tx.rollback();
throw e;
} finally {
if (session != null && session.isOpen()) {
session.close();
}
}
log.debug("KisiInfoProcess - getStudentList - End / Returning");
return osList;
}
public void savePerson() {
saveOsList(getPusername(), getPsurname(), getPtcidno(),
getPdogumtarihi(), getPcinsiyet());
System.out.println("saveperson" + " - " + getPusername() + " - "
+ getPsurname() + " - " + getPtcidno() + " - "
+ getPdogumtarihi() + " - " + getPcinsiyet());
}
public void saveOsList(String ad, String soyad, String tcno,
Date dogumtarihi, char cinsiyet) {
System.out.println("saveOSList");
Session session = null;
Transaction tx = null;
try {
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
TrvrKisi tkisi = new TrvrKisi();
TrvrKisiDAO tkisiDAO = new TrvrKisiDAO();
tkisi.setAd(ad);
tkisi.setSoyad(soyad);
tkisi.setTcno(tcno);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String dateInString = "07/06/2013";
dogumtarihi = formatter.parse(dateInString);
System.out.println(dogumtarihi);
System.out.println(formatter.format(dogumtarihi));
tkisi.setDogumtarihi(dogumtarihi);
tkisi.setCinsiyet(cinsiyet);
tkisiDAO.save(tkisi);
tx.commit();
log.debug("KisiInfoProcess - getStudentList - End DAO and Process Work");
} catch (Exception e) {
log.error("KisiInfoProcess - getStudentList - Error");
tx.rollback();
} finally {
if (session != null && session.isOpen()) {
session.close();
}
}
log.debug("KisiInfoProcess - getStudentList - End / Returning");
}
layout.xhtml :
<?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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:form id="form">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="EmulateIE8" />
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
<title>REVİR HASTA KAYIT</title>
</f:facet>
<link type="text/css" rel="stylesheet"
href="#{request.contextPath}/css/default.css" />
<style type="text/css">
.ui-layout-north {
z-index: 20 !important;
overflow: visible !important;;
}
.ui-layout-north .ui-layout-unit-content {
overflow: visible !important;
}
</style>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north">
<p:layout>
<p:layoutUnit position="north">
<h:outputText value="Middle top unit content." />
</p:layoutUnit>
<p:layoutUnit position="south">
<p:layout>
<p:layoutUnit position="north">
<p:menubar>
<p:submenu label="Duyurular" outcome="duyurular.xhtml"></p:submenu>
<p:submenu label="Hasta Arama" url="#"></p:submenu>
</p:menubar>
</p:layoutUnit>
<p:layoutUnit position="center" size="200">
<ui:include src="/search.xhtml" />
</p:layoutUnit>
</p:layout>
</p:layoutUnit>
<p:layoutUnit position="west">
<h:outputText value="Middle left unit content." />
</p:layoutUnit>
<p:layoutUnit position="east">
<h:panelGrid columns="1">
<h:outputText value="Hoşgeldin #{loginBean.username}"></h:outputText>
<h:outputLink
value="#{request.contextPath}/j_spring_security_logout">Oturumu Kapat</h:outputLink>
</h:panelGrid>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:outputText value="REVİR HASTA OTOMASYON SİSTEMİ" />
</p:layoutUnit>
</p:layout>
</p:layoutUnit>
<p:layoutUnit position="south" size="50">
<h:outputText value="South unit content." />
</p:layoutUnit>
<p:layoutUnit position="west" size="900">
<ui:include src="/searchresults.xhtml" />
</p:layoutUnit>
<p:layoutUnit position="center">
</p:layoutUnit>
</p:layout>
</h:body>
<p:dialog id="modalDialog" header="Yeni Hasta Kayıt" widgetVar="dlg2"
modal="true" height="300" width="300">
<p:panel id="panel">
<p:messages id="messages" />
<h:panelGrid columns="2" columnClasses="column1">
<h:outputText value="Ad: *" />
<p:inputText id="username" value="#{userOS.pusername}"
required="true" label="Ad">
<f:validateLength minimum="2" />
</p:inputText>
<br />
<p:message for="username" />
<h:outputText value="Soyad: *" />
<p:inputText id="surname" value="#{userOS.psurname}"
required="true" label="Soyad" />
<br />
<p:message for="surname" />
<h:outputText value="TC Kimlik: *" />
<p:inputText id="tcidno2" value="#{userOS.ptcidno}" required="true"
label="TC Kimlik" />
<br />
<p:message for="tcidno" />
<h:outputText value="Doğum Tarihi:" />
<p:inputMask value="#{userOS.pdogumtarihi}" mask="99/99/9999" />
<h:outputText value="Cinsiyet: " />
<p:selectOneRadio id="options" value="#{userOS.pcinsiyet}">
<f:selectItem itemLabel="Erkek" itemValue="E" />
<f:selectItem itemLabel="Kadın" itemValue="K" />
<br></br>
</p:selectOneRadio>
</h:panelGrid>
</p:panel>
<p:commandButton value="Ekle" id="ajax"
actionListener="#{userOS.savePerson}" />
</p:dialog>
</h:form>
</f:view>
</html>
search.xhtml :
<?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"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:composition>
<p:panel header="Arama" style="margin-bottom:10px;">
<h:panelGrid columns="2">
<h:outputText value="Ad : "></h:outputText>
<p:inputText id="ad" value="#{userOS.username}" label="Keyword" />
<h:outputText value="Soyad : "></h:outputText>
<p:inputText id="soyad" value="#{userOS.surname}" label="Keyword" />
<h:outputText value="TC Kimlik no : "></h:outputText>
<p:inputText id="tcidno" value="#{userOS.tcidno}" label="Keyword" />
<p:watermark for="ad" value="Ad giriniz" />
<p:watermark for="soyad" value="Soyad giriniz" />
<p:watermark for="tcidno" value="TC Kimlik no giriniz" />
<p:commandButton actionListener="#{userOS.search}" value="Arama"
update=":form:users" />
</h:panelGrid>
</p:panel>
</ui:composition>
</body>
</html>
web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Revir Kayit</display-name>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/css/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/dispatcher-servlet.xml,
/WEB-INF/applicationContext.xml,
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>casablanca</param-value>
</context-param>
<welcome-file-list>
<welcome-file>login.jsf</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<resource-ref>
<description>REVIR DB Connection</description>
<res-ref-name>jdbc/REVIR</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
JSF 2.2
Richfaces 4.3.3
Java 7
Netbeans 7.3.1
Im trying to use a richfaces popup calender, but it does not popup, i can see the input field aswell as the calender icon but when i click it nothing happens. when setting popup to false i can see the whole calender.
Page examples:
<?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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:composition template="/template.xhtml" >
<ui:define name="title">
<h:outputText value="#{bundle.CreateTimeLoggingDetailTitle}"></h:outputText>
</ui:define>
<ui:define name="pagetitle">
<h:outputText value="Client Details" styleClass="auto-style3"></h:outputText>
</ui:define>
<ui:define name="heads">
<h:link outcome="/login/admin.xhtml" value="#{bundle.CreateTimeLoggingDetailIndexLink}"/>
</ui:define>
<ui:define name="body">
<!-- CLIENT INFORMATION-->
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:form>
<h:panelGrid columns="4">
<h:outputText value="#{bundle.ViewTimeLoggingLabel_employeesEmployeeNo}"/>
<h:outputText value="#{employeesController.getEmployees(timeLoggingController.selected.employeesEmployeeNo).name} #{employeesController.getEmployees(timeLoggingController.selected.employeesEmployeeNo).surname}" title="#{bundle.ViewTimeLoggingTitle_employeesEmployeeNo}"/>
<h:outputText value="#{bundle.ViewTimeLoggingLabel_customersId}"/>
<h:outputText value="#{customersController.getCustomers(timeLoggingController.selected.customersId).name}" title="#{bundle.ViewTimeLoggingTitle_customersId}"/>
<h:outputText value="#{bundle.ViewTimeLoggingLabel_projectsId}"/>
<h:outputText value="#{projectsController.getProjects(timeLoggingController.selected.projectsId).description}" title="#{bundle.ViewTimeLoggingTitle_projectsId}"/>
<h:outputText value="#{bundle.ViewTimeLoggingLabel_tasksId}"/>
<h:outputText value="#{tasksController.getTasks(timeLoggingController.selected.tasksId).description}" title="#{bundle.ViewTimeLoggingTitle_tasksId}"/>
<br/>
</h:panelGrid>
<h:outputText value="Log Time" styleClass="auto-style3" />
<!-- LOG TIME PANEL-->
<br/>
<br/>
<table border="1" style="text-align: center" class="jsfcrud_odd_row,jsfcrud_even_row, jsfcrud_list_form">
<tr>
<th><h:outputLabel value="#{bundle.CreateTimeLoggingDetailLabel_date}" for="date" /></th>
<th><h:outputLabel value="#{bundle.CreateTimeLoggingDetailLabel_description}" for="description" /></th>
<th><h:outputLabel value="#{bundle.CreateTimeLoggingDetailLabel_normalHours}" for="normalHours" /></th>
<th><h:outputLabel value="#{bundle.CreateTimeLoggingDetailLabel_overtimeHours}" for="overtimeHours" /></th>
<th><h:outputLabel value="#{bundle.CreateTimeLoggingDetailLabel_doubleTimeHours}" for="doubleTimeHours" /></th>
<th><h:outputLabel value="#{bundle.CreateTimeLoggingDetailLabel_billTypesId}" for="billTypesId" /></th>
</tr>
<tr>
<td>
<rich:calendar value="#{timeLoggingDetailController.selected.date}" locale="Locale.US" popup="true" datePattern="MM/dd/yyyy" style="width:200px"/>
</td>
<td><h:inputText id="description" value="#{timeLoggingDetailController.selected.description}" title="#{bundle.CreateTimeLoggingDetailTitle_description}" size="18" /></td>
<td><h:inputText id="normalHours" value="#{timeLoggingDetailController.selected.normalHours}" title="#{bundle.CreateTimeLoggingDetailTitle_normalHours}" size="10"/></td>
<td><h:inputText id="overtimeHours" value="#{timeLoggingDetailController.selected.overtimeHours}" title="#{bundle.CreateTimeLoggingDetailTitle_overtimeHours}" size="10" /></td>
<td><h:inputText id="doubleTimeHours" value="#{timeLoggingDetailController.selected.doubleTimeHours}" title="#{bundle.CreateTimeLoggingDetailTitle_doubleTimeHours}" size="16" /></td>
<td><h:selectOneMenu id="billTypesId" value="#{timeLoggingDetailController.selected.billTypesId}">
<f:selectItems value="#{billTypesController.items}" var="i" itemLabel="#{i.description}" itemValue="#{i.id}" />
</h:selectOneMenu></td>
<td> <h:commandLink onclick="#{timeLoggingDetailController.selected.timeLoggingId=timeLoggingController.selected.id}" action="#{timeLoggingDetailController.create}" value="#{bundle.CreateTimeLoggingDetailSaveLink}" styleClass="linkbutton"/></td>
</tr>
</table>
<br/>
</h:form>
where i use the calender:
<rich:calendar value="#{timeLoggingDetailController.selected.date}" locale="Locale.US" popup="true" datePattern="MM/dd/yyyy" style="width:200px"/>
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>plain</param-value>
</context-param>
</web-app>
I also have <h:head></h:head> in my template file
I develop a java application with jsf and eclispeLink with netbeans 7.3.1 but my character don't save correctly. I look at request variable and saw that my character are not correctly show in the request object.
My Jsf sample :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.CreateTblAccessTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="#{bundle.CreateTblAccessLabel_id}" for="id" />
<h:inputText id="id" value="#{tblAccessController.selected.id}" title="#{bundle.CreateTblAccessTitle_id}" required="true" requiredMessage="#{bundle.CreateTblAccessRequiredMessage_id}"/>
<h:outputLabel value="#{bundle.CreateTblAccessLabel_userName}" for="userName" />
<h:inputText id="userName" value="#{tblAccessController.selected.userName}" title="#{bundle.CreateTblAccessTitle_userName}" />
<h:outputLabel value="#{bundle.CreateTblAccessLabel_userTypeId}" for="userTypeId" />
<h:selectOneMenu id="userTypeId" value="#{tblAccessController.selected.userTypeId}" title="#{bundle.CreateTblAccessTitle_userTypeId}" >
<f:selectItems value="#{tblUserTypeController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:outputLabel value="#{bundle.CreateTblAccessLabel_formId}" for="formId" />
<h:selectOneMenu id="formId" value="#{tblAccessController.selected.formId}" title="#{bundle.CreateTblAccessTitle_formId}" required="true" requiredMessage="#{bundle.CreateTblAccessRequiredMessage_formId}">
<f:selectItems value="#{tblFormController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:outputLabel value="#{bundle.CreateTblAccessLabel_activitesId}" for="activitesId" />
<h:selectOneMenu id="activitesId" value="#{tblAccessController.selected.activitesId}" title="#{bundle.CreateTblAccessTitle_activitesId}" required="true" requiredMessage="#{bundle.CreateTblAccessRequiredMessage_activitesId}">
<f:selectItems value="#{tblAccessActivitiesController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
</h:panelGrid>
<br />
<h:commandLink action="#{tblAccessController.create}" value="#{bundle.CreateTblAccessSaveLink}" />
<br />
<br />
<h:commandLink action="#{tblAccessController.prepareList}" value="#{bundle.CreateTblAccessShowAllLink}" immediate="true"/>
<br />
<br />
<h:link outcome="/index" value="#{bundle.CreateTblAccessIndexLink}"/>
</h:form>
</ui:define>
</ui:composition>
</html>
MY Filter to change encoding :
public class EncodingFilter implements Filter{
private String encoding;
#Override
public void init(FilterConfig filterConfig) throws ServletException {
encoding = filterConfig.getInitParameter("requestEncoding");
if( encoding==null ) encoding="UTF-8";
}
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpRequest.setCharacterEncoding(encoding);
httpResponse.setCharacterEncoding(encoding);
response.setContentType("text/html;charset=utf-8");
chain.doFilter(httpRequest, httpResponse);
}
#Override
public void destroy() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
My Template.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ui:insert name="title">Default Title</ui:insert></title>
<h:outputStylesheet name="css/jsfcrud.css"/>
</h:head>
<h:body>
<h1>
<ui:insert name="title">Default Title</ui:insert>
</h1>
<p>
<ui:insert name="body">Default Body</ui:insert>
</p>
</h:body>
</html>
My web.xml
<web-app version="3.1" 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-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>business.EncodingFilter</filter-class>
<init-param>
<param-name>requestEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<jsp-config>
<jsp-property-group>
<url-pattern>*.xhtml</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
</web-app>
what is the problem? how could i solve it?
Every things look fine! You should check the following:
a) Check whether your Glassfish Resources has following inside :
<property name="useUnicode" value="true"/>
<property name="characterEncoding" value="UTF8"/>
b) Whether your database and the table are UTF-8 CHARCTER SET
for mysql use following code:
ALTER DATABASE dbname DEFAULT CHARACTER SET utf8;
USE dbname;
ALTER TABLE tblname CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
This question already has answers here:
How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable
(11 answers)
Closed 7 years ago.
I searched and tried every example on web that i found but my example still doesn't work.
My web.xml
...(headers)
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<listener>
<listener-class>registration.cleanRegisterDB</listener-class>
</listener>
<listener>
<listener-class>main.poolChecker</listener-class>
</listener>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<listener>
<listener-class>Utils.SessionAtributeListener.MyAtributeListener</listener-class>
</listener>
<context-param>
<param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name>
<param-value>...</param-value>
</context-param>
<context-param>
<param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name>
<param-value>...</param-value>
</context-param>
<error-page>
<error-code>404</error-code>
<location>/faces/404.xhtml</location>
</error-page>
My xhtml page:
<?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
lang="#{main_bean.authLang()}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<f:view locale="#{main_bean.locale}" encoding="ISO-8859-1" >
<h:head>
<h:outputStylesheet library="theme1" name="css/style.css"/>
<h:outputScript library="theme1" name="js/jquery.validate.js"/>
</h:head>
<h:body>
<f:event type="preRenderComponent" listener="#{postbean.loadMasterCategories()}" ></f:event>
<h:panelGroup id="layout-for-image" layout="block">
<h:link outcome="index.xhtml?faces-redirect=true">
<h:graphicImage name="theme1/images/logo.png" />
</h:link>
</h:panelGroup>
<h:panelGroup class="layout-titles" layout="block">
<h2>#{msg.postInt}</h2>
</h:panelGroup>
<h:form id="formPostpool" enctype="multipart/form-data" >
<p:growl id="growlaa" autoUpdate="true"/>
<p:confirmDialog id="confirmDialog" message="#{msg.dialogConfPostInt}"
header="#{msg.confirmDialogHeader}" severity="alert" widgetVar="confirmation" >
<h:panelGroup id="dialog-captcha-layout" layout="block" >
<h:panelGroup layout="block" style="display: inline-block; *display: inline; zoom: 1;">
<p:captcha label="Captcha" validatorMessage="#{msg.invalidCaptcha}" required="true" requiredMessage="#{msg.CaptchaNull}" language="#{main_bean.authLang()}"/>
</h:panelGroup>
</h:panelGroup>
<p:commandButton id="confirm" styleClass="h-button-search" icon="iconDialogYes" actionListener="#{captchaBean.submit}"
action="index" ajax="false" onclick="confirmation.hide();" style="background-image: url('../resources/theme1/images/icons/yes.png')" >
<f:actionListener binding="#{postbean.publicatePool()}" />
</p:commandButton>
<p:commandButton id="notconfirm" styleClass="h-button-search" icon="iconDialogNo"
ajax="false" type="button" onclick="confirmation.hide();"/>
</p:confirmDialog>
<h:panelGroup class="layout-item-details" layout="block">
<h2>#{msg.infoProd}</h2>
<h:panelGroup class="details-element" layout="block">
<h:outputLabel value="#{msg.categoryPost}" for="cat"/>
<h:panelGroup class="element-inputs" layout="block">
<p:selectOneListbox style="height: 150px;" id="cat" value="#{postbean.masterCategoria}" converter="omnifaces.SelectItemsConverter" required="true" requiredMessage="#{msg.message_radiobutton_choose}">
<f:selectItems value="#{postbean.categorias}" var="cat" itemLabel="#{cat.descricao}" itemValue="#{cat}" />
</p:selectOneListbox>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup class="details-element" layout="block">
<h:panelGroup class="element-labels" layout="block">
<h:outputLabel value="#{msg.titlePost}" for="titulo"/>
</h:panelGroup>
<h:panelGroup layout="block">
<p:inputText id="titulo" value="#{postbean.titulo}" styleClass="inputs-login" required="true" requiredMessage="#{msg.message_titulo_null}"/>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup class="details-element" layout="block">
<h:panelGroup class="element-labels" layout="block">
<h:outputLabel value="#{msg.descricaoPost}" for="desc"/>
</h:panelGroup>
<h:panelGroup layout="block">
<p:inputTextarea id="desc" value="#{postbean.descricao}" rows="6" cols="70" styleClass="inputs-textarea" required="true" requiredMessage="#{msg.message_descricao_null}"/>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup class="details-element" layout="block">
<h:panelGroup class="element-labels" layout="block">
<h:outputLabel value="#{msg.marcaPost}" for="marca"/>
</h:panelGroup>
<h:panelGroup layout="block">
<p:inputText id="marca" value="#{postbean.marca}" styleClass="inputs-login" />
</h:panelGroup>
</h:panelGroup>
<h:panelGroup class="details-element" layout="block">
<h:panelGroup class="element-labels" layout="block">
<h:outputLabel value="#{msg.modeloPost}" for="Modelo"/>
</h:panelGroup>
<h:panelGroup layout="block">
<p:inputText id="Modelo" value="#{postbean.modelo}" styleClass="inputs-login" />
</h:panelGroup>
</h:panelGroup>
<h:panelGroup class="details-element" layout="block">
<h:panelGroup class="element-labels" layout="block">
<h:outputLabel value="#{msg.quantidadePost}" for="qtdDesejada"/>
</h:panelGroup>
<h:panelGroup layout="block">
<p:inputText id="qtdDesejada" value="#{postbean.quantidadePretendida}" styleClass="inputs-login" style="width: 100px !important;" required="true" requiredMessage="#{msg.message_quantidade_null}" validatorMessage="#{msg.message_quantidade_invalid}">
<f:validateDoubleRange minimum="0.00000001" />
<!--<f:validateRegex pattern="([1-9][0-9]*\.?[0-9]*)" for="qtdDesejada" />-->
</p:inputText>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup class="details-element" layout="block">
<h:panelGroup class="element-labels" layout="block">
<h:outputLabel value="#{msg.precoTargetPost}" for="precoTarget"/>
</h:panelGroup>
<h:panelGroup layout="block">
<p:inputText id="precoTarget" value="#{postbean.preco}" styleClass="inputs-login" style="width: 100px !important;" required="true" requiredMessage="#{msg.message_precoTarget_null}" validatorMessage="#{msg.message_precoTarget_invalid}">
<f:validateDoubleRange minimum="0.00000001" />
</p:inputText>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup class="details-element" layout="block">
<h:panelGroup class="element-labels" layout="block">
<h:outputLabel value="#{msg.fotosPost}" for="foto"/>
</h:panelGroup>
<!-- <h:panelGroup layout="block" style="display: inline-block; *display: inline; zoom: 1;" id="addFotoPanel">
<h:inputFile id="idinputFile" value="#{postbean.file}" />
</h:panelGroup>-->
<p:fileUpload value="#{postbean.upfile}" auto="true" fileUploadListener="#{postbean.handleFileUpload}" widgetVar="asd" />
</h:panelGroup>
<h:panelGroup class="details-element" layout="block" style="margin-bottom: 15px; width: 250px; padding-left: 175px;">
<p:commandButton id="btn" value="#{msg.label_buttonsubmit}" styleClass="h-button-search" onclick="confirmation.show();"/>
</h:panelGroup>
</h:panelGroup>
<script type="text/javascript">
$(document).ready(function() {
$('#formPostpool').keypress(function(e) {
if (e.keyCode == 13) {
event.preventDefault();
$("#btn").click();
}
})
});
</script>
</h:form>
</h:body>
</f:view>
And the bean:
//...some imports
#ManagedBean(name = "postbean")
#ViewScoped
public class postbean implements Serializable {
//////////////////////////////////
// FACADES
/////////////////////////////////
#EJB
ProdutoFacade produtofacade = new ProdutoFacade();
#EJB
UsersFacade userfacade = new UsersFacade();
#EJB
ImageFacade imagefacade = new ImageFacade();
#EJB
categoriasFacade categoriafacade = new categoriasFacade();
#EJB
buyerPoolFacade buyerPoolFacade = new buyerPoolFacade();
#EJB
LanguageFacade languageFacade = new LanguageFacade();
#EJB
Lingua_ProdutoFacade langProFacade = new Lingua_ProdutoFacade();
#EJB
MessagesFacade messagesFacade = new MessagesFacade();
/////////////////////////////////////
// VARIAVEIS
////////////////////////////////////
//Destino onde vão ser guardadas as imagens relativas a pool
private String destination = "C:";
private List<String> urls;
private String titulo;
private String descricao;
private String marca;
private String modelo;
private float preco;
private short estado;
private int quantidadePretendida;
private List<categorias> categoria; // lista das categorias
private Timestamp dataActual;
private Users publicationUser;
private categorias masterCategoria;
private categorias option2;
private List<categorias> text;
private List<categorias> subcat2;
private boolean rend;
private boolean rend2;
private Part file;
private UploadedFile upfile;
public Part getFile() {
return file;
}
public void setFile(Part file) {
this.file = file;
}
public UploadedFile getUpfile() {
return upfile;
}
public void setUPfile(UploadedFile upfile) {
this.upfile = upfile;
}
public postbean() {...}
//...getters and setters
//...some methods
public void handleFileUpload(FileUploadEvent event) {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
FacesContext ctx = FacesContext.getCurrentInstance();
Locale l = ctx.getViewRoot().getLocale();
ResourceBundle rb = ResourceBundle.getBundle("languages.welcome", l);
FacesContext aFacesContext = FacesContext.getCurrentInstance();
ServletContext context = (ServletContext) aFacesContext.getExternalContext().getContext();
try {
copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
FacesMessage msg = new FacesMessage(rb.getString("Success"), event.getFile().getFileName() + rb.getString("wasUploaded"));
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (IOException e) {
e.printStackTrace();
}
}
public void copyFile(String fileName, InputStream in) {
String username = userfacade.findUserByIDSessao(FacesUtils.getSessionID());
OutputStream out = null;
try {
// write the inputStream to a FileOutputStream
File dir = new File(destination + username);
if (!dir.exists()) {
dir.mkdir();
}
File f = new File(dir + "\\" + fileName);
out = new FileOutputStream(f);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
urls.add(username + "//" + f.getName());
System.out.println("New file created!");
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
try {
in.close();
out.flush();
out.close();
} catch (IOException ex) {
}
}
}
//..some methods
}
Well, I changed parameters, I removed the filter from web.xml file, I changed the bean... I know I've got to have a "multipart/form-data" form, a filter in web.xml file and a fileUploader to receive the event in the bean. However nothing is triggered. I click to choose and then to upload (if parameter is not auto="true") and nothing happens. I do have commons-io-2.4, commons-fileupload-1.3, primefaces-3.5 and I use GlassFish Server 4.
Thank you!
**Note:if you are using Spring-web-flow then it will work**
My web.xml file
*Add this Configuration in web.xml file**
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet- name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
Fileupload.xhtml
<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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:fileUpload id="image"
fileUploadListener="#{loadFileForm.handleFileUpload}"
mode="advanced" dragDropSupport="true" multiple="true"
update="messages" sizeLimit="100000" fileLimit="3"
allowTypes="/(\.|\/)(xls)$/" />
<p:growl id="messages" showDetail="true" />
</html>
LoadFileBean.java
#ManagedBean(name = "loadFileForm")
public class LoadFileFormBean implements Serializable {
/**
* handleFileUpload
* #param event
*/
public void handleFileUpload(FileUploadEvent event) {
FacesMessage msg = new FacesMessage("Succesful", event.getFile()
.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
I haven't tried GlassFish but found that using PrimeFaces 4 on WebLogic we had to add this parameter to the web.xml:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
We're using this Maven dependency:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
We also had to make sure that the PrimeFaces FileUpload Filter was the first filter entry in the web.xml. But it looks like yours is already.
Also, the file upload should have a form of its own.