In my application I have a relationship between cities (A) and postalcodes (B).
So I have two SelectOneMenu's where the first represents A's and the second represents the B's of the selected A which are updated via ajax.
Since I use these two menu's multiple times i wrote a custom tag for them which usually works fine aslong the A and B values are assigned to existing variables in my session bean.
But there is a case where I want to pass a new relationship object to my bean which is not working using a tag component.
The properties A and B of the new request scoped AToB Object which I want to pass as an argument to the add method of my logic session bean are null!
*Additional Notes
- Using the tag component with existing session bean variables works.
- Using tag component to add a new request bean based relationship object does not work.
- The selected A is always (in case 1 and 2) passed correctly to the bean using ajax change event.
- The converters for the SelectOneMenu's always work. (Tested in debug mode)
- Using the tag component JSF never calls the setters to set A and B of the new AToB Object, tested in debug mode.
- Using jsf default h:commandButton instead of primefaces produces same error.
- It works perfectly not using the tag component!
Environment:
Mojarra 2.14
GlassFish 3.01
I simplified the classes removing constructors and getter & setters.
DTO, Pojo:
public Class A{}
public Class B{}
public Class AToB
{
private A a;
private B b;
}
Session Bean:
public Class Bean
{
private List<A> as;
private List<B> bs;
private AConverter aConverter;
private BConverter bConverter;
//updates bs list
public void updateBsByA(AjaxBehaviorEvent event) {}
//does something with the given AToB
public void add(AToB aToB)
}
faces-config.xml:
<managed-bean>
<managed-bean-name>beanLogic</managed-bean-name>
<managed-bean-class>package.Bean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<description>new AToB Object I want to add at database</description>
<managed-bean-name>newAToB</managed-bean-name>
<managed-bean-class>package.Bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
abSelect tag file:
<ui:composition
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"
xmlns:abcd="http://store24.de/jsf/admin">
<h:selectOneMenu value="#{tagA}" converter="#{beanLogic.aConverter}">
<f:selectItems value="#{beanLogic.as}"/>
<p:ajax event="change" listener="#{beanLogic.updateBsByA}" update="selectB"/>
</h:selectOneMenu>
<h:selectOneMenu id="selectB" value="#{tagB}" converter="#{beanLogic.bConverter}">
<f:selectItems value="#{beanLogic.bs}"/>
</h:selectOneMenu>
</ui:composition>
abcd.taglib.xml
<?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://abcd.com/jsf</namespace>
<tag>
<tag-name>abSelect</tag-name>
<source>tags/abSelect.xhtml</source>
<attribute>
<display-name>a</display-name>
<name>tagA</name>
<required>true</required>
<type>package.A</type>
</attribute>
<attribute>
<display-name>a</display-name>
<name>tagB</name>
<required>true</required>
<type>package.B</type>
</attribute>
</tag>
</facelet-taglib>
calling site:
<abcd:abSelect a="#{newAToB.a} b="#{newAToB.b}"/>
<p:commandButton value="add" action="#{beanLogic.add(newAToB)}"/>
Instead adding a new AToB without the tag component works (see above #2)
<h:selectOneMenu value="#{newAToB.a}" converter="#{beanLogic.aConverter}">
<f:selectItems value="#{beanLogic.as}"/>
<p:ajax event="change" listener="#{beanLogic.updateBsByA}" update="selectB"/>
</h:selectOneMenu>
<h:selectOneMenu id="selectB" value="#{newAToB.b}" converter="#{beanLogic.bConverter}">
<f:selectItems value="#{beanLogic.bs}"/>
</h:selectOneMenu>
<p:commandButton value="add" action="#{beanLogic.add(newAToB)}"/>