I am using (simple) JSF 2 custom components.
I mean that I am using a taglib.xml file like :
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib id="sentest"
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://www.senat.fr/taglib/sentest</namespace>
[...]
<tag>
<description>
<![CDATA[
À COMPLÉTER
]]>
</description>
<tag-name>senMandats</tag-name>
<source>tags/sen/senMandats.xhtml</source>
<attribute>
<description>
<![CDATA[
Identifiant unique.
]]>
</description>
<name>id</name>
<required>true</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
<![CDATA[
Contexte de sélection du Sénateur.
]]>
</description>
<name>context</name>
<required>true</required>
</attribute>
</tag>
</facelet-taglib>
The component is defined using ui composition :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="fr"
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:composite="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui"
xmlns:sen="http://java.sun.com/jsf/composite/sen"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:sf="http://www.senat.fr/taglib/senfunctions"
xmlns:st="http://www.senat.fr/taglib/sentest"
xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<h:head/>
<h:body>
<ui:composition>
[...]
</ui:composition>
</h:body>
</html>
it works fine except for one very embarrassing point.
I am passing dynamic el values to those custom components.
Example :
<st:senMandats id="toto" context="#{selectionContext}"/>
The selectionContext bean being defined elsewhere.
In st:senMandats, I use other custom components in a nested way. Something like :
<st:listeMandats mandatContext="#{sensContext}" asen="#{selectionContext.selectedSen}"/>
The listeMandat component uses a primefaces dataTable to display some lists from the context. So, I have code like :
<h:outputLabel value="listeMandats de #{asen.libelleLong}" styleClass="bigTitleMandats" rendered="#{not empty asen}" />
<p:dataTable id="tableMandatsSenatoriaux" value="#{mandatContext.asList}" /* lots of other parameters */>
When I select an entry in the picker, the custom component gets properly updated. I can see that the valueDisplayed by the h:outputLabel is correctly updated depending on the selection.
When #{mandatContext.AsList} is called, I am retrieving #{asen} from the application context and performing some internal update before returning the requested list. There comes the problem : if #{asen} seems to be ok when rendering #{asen.libelleLong}, I can not get the updated value from the backing bean.
I am using the following function :
@SuppressWarnings("unchecked")
public static <T> T findBean(String name) {
if ((name == null) || name.isEmpty())
return null;
FacesContext fc = FacesContext.getCurrentInstance();
logger.debug("Retrieving #{" + name + "}");
return (T) fc.getApplication().evaluateExpressionGet(fc,
"#{" + name + "}", Object.class);
}
in the AsList method :
JSFUtils.findBean("#{asen}")
always return an old, not updated value.
What should I do so that my bean can access the updated value ? I tried the solutions 4, 5 and 6 proposed by mykong in http://www.mkyong.com/jsf2/access-a-managed-bean-from-event-listener-jsf/ but still does not get the right value.
Am I forced to code a custom component class, deriving from a specific class ? If so, am I forced to also code a renderer ? I would like to avoid that, as I appreciate to have the layout in an xhtml file.
Thanks in advance.
I am using :
- PrimeFaces 3.4.1
- CODI 1.0.5
- OpenWebBeans 1.1.6
- MyFaces 2.1.9
- Tomcat 7.0.32 (edit : set "extra question" as a another question)