Unicode character not correctly redisplayed in request query string - jsf

I wrote this little JSF 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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>What's your Name?</title>
</h:head>
<h:body>
<h1>What's your name?</h1>
<h:form>
<p>Name: <h:inputText value="#{nameController.name}" /></p>
<h:commandButton value="Submit" action="#{nameController.process}" />
</h:form>
</h:body>
</html>
The name property in nameController is simple, with a variable (of type String), a getter, and a setter, just how you would expect. nameController.process passes name as a GET parameter to another JSF page.
But, if I type "ëlmer" as the name, for example, I am redirected to this URL:
http://localhost:8080/NameThing/name.jsf?name=ëlmer
instead of
http://localhost:8080/NameThing/name.jsf?name=ëlmer
How is this caused and how can I solve it?

Related

ArrayIndexOutOfBoundsException for composite component with ajax invocation inside

My 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 xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:compo="http://java.sun.com/jsf/composite/test">
<h:head>
</h:head>
<h:body>
<h:form>
<compo:composite changeListener="#{testBean.invoke}"/>
</h:form>
</h:body>
</html>
My composite component:
<?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:composite="http://java.sun.com/jsf/composite"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<composite:interface>
<composite:attribute name="changeListener" required="true"
method-signature="java.lang.Object action(javax.faces.event.AjaxBehaviorEvent)"/>
</composite:interface>
<composite:implementation>
<h:commandButton value="Click">
<f:ajax event="click" listener="#{cc.attrs.changeListener}"/>
</h:commandButton>
</composite:implementation>
</html>
My java bean (prototype scope in spring):
public class Bean {
public void invoke(javax.faces.event.AjaxBehaviorEvent event) {
// some logic
}
}
When I trying to press button, I see
02-Jul-2014 01:24:22.242 WARNING [http-apr-8080-exec-43] com.sun.faces.lifecycle.InvokeApplicationPhase.execute 0
java.lang.ArrayIndexOutOfBoundsException: 0
at org.apache.el.parser.AstValue.convertArgs(AstValue.java:287)
at org.apache.el.parser.AstValue.invoke(AstValue.java:241)
in log. For some cases I've got: java.lang.NumberFormatException: For input string: testBean.invoke So, it is JSF bug or I do something wrong? How I can pass method expression inside composite component?
Looks like JSF bug https://java.net/jira/browse/JAVASERVERFACES-2758
Exceptions are different, but if you opens response in browser, you will see PropertyNotFoundException.
Workaround for me: pass not MethodExpression, but bean and methodName separately and execute listener as
listener="#{cc.attrs.bean[cc.attrs.method]}"
The stack trace it looks like the Apache Expression Language parser form Tomcat (org.apache.el.parser). I think it is this issue: https://bz.apache.org/bugzilla/show_bug.cgi?id=57855 ( Invoke MethodExpression with wrong pram count results in ArrayIndexOutOfBoundsException).

Possible Scope problems in a JSF2 web application

I´ve a JSF web application using SPRING3 + JSF2 (mojarra 2.1.12) and I´m having some problems that I think can be derived of a bad choose of the Scope of one controller in one combo of the JSF2+primefaces interface.
This combo functionality allows the user to choose one of the internal xhtml subpages and a button that automatically redirects you to that page.
The website uses a template technology: there is template (standard.xhtml) with the JSF2 code and using this template there are several pages: a inicio.xhtml that is the home page and a contact page (contacto.xhtml). In both pages the combo is displayed properly.
The following code it is working properly only if you´re navigating at the home page (incio.xhtml) but when you´re in other part of the web (i.e. contacto.xhtml) it displays the combo with all the options, but the button doesn´t work at all.
Here it´s my code in standard.xhtml file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="${userContext.locale}" lang="${userContext.locale}"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:sec="http://www.springframework.org/security/tags">
<f:view contentType="text/html">
<h:head>
//HEAD
</h:head>
<body>
<div id="…">
<div id="…">
//CODE
//CODE to go from one page (inicio.xhtml) to other (contacto.xhtml)
<li><h:commandLink value="${msg.app_menu_contacto}" action="mContacto" /></li>
//MORE CODE
<h:form>
//MORE CODE
<h:panelGrid id="buscar" columns="2" style="margin-top:20px;" cellpadding="5">
<p:selectOneMenu id="selectBuscar" value="#{buscador.procedimiento}" panelStyle="width:150px;"
var="p" style="width:220px; margin-right: 10px; " filter="true" filterMatchMode="startsWith">
<f:selectItem itemLabel="${msg.app_comun_seleccionar}" itemValue="" />
<f:selectItems value="#{buscador.procedimientos}" var="proc" itemLabel="#{proc.codigo}" itemValue="#{proc.valor}"/>
</p:selectOneMenu>
<p:commandButton id="btnIr" style="width:40px" value="#{msg.app_comun_btn_ir}" title="#{msg.app_comun_btn_ir_title}"
action="#{buscador.direccion}">
</p:commandButton>
</h:panelGrid>
</h:form>
</div>
</div>
</body>
</f:view>
</html>
In the faces-navigation.xml we have these lines (faces-navigation is only used in several inherited parts of the code):
<navigation-case>
<from-outcome>mContacto</from-outcome>
<to-view-id>/views/comun/contacto.xhtml</to-view-id>
<redirect />
</navigation-case>
Code of the xhtml home page where it is working:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition 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:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
xmlns:sec="http://www.springframework.org/security/tags"
template="/WEB-INF/layouts/standard.xhtml">
//Code independent of the combo or button failing
// it uses ui:define to show different components in the page.
</ui:composition>
and this is the controller code:
#Controller("buscador")
//#Scope(“Session”)  Do not work with “request”, “view” or without scope
public class BuscadorController implements Serializable {
public List<ValorCombo> getProcedimientos() {
//Code that returns a list of pair String to show in the combo, name of the xhtml page should be redirected
}
public String direccion() {
//CODE
String salida = "proc/"+procedimiento+"?faces-redirect=true";
//more CODE
return salida;
}
}
I have tried this but it doesn´t work neither.
http://balusc.blogspot.com.es/2011/09/communication-in-jsf-20.html
how can I solve this problem?
Thanks!

rich:calendar does not display within ui:composition

I'm new to JSF and I'm facing this weird issue. I'm sure it's a silly mistake but I just can't seem to figure it out. Basically, when I insert rich:calendar within ui:composition it does not display. My (simplified) template is defined like this
<?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:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title></title>
</h:head>
<h:body>
<ui:insert name="content"/>
<ui:debug/>
</h:body>
</html>
My index 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 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">
<head>
<title></title>
</head>
<body>
<ui:composition template="/indexLayout.xhtml">
<h:outputScript library="javascript" name="common.js" target="head"/>
<ui:define name="content">
<h:form>
<h:panelGrid columns="2">
From
<rich:calendar id="pickup" onchange="#{rich:component('return')}.setValue(#{rich:component('pickup')}.getValue())"
dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" value="#{reservation.pickUp}" />
To
<rich:calendar id="return" dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" />
</h:panelGrid>
<h:commandButton value="Redisplay" />
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
If I define the index page without ui:composition it displays just fine. Please help. Thank you.
You should place your <h:outputScript /> inside the <ui:define></ui:define> since when you are using <ui:composition />, every <ui:insert /> inside the template are replaced by respective <ui:define />. Everything outside <ui:define /> is not rendered.
In your case the JavaScript function disablementFunction is not loaded so your rich:calendar doesn't work properly.
Here is how your index page should look like :
<ui:composition template="/indexLayout.xhtml">
<ui:define name="content">
<h:outputScript library="javascript" name="common.js" target="head"/>
<h:form>
<h:panelGrid columns="2">
From
<rich:calendar id="pickup" onchange="#{rich:component('return')}.setValue(#{rich:component('pickup')}.getValue())" dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" value="#{reservation.pickUp}" />
To
<rich:calendar id="return" dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" />
</h:panelGrid>
<h:commandButton value="Redisplay" />
</h:form>
</ui:define>
</ui:composition>
More info :
JSF 2 templating with Facelets example

Why does my form open in a new Tab?

Here is my code:
<?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">
<h:head>
<title>Guess Number</title>
</h:head>
<h:body>
The number I guessed is: #{guessNumber.generatedNumber}
<br />
<strong>Please guess the number I generated which is between 0 and 10!</strong>
<h:form target="index">
<h:commandButton type="submit" value="Guess The Number!"></h:commandButton>
</h:form>
</h:body>
</html>
So in the output I see something like:
The number I guessed is: 6 Please guess the number I generated which
is between 0 and 10!
and a button below this text. When I click the button, the page opens in a new tab. But why?
That's caused for the target attribute in the <h:form>. Note that this is defined for pure HTML, not a JSF-ish special behavior.
To solve the problem, just remove the target attribute from the <h:form>.

Trying to change <ui:include> src tag dynamically

I have main page that looks like this:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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.prime.com.tr/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<p:panel id="panel">
<ui:include src="#{bean.page}">
</ui:include>
</p:panel>
<p:commandButton actionListener="#{bean.changePage}" value="Push" ajax="true" update="panel"/>
</h:form>
</h:body>
</html>
What I want to do is have a bean like this and change dynamically which page is included. This is how bean looks like:
#ManagedBean
#SessionScoped
public class Bean {
private String page = "";
public Bean() {
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public void changePage(ActionEvent e) {
page = "Page.xhtml";
}
}
When I click button Push I want this page to be included:
<?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:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<ui:component>
Hello from facelets
</ui:component>
</h:form>
</h:body>
Problem is that I have to press the button twice for page to be included. How can this be done so when I press the button the first time page is included?
This kind of templating is normally achieved using the <ui:insert> and <ui:define> tags. Check out this page of the Java EE tutorial.

Resources