jsf not showing the fields just the text - jsf

My jsf page on IE won't show anything on firefox i atleast get the text. Strange thing is that there is no error so i am not sure what is wrong. I looked around for information and even added a f:view for the page but still nothing. Thank you for your time.
<!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://xmlns.jcp.org/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j" >
<f:view contentType="text/html">
<h:head>
<title>QC-Form</title>
<link href="./css/styles.css"
rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">QC Form</h1>
<br/> <br/>
<font face="comic sans MS" size="2" color="#33CCFF">
<p><b>Enter the information below: </b> </p>
</font>
<h:form>
<font face="comic sans MS" size="2">
<h:panelGroup id="initialInfo">
<b>Your initials: </b>
<h:inputText value="#{qcFormBean.techNameValue}"/><br/>
<br/>
<b>Model #: </b>
<h:selectOneMenu value="#{qcFormBean.modelValue}">
<f:selectItem itemValue="3600" itemLabel="3600" />
<f:selectItem itemValue="7200" itemLabel="7200" />
<f:selectItem itemValue="8300" itemLabel="8300" />
<f:selectItem itemValue="8400" itemLabel="8400" />
<f:selectItem itemValue="8500p" itemLabel="8500p" />
<f:selectItem itemValue="8800" itemLabel="8800" />
<f:selectItem itemValue="9000" itemLabel="9000" />
<f:selectItem itemValue="9008" itemLabel="9008" />
<f:selectItem itemValue="9200" itemLabel="9200" />
<f:selectItem itemValue="9300" itemLabel="9300" />
</h:selectOneMenu><br/>
<br/>
<b>Date : </b>
<h:outputText value="#{currentDate}"/>
<br/> <br/>
<b>Serial #: </b>
<h:inputText value="#{qcFormBean.serialValue}"/><br/>
<br/>
<b>Customer Name: </b>
<h:inputText value="#{qcFormBean.customerNameValue}"/><br/>
<br/>
<b>Special Instructions: </b>
<h:inputText value="#{qcFormBean.specialInstructionsValue}"/><br/>
</h:panelGroup>
</font>
<font face="comic sans MS" size="2" color="#33CCFF">
<p><b>QC Process</b> </p>
</font>
<font face="comic sans MS" size="2">
<h:panelGroup id="dliSerial">
<b>1.Unit Serial number has been applied: </b>
<h:selectOneMenu value="#{qcFormBean.unitSerialValue}">
<f:selectItems value="#{qcFormBean.valueQcValue}"/>
</h:selectOneMenu>
<br/>
</h:panelGroup>
<br/>
<b>2.Screen Protector has been applied: </b>
<h:panelGroup id="dliSticker">
<h:selectOneMenu value="#{qcFormBean.dliStickerValue}">
<f:selectItem itemValue="P" itemLabel="Pass or Not applicable" />
<f:selectItem itemValue="M" itemLabel="FAIL-Mechanical" />
<f:selectItem itemValue="E" itemLabel="FAIL-Electrical" />
<f:selectItem itemValue="C" itemLabel="FAIL-Cosmetic" />
<f:selectItem itemValue="S" itemLabel="FAIL-Software" />
<a4j:ajax event="change" execute="#this" render="perfbyDliSticker" limitRender="true" />
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup id="perfbyDlitcSticker">
<h:selectOneMenu value="#{qcFormBean.stickerFreq}"
rendered="#{!qcFormBean.dliStickerValue eq 'P'}">
<f:selectItem itemValue="A" itemLabel="Always" />
<f:selectItem itemValue="O" itemLabel="Often" />
<f:selectItem itemValue="S" itemLabel="Seldom" />
</h:selectOneMenu>
</h:panelGroup>
<br/>
</font>
<h:commandButton action="#{qcFormBean.submitForm()}"/>
</h:form>
</h:body>
</f:view>
</html>
Update: Right clicking on the source file on firefox does show the raw code being displayed like this:
<b>Your initials: </b>
<h:inputText value=""></h:inputText><br />
<br />
<b>Model #: </b>
<h:selectOneMenu value="">
</h:selectOneMenu><br />
<br />
and my web.xml file has the following servlet information.
<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>*.jsf</url-pattern>
</servlet-mapping>

As per the symptoms described in the comments, the <f:xxx> and <a4j:xxx> tags are properly processed by JSF, but the <h:xxx> tags not. Now, let's look at their XML namespace declarations, which is where all the processing starts:
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j" >
The xmlns.jcp.org domain as you've declared for the <h:xxx> XML namespace is introduced since JSF 2.2. The symptom of it being unprocessed thus indicates that you aren't running JSF 2.2 at all, but an older JSF 2.x version, such as 2.0 or 2.1, which don't recognize the new XML namespace domains yet.
You've basically 2 options:
Either fix the <h:xxx> XML namespace accordingly to match JSF 2.0/2.1 specification:
xmlns:h="http://java.sun.com/jsf/html"
Or, just upgrade to JSF 2.2.

That means your jsf tags are not parsed to plain html. To confirm this one see the page view source if you could see the plain jsf tags then that is the problem.
The primary reason for tags not being parsed means your request is not being handed by Faces servlet. You should have some thing like this in your web.xml
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

Related

Is it possible to pass on the children of a composite component CC as the cell contents of CC's panelGrid parent? [duplicate]

I have lot's of outputLabel and inputText pairs in panelGrids
<h:panelGrid columns="2">
<h:outputLabel value="label1" for="inputId1"/>
<h:inputText id="inputId1/>
<h:outputLabel value="label2" for="inputId2"/>
<h:inputText id="inputId2/>
...
</h:panelGrid>
I want to have some behaviour for all of them: like same validation or same size for every inputText. So I have created a composite component which just includes an outputLabel and and an inputText
<my:editField value="field1"/>
<my:editField value="field2"/>
But now when I put them in a gridPanel, they do not get aligned depending on the length of the label text. I understand why, but I don't know how to work around.
A composite component gets indeed rendered as a single component. You want to use a Facelet tag file instead. It gets rendered exactly as whatever its output renders. Here's a kickoff example assuming that you want a 3-column form with a message field in the third column.
Create tag file in /WEB-INF/tags/input.xhtml (or in /META-INF when you want to provide tags in a JAR file which is to be included in /WEB-INF/lib).
<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:ui="http://java.sun.com/jsf/facelets">
<c:set var="id" value="#{not empty id ? id : (not empty property ? property : action)}" />
<c:set var="required" value="#{not empty required and required}" />
<c:choose>
<c:when test="#{type != 'submit'}">
<h:outputLabel for="#{id}" value="#{label} #{required ? '* ' : ''}" />
</c:when>
<c:otherwise>
<h:panelGroup />
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="#{type == 'text'}">
<h:inputText id="#{id}" value="#{bean[property]}" label="#{label}" required="#{required}">
<f:ajax event="blur" render="#{id}-message" />
</h:inputText>
<h:message id="#{id}-message" for="#{id}" />
</c:when>
<c:when test="#{type == 'password'}">
<h:inputSecret id="#{id}" value="#{bean[property]}" label="#{label}" required="#{required}">
<f:ajax event="blur" render="#{id}-message" />
</h:inputSecret>
<h:message id="#{id}-message" for="#{id}" />
</c:when>
<c:when test="#{type == 'select'}">
<h:selectOneMenu id="#{id}" value="#{bean[property]}" label="#{label}" required="#{required}">
<f:selectItems value="#{options.entrySet()}" var="entry" itemValue="#{entry.key}" itemLabel="#{entry.value}" />
<f:ajax event="change" render="#{id}-message" />
</h:selectOneMenu>
<h:message id="#{id}-message" for="#{id}" />
</c:when>
<c:when test="#{type == 'submit'}">
<h:commandButton id="#{id}" value="#{label}" action="#{bean[action]}" />
<h:message id="#{id}-message" for="#{id}" />
</c:when>
<c:otherwise>
<h:panelGroup />
<h:panelGroup />
</c:otherwise>
</c:choose>
</ui:composition>
Define it in /WEB-INF/example.taglib.xml (or in /META-INF when you want to provide tags in a JAR file which is to be included in /WEB-INF/lib):
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
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-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://example.com/jsf/facelets</namespace>
<tag>
<tag-name>input</tag-name>
<source>tags/input.xhtml</source>
</tag>
</facelet-taglib>
Declare the taglib usage in /WEB-INF/web.xml (this is not needed when the tags are provided by a JAR file which is included in /WEB-INF/lib! JSF will auto-load all *.taglib.xml files from /META-INF).
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/example.taglib.xml</param-value>
</context-param>
(multiple taglib files can be separated by semicolon ;)
Finally just declare it in your main page templates.
<!DOCTYPE html>
<html lang="en"
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:my="http://example.com/jsf/facelets"
>
<h:head>
<title>Facelet tag file demo</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="3">
<my:input type="text" label="Username" bean="#{bean}" property="username" required="true" />
<my:input type="password" label="Password" bean="#{bean}" property="password" required="true" />
<my:input type="select" label="Country" bean="#{bean}" property="country" options="#{bean.countries}" />
<my:input type="submit" label="Submit" bean="#{bean}" action="submit" />
</h:panelGrid>
</h:form>
</h:body>
</html>
(the #{bean.countries} should return a Map<String, String> with country codes as keys and country names as values)
Screenshot:
Hope this helps.
There should have been a switch in panelGrid to render composite components separately. I have a solution for this. You can have separate composite components instead of clubbing them together. In each composite component you can use ui:fragments to demarcate the components you want to separately fall under different columns. Following is extract from my inputText.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:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets">
<composite:interface>
<composite:attribute name="id" />
<composite:attribute name="value" />
<composite:attribute name="label" />
<composite:attribute name="readonly" />
<composite:attribute name="disabled" />
<composite:attribute name="required" />
</composite:interface>
<composite:implementation>
<ui:fragment id="label">
<h:outputText id="#{cc.attrs.id}Label" value="#{cc.attrs.label}"
for="#{cc.attrs.id}" />
<h:outputLabel value="#{bundle['label.STAR']}"
rendered="#{cc.attrs.required}" styleClass="mandatory"
style="float:left"></h:outputLabel>
<h:outputLabel value=" " rendered="#{!cc.attrs.required}"
styleClass="mandatory"></h:outputLabel>
</ui:fragment>
<ui:fragment id="field">
<h:inputText id="#{cc.attrs.id}" value="#{cc.attrs.value}"
styleClass="#{not component.valid ? 'errorFieldHighlight medium' : 'medium'}"
disabled="#{cc.attrs.disabled}" required="#{cc.attrs.required}"
label="#{cc.attrs.label}" readonly="#{cc.attrs.readonly}">
</h:inputText>
</ui:fragment>
</composite:implementation>
</html>
Now this will not going to align in the form which is inside the panelGrid:
<h:panelGrid width="100%">
<my:inputText label="#{bundle['label.fname']}" value="#{bean.fname}" id="fname"></my:inputtext>
<my:inputText label="#{bundle['label.lname']}" value="#{bean.lname}" id="lname"></my:inputtext>
</panelGrid>
So i have extended the GroupRenderer's encodeRecursive method, to add after label and a before field:
// inside my extended renderer
protected void encodeRecursive(FacesContext context, UIComponent component)
throws IOException {
// Render our children recursively
if (component instanceof ComponentRef
&& component.getId().equals("field")) {
context.getResponseWriter().startElement("td", component);
}
super.encodeRecursive(context, component);
if (component instanceof ComponentRef
&& component.getId().equals("label")) {
context.getResponseWriter().endElement("td");
}
}

How to make a richfaces skin work?

I have a jsf project, that i made using only core and html jsf taglibs, but the components of the forms look awful, so i'm now trying to add richfaces so i can add a skin to them, the jars i've added for richfaces are:
richfaces-core-api-4.3.4.Final.jar
richfaces-core-impl-4.3.4.Final.jar
richfaces-components-api-4.3.4.Final.jar
richfaces-components-ui-4.3.4.Final.jar
cssparser-0.9.5.jar
guava-r09.jar
sac-1.3.sources,jar
and my web.xml looks like this
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<!-- Nome que indentifica o filtro pode ser qualquer um -->
<filter-name>LoginWard</filter-name>
<!-- Endereço da classe que herda de javax.servlet.Filter com o nome dos pacotes e sem .java ex: org.otkdrg.NomeDaClasse -->
<filter-class>br.com.gbcCalcados.moduloVendas.filter.LoginWard</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginWard</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>classic</param-value>
</context-param>
Still nothing happens when i run the project everthing still the same not even an exception.
Here is a page
<!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"
>
<ui:composition template="/WEB-INF/templates/gbcTemplate.xhtml"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j" >
<ui:define name="Conteudo">
<div id="funcFormDiv" align="center">
<h:form>
<h:messages/>
<h:outputLabel for="campoNome" value="Nome Completo:"/><br/>
<h:inputText id="campoNome" required="true" value="#{cadastroFuncBean.nomeCompleto}" validatorMessage="O nome completo é composto de um ou mais nomes e não pode conter numeros" requiredMessage="O nome completo é obrigatorio" >
<f:validateRegex pattern="\D* \D*"/>
</h:inputText><br/>
<h:outputLabel for="campoUsuario" value="Nome de usuário:"/><br/>
<h:inputText id="campoUsuario" required="true" value="#{cadastroFuncBean.usuario}" requiredMessage="O nome de usuario é obrigatorio" validatorMessage="O nome de usuário deve conter no minimo 6 e no maximo 15 letras">
<f:validateLength minimum="6" maximum="15"/>
</h:inputText><br/>
<h:outputLabel for="campoSenha" value="Senha:"/><br/>
<h:inputSecret id="campoSenha" required="true" value="#{cadastroFuncBean.senha}" requiredMessage="A senha é obrigatoria" validatorMessage="A senha deve conter no minimo 3 e no maximo 10 letras">
<f:validateLength minimum="3" maximum="10"/>
</h:inputSecret><br/>
<h:outputLabel for="campoNumContrato" value="Numero do contrato:"/><br/>
<h:inputText id="campoNumContrato" required="true" value="#{cadastroFuncBean.numContrato}" requiredMessage="O numero de contrato é obrigatorio" validatorMessage="Numero de contrato invalido">
<f:validateRegex pattern="^9\d{5}"/>
</h:inputText><br/><br/><br/>
<h:commandButton value="Enviar" action="#{cadastroFuncBean.cadastrar}" /><input type="reset" value="Resetar" />
<br/>
<h:button id="voltar" value="Voltar para Login" outcome="login" />
</h:form>
</div>
</ui:define>
</ui:composition>
</html>
the template:
<?xml version="1.0" encoding="UTF-8"?>
<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:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j" >
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GBC calçados</title>
<h:outputStylesheet name="arquivo.css" library="css"/>
</h:head>
<h:body>
<div id="LoginInfoTab"><span id="LoginInfo">Usuário Logado:<h:outputText value="#{sessionScope['usuario_logado'] }" /></span></div>
<div id="TopBanner"><h:graphicImage width="100%" library="images" name="TopBanner.jpg" /></div>
<div id="Menu" >
<h:form>
<h:link outcome="clientesHome">
<div class="menuItem">
<span class="menuItemTexto">Clientes</span>
</div>
</h:link>
<h:link outcome="vendasHome" >
<div class="menuItem" id="botaoVendas">
<span class="menuItemTexto">Vendas</span>
</div>
</h:link>
</h:form>
</div>
<div id="Content" align="center">
<ui:insert name ="Conteudo"/>
</div>
<div id="BottomBanner"><h:graphicImage width="100%" library="images" name="BottomBanner.jpg" /></div>
</h:body>
</html>

<rich:calendar> does not popup on click

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

jsf facelet persian character encoding error

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;

Using the same page for creating and editing in JSF 1.2 (Facelets)

Suppose I've got a XHTML page that contains a form for creating a user. There are all necessary fields and a "Save" button. Now in other place of my app there is an option to edit user informations. I would like to reuse the same page for performing this operation. But how? How can I pass user information to that page and how can I change "Save" action to navigate to page that I want? I'm looking for a clean solution (best practice?), not any dirty solution.
You could put the input fields in a Facelet tag file. Basic kickoff example:
/tags/user.xhtml
<ui:composition
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:outputLabel for="name" value="Name" />
<h:inputText id="name" value="#{user.name}" />
<h:message for="name" />
<br />
<h:outputLabel for="email" value="Email" />
<h:inputText id="email" value="#{user.email}" />
<h:message for="email" />
<br />
<h:outputLabel for="city" value="City" />
<h:inputText id="city" value="#{user.city}" />
<h:message for="city" />
</ui:composition>
Define it in /META-INF/user.taglib.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://example.com/jsf/facelets</namespace>
<tag>
<tag-name>user</tag-name>
<source>tags/user.xhtml</source>
</tag>
</facelet-taglib>
which you register in /WEB-INF/web.xml as follows
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/META-INF/user.taglib.xml</param-value>
</context-param>
(note, when you have multiple, use semicolon ; to separate them)
Finally just declare it in your main page templates.
<ui:composition
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:my="http://example.com/jsf/facelets"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:form>
<my:user user="#{register.user}" />
<h:commandButton value="Create" action="#{register.create}" />
</h:form>
</ui:composition>
and
<ui:composition
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:my="http://example.com/jsf/facelets"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:form>
<my:user user="#{editor.user}" />
<h:commandButton value="Save" action="#{editor.save}" />
</h:form>
</ui:composition>
The user="#{whatever}" attribute of <my:user> becomes the #{user} in the tag file (i.e. it's available by the attribute name as key).

Resources