Injecting 'selected' value from RichFaces 'selectOneMenu' into an EJB
notify Jun 29, 2015 7:44 AMI'm porting a live JBoss 6.1, RichFaces 3.x & Seam 2.x application to:
JBoss WildFly 8.2, RichFaces 4.5.1 & JBoss Weld 2.2
I'm having trouble retrieving the selected value from a RichFaces selectOneMenu, which I need to select the values for the second selectOneMenu list,
My first selectOneMenu is populated with two rows from the database using @Produces
I have it working in all my Seam applications, but in the Weld CDI application it's returning 'null'.
XHTML
<code>
<h:selectOneMenu value="#{selectedAwcat}" valueChangeListener="#{categoriesBean.selectedAwcatChanged}">
<f:selectItems value="#{categoriesBean.awcatsList}" var='awCat' itemValue="${awCat.awcat}" itemLabel="#{awCat.awcat}" />
<f:converter converterId="awcatConverter" />
<a4j:ajax event="valueChange" execute="@this" />
</h:selectOneMenu>
</code>
My EJB
<code>
@Stateless
@Named("categoriesBean")
public class CategoriesBean implements CategoriesLocal {
...........
@Inject
private Awcat selectedAwcat;
@Produces
public List<Awcat> getAwcatsList() {
.....
return return awcatList;
}
/**
*
* @param awcat
* /
public void setSelectedAwcat(Awcat selectedAwcat) {
this.selectedAwcat = selectedAwcat;
}
/**
*
* @return
*/
public Awcat getSelectedAwcat() {
return this.selectedAwcat;
}
/**
*
*/
public void selectedAwcatChanged() {
logger.info(">>>>> selectedAwcatChanged selectedAwcat == " + this.selectedAwcat.getAwcat());
}
</code>
AwCat is an Entity bean:
<code>
public class Awcat implements Serializable {
}
<code>
I also wrote a customer converter
<code>
@FacesConverter("awcatConverter")
public class AwCatConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
System.out.println(">>>>> AwCatConverter s = " + s);
Awcat awcat = new Awcat();
awcat.setAwcat(s);
//return null;
return awcat;
}
@Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
System.out.println(">>>>> AwCatConvçerter getAsString o = " + o.toString());
//return null;
return o.toString();
}
}
<code>
In Seam I used:
<s:convertEntity/>
The JBoss WildFly console shows:
12:17:31,487 INFO [com.nohagl.ejb.CategoriesBean] (default task-128) >>>>> getAwcatsList .....
12:17:31,489 INFO [com.nohagl.ejb.CategoriesBean] (default task-128) >>>>> getAwcatsList awcatList = 2
12:17:31,489 INFO [stdout] (default task-128) >>>>> AwCatConvçerter getAsString o = Cycling
12:17:31,490 INFO [stdout] (default task-128) >>>>> AwCatConvçerter getAsString o = Motorcycling
12:17:35,042 INFO [stdout] (default task-15) >>>>> AwCatConverter s = Motorcycling
12:17:35,043 INFO [com.nohagl.ejb.CategoriesBean] (default task-15) >>>>> getAwcatsList .....
12:17:35,043 INFO [com.nohagl.ejb.CategoriesBean] (default task-15) >>>>> getAwcatsList awcatList = 2
12:17:35,044 INFO [stdout] (default task-15) >>>>> AwCatConverter s = Cycling
12:17:35,044 INFO [stdout] (default task-15) >>>>> AwCatConverter s = Motorcycling
12:17:35,045 INFO [com.nohagl.ejb.CategoriesBean] (default task-15) >>>>> getAwcatsList .....
12:17:35,045 INFO [com.nohagl.ejb.CategoriesBean] (default task-15) >>>>> getAwcatsList awcatList = 2
12:17:35,045 INFO [stdout] (default task-15) >>>>> AwCatConverter s = Cycling
12:17:35,045 INFO [stdout] (default task-15) >>>>> AwCatConverter s = Motorcycling
12:17:35,047 INFO [com.nohagl.ejb.CategoriesBean] (default task-15) >>>>> selectedAwcatChanged selectedAwcat == null
I can't get my head around what I'm doing wrong. Any pointers greatly received.
N.B. For many reasons I want to use EJB as my 'backing' beans, unless I've misunderstood the spec this is possible.