Primefaces how to get POJO from selectOneMenu - ajax

My question is how to get value from selection in 'selectOneMenu' component. I use POJO not String type. I try to display the name property of selected object in inputText. I use commandButton to refresh value in inputText as in code below. But the problem is that nothing appears in inputText. I'm not sure there is need to use converter but I tried and it also hasn't worked.
here is my .jsp file:
<p:selectOneMenu value="#{appointentBean.selectedSpecialization}">
<f:selectItems value="#{appointentBean.specializationResult}" var="i" itemValue="#{i}" itemLabel="#{i.name}"/>
</p:selectOneMenu>
<p:commandButton value="Szukaj" >
<p:ajax update="textid" />
</p:commandButton>
<p:inputText id="textid" value="#{appointentBean.selectedSpecialization.name}" />
appointmentBean:
#ManagedBean
#ViewScoped
#SessionScoped
public class appointentBean
{
private ArrayList<Specialization> specializationResult;
private Specialization selectedSpecialization;
public ArrayList<Specialization> getSpecializationResult()
{
//Here retrievie objects list from database and it works
return specializationResult;
}
public void setSpecializationResult(ArrayList<Specialization> result) {
this.specializationResult = result;
}
public Specialization getSelectedSpecialization() {
return selectedSpecialization;
}
public void setSelectedSpecialization(Specialization selectedSpecialization) {
this.selectedSpecialization = selectedSpecialization;
}
}
Specialization.java:
#Entity
#Table(name="Specializations")
public class Specialization
{
#Id
#GeneratedValue
private int specialization_id;
#Column(name="name")
private String name;
public int getSpecialization_id() {
return specialization_id;
}
public void setSpecialization_id(int specialization_id) {
this.specialization_id = specialization_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
What is more. If I do not make selection on the list NullPointerExcetion appears. But when I make choice i doesn't. So the object is set after selection.

Give a name to your Managed Bean like this
1. #ManagedBean(name ="appointentBean")
2. It should be in Session Scoped or View Scoped not in Both
Your code works perfectly on my End. I did changes to
ArrayList<Specialization> getSpecializationResult() like this:
public ArrayList<Specialization> getSpecializationResult()
{
//Here retrievie objects list from database and it works
specializationResult = new ArrayList<Specialization>();
Specialization specialize= new Specialization();
specialize.setName("Vinayak");
specialize.setSpecialization_id(1);
specializationResult.add(specialize);
return specializationResult;
}
It worked . So, make the necessary changes and let us know.
EDIT 2
Whenever we Deal with POJO's at that time we have to deal with Converter.
Why Custom Converter is the question is what you want to ask now. Refer Custom Converter
These are the steps to create Custom Converter
1. Create a converter class by implementing javax.faces.convert.Converter interface.
2. Override both getAsObject() and getAsString() methods.
3. Assign an unique converter ID with #FacesConverter annotation present in javax.annotation.
First of all I have created a POJOConverter class for your Specialization class
package primefaces1;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
#FacesConverter(forClass=Specialization.class)
public class PojoConverter implements Converter{
public static List<Specialization> specilizationObject;
static {
specilizationObject = new ArrayList<Specialization>();
specilizationObject.add(new Specialization("Vinayak", 10));
specilizationObject.add(new Specialization("Pingale", 9));
}
public Object getAsObject(FacesContext facesContext, UIComponent
component, String submittedValue) {
if (submittedValue.trim().equals("")) {
return null;
} else {
try {
for (Specialization p : specilizationObject) {
if (p.getName().equals(submittedValue)) {
return p;
}
}
} catch(NumberFormatException exception) {
throw new ConverterException(new
FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion
Error", "Not a valid Specialization"));
}
}
return null;
}
public String getAsString(FacesContext facesContext, UIComponent
component, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return String.valueOf(((Specialization) value).getName());
}
}
}
Following changes has been made to your managed Bean class. To overcome the NUll Pointer Exception
package primefaces1;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean(name = "appointentBean")
#SessionScoped
public class appointentBean {
private ArrayList<Specialization> specializationResult;
private Specialization selectedSpecialization ;
#PostConstruct
public void init() {
selectedSpecialization = new Specialization();
selectedSpecialization.setName(new String());
selectedSpecialization.setSpecialization_id(0);
}
public appointentBean() {
specializationResult= (ArrayList<Specialization>)
PojoConverter.specilizationObject;
}
public ArrayList<Specialization> getSpecializationResult() {
// Here retrievie objects list from database
//and it works
return specializationResult;
}
public void setSpecializationResult(ArrayList<Specialization> result) {
this.specializationResult = result;
}
public Specialization getSelectedSpecialization() {
if (this.selectedSpecialization != null)
System.out.println("getSelectedSpecialization----"
+ this.selectedSpecialization.getName());
return this.selectedSpecialization;
}
public void setSelectedSpecialization(Specialization
selectedSpecialization) {
this.selectedSpecialization = selectedSpecialization;
}
}
I have made some minute changes to your xhtml for showing values.
<h:body>
<h:form id="me">
<p:selectOneMenu value="#{appointentBean.selectedSpecialization}" >
<f:selectItem itemLabel="Select One" itemValue=""></f:selectItem>
<f:selectItems value="#{appointentBean.specializationResult}"
var="result" itemValue="#{result}" itemLabel="#{result.name}" />
</p:selectOneMenu>
<p:commandButton value="Szukaj" update="me:textid">
</p:commandButton>
<h:outputText value="NAME: "></h:outputText>
<h:outputText id="textid" value="#{appointentBean.selectedSpecialization.name}" rendered="#{not empty appointentBean.selectedSpecialization}"/>
</h:form>
</h:body>

I find myself in the same situation that user2374573, SelectOneMenu, was populated correctly using a custom converter, but the selected item was null. The proposed solution is a variation of the custom converter, but it doesn't solve the problem (at least for me). The value selecting does not arrive as explained in the Primefaces documentation, this occurs because SelectOneMenu operates with String and not with Pojos. After studying In the end I have opted for an intermediate solution.
Instead of having a variable of type pojo to store the value, I use just having a String that stores the id of the element as follows.
This solution has been useful for the SelectOneMenu and also for loading the Targer in the DualList used in the Primefaces Picklist. It is not an ideal solution, but it saves the problem.
Java View
public class PickListView implements Serializable {
private static final long serialVersionUID = 1L;
private List<CviConcesione> listaConcesion;
private CviConcesione concesionSeleccionada;
private String concesionSeleccionadaS;
#Autowired
private ConcesionesBO concesionesBO;
#PostConstruct
public void init() {
}
public List<CviConcesione> getListaConcesion() {
if (null != listaConcesion && !listaConcesion.isEmpty()) {
return listaConcesion;
} else {
listaConcesion = new ArrayList<CviConcesione>();
listaConcesion = concesionesBO.consultaTodasConcesiones();
return listaConcesion;
}
}
public void setListaConcesion(List<CviConcesione> listaConcesion) {
this.listaConcesion = listaConcesion;
}
public ConcesionesBO getConcesionesBO() {
return concesionesBO;
}
public void setConcesionesBO(ConcesionesBO concesionesBO) {
this.concesionesBO = concesionesBO;
}
public CviConcesione getConcesionSeleccionada() {
return concesionSeleccionada;
}
public void setConcesionSeleccionada(CviConcesione concesionSeleccionada) {
this.concesionSeleccionada = concesionSeleccionada;
}
public String getConcesionSeleccionadaS() {
return concesionSeleccionadaS;
}
public void setConcesionSeleccionadaS(String concesionSeleccionadaS) {
this.concesionSeleccionadaS = concesionSeleccionadaS;
}
}
Html Code for select one menu
<p:selectOneMenu
id="concesionR"
value="#{pickListView.concesionSeleccionadaS}"
style="width:125px"
dynamic="true"
converter="#{concesionConverter}">
<f:selectItem itemLabel="Seleccione" itemValue="" />
<f:selectItems value="#{pickListView.listaConcesion}"
var="concesion"
itemLabel="#{concesion.conCodigo} - #{concesion.conDescripcion}"
itemValue="#{concesion.conCodigo}"
ajax = "true"
/>
<p:ajax update="lineaR" process="#form" />
</p:selectOneMenu>
a
Class converter
#FacesConverter("concesionConverter")
public class ConcesionesConverter implements Converter {
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
if(value != null && value.trim().length() > 0) {
try {
PickListView service = (PickListView) fc.getExternalContext().getApplicationMap().get("pickListView");
return service.getListaConcesion().get(Integer.parseInt(value));
} catch(NumberFormatException e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
}
}
else {
return null;
}
}
public String getAsString(FacesContext fc, UIComponent uic, Object object) {
if(object != null) {
return String.valueOf(((CviConcesione) object).getConId());
}
else {
return null;
}
}
}
This solution does not manage to bring the pojo, but lets you know that it has been selected, showing pojo values.

Related

Ajax event does not fire on JSF page when an item is selected (update)

I am learning JavaEE and I am playing around with ajax call with jsf and managedbean. I am trying to display the text as soon as i change the value from the drop down list. I see many people have the same problem on stackoverflow and i try to follow answers that are marked as accepted but I still can't make it work. Can someone please tell me where my error is?
Here is the jsf code:
<h:form>
<h:selectOneMenu id="productlist" value="#{productRepoMB.selectedProduct}">
<f:selectItems value="#{productRepoMB.productList}" var="product" itemValue="#{product.productID}" />
<f:ajax event="valueChange"
render="result"
listener="#{productRepoMB.selectMenuListener}" />
</h:selectOneMenu>
text changed: <h:outputText id="result" value="#{productRepoMB.text}" />
</h:form>
Here is managed bean code, Products list is populated from a database:
#Named
#RequestScoped
public class ProductRepoMB implements Serializable {
#EJB
private ProductsRepo productRepo;
private Products selectedProduct;
private List<Products> productList;
private String text="init text"; //use for testing ajax call
public ProductRepoMB() {
}
public Products getSelectedProduct() {
return selectedProduct;
}
public List<Products> getProductList() {
productList = productRepo.findAll();
return productList;
}
//The following code are used to testing ajax only!
public void selectMenuListener(AjaxBehaviorEvent e) {
setText("changed!");
}
public String getText() {
return text;
}
public void setText(String text){
this.text = text;
}
}

Spring Bean injection in JSF Converter

I have seen this question has been asked in this forum but following the solutions provided on those posts, I am not able to inject the spring bean in my converter.
Below is the code snippet:
UserConverter.java class:
#ManagedBean
public class UserConverter implements Converter {
private SearchServiceImpl searchService;
public SearchServiceImpl getSearchService() {
return searchService;
}
public void setSearchService(SearchServiceImpl searchService) {
this.searchService = searchService;
}
#Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String submittedValue) {
List<User> users = getSearchService().getAllUsers();
if (submittedValue.trim().equals("")) {
return null;
} else {
try {
int number = Integer.parseInt(submittedValue);
for (User user : users) {
if (user.getId() == number) {
return user;
}
}
} catch(NumberFormatException exception) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid player"));
}
}
return null;
}
#Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return String.valueOf(((User) value).getFirstName());
}
}
}
I am invoking the converter from xhtml like:
<p:autoComplete id="users" value="#{userSearchBean.selecteSearchedUser}" completeMethod="# {userSearchBean.searchFriends}" var="user" itemLabel="#{user.firstName}" itemValue="#{user}" converter="#{userConverter}" forceSelection="true">
</p:autoComplete>
faces-config.xml:
<converter>
<converter-id>userConverter</converter-id>
<converter-class>com.mbeans.UserConverter</converter-class>
<property>
<property-name>searchService</property-name>
<property-class>com.services.SearchServiceImpl</property-class>
<default-value>#{searchService}</default-value>
</property>
</converter>
enter code here
SearchServiceImpl is the spring class that needs to be injected in the UserConverter.java class.
But unable to get any reference of SearchServiceImpl in the UserConverter.java
Thank you in advance for your help.

Disable inputText Primefaces depending selectOneMenu

I have a form with a selectOneMenu with two option and one inputText that which must be disabled if user choose the second option. I think that I should use ajax with update of inputText and is what I did, but don't work. Here is my code, please help me. Thanks
<h:outputText value="Modalita"></h:outputText>
<p:selectOneMenu value="#{vociCostoBean.selected.modalita}" immediate="true">
<f:selectItem itemLabel="Importo" itemValue="0"/>
<f:selectItem itemLabel="Quantita" itemValue="1"/>
<p:ajax update="uc" />
</p:selectOneMenu>
<h:outputText value="Costo Unitario"></h:outputText>
<p:inputText id="uc" disabled="#{vociCostoBean.selected.modalita !='1'}" value="#{vociCostoBean.selected.CUnitario}" />
<br></br>
and this vociCostoBean:
#ManagedBean
#SessionScoped
public class VociCostoBean {
#EJB
private CostoBeanRemote cust;
private List<VociCosto> list;
private VociCosto selected= new VociCosto();
private boolean UcDisabled=true;
#PostConstruct
public void init(){
setList(new ArrayList<VociCosto>());
setList(cust.getAll());
//selected.setModalita("0");
}
public String newCosto(){
return "editCosto";
}
public void onRowSelect(){
FacesContext fc = FacesContext.getCurrentInstance();
System.out.println("|||||"+ getSelected().getNome());
try {
fc.getExternalContext().redirect("editCosto.jsf");
} catch (IOException e) {
}
}
public VociCosto getSelected() {
return selected;
}
public void setSelected(VociCosto selected) {
this.selected = selected;
}
public void setCust(CostoBeanRemote cust) {
this.cust = cust;
}
public List<VociCosto> getList() {
return list;
}
public void setList(List<VociCosto> list) {
this.list = list;
}
public boolean isUcDisabled() {
return UcDisabled;
}
public void setUcDisabled(boolean ucDisabled) {
this.UcDisabled = ucDisabled;
}
}
and this is VociCosto.java
package it.bway.timerep.entities;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Set;
/**
* The persistent class for the VOCI_COSTO database table.
*
*/
#Entity
#Table(name="VOCI_COSTO")
public class VociCosto implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(name="ID_COSTO", unique=true, nullable=false)
private int idCosto;
#Column(name="C_UNITARIO")
private int cUnitario;
#Column(length=1)
private String modalita;
#Column(length=50)
private String nome;
//bi-directional many-to-one association to NoteSpese
#OneToMany(mappedBy="vociCosto", fetch=FetchType.EAGER)
private Set<NoteSpese> noteSpeses;
public VociCosto() {
}
public int getIdCosto() {
return this.idCosto;
}
public void setIdCosto(int idCosto) {
this.idCosto = idCosto;
}
public int getCUnitario() {
return this.cUnitario;
}
public void setCUnitario(int cUnitario) {
this.cUnitario = cUnitario;
}
public String getModalita() {
return this.modalita;
}
public void setModalita(String modalita) {
this.modalita = modalita;
}
public String getNome() {
return this.nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Set<NoteSpese> getNoteSpeses() {
return this.noteSpeses;
}
public void setNoteSpeses(Set<NoteSpese> noteSpeses) {
this.noteSpeses = noteSpeses;
}
#Override
public boolean equals(Object obj) {
try{
VociCosto toCompare = (VociCosto) obj;
if (idCosto==toCompare.getIdCosto()) return true;
return false;
} catch (Exception e){
return false;
}
}
#Override
public int hashCode(){
return idCosto;
}
}
You are doing exacly the opposite of what you are expecting. You should change
#{vociCostoBean.selected.modalita != '1'}
to
#{vociCostoBean.selected.modalita == '1'}
Working test case
View :
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<h:outputText value="Modalita"></h:outputText>
<p:selectOneMenu value="#{selectMenuActions.value}" immediate="true">
<f:selectItem itemLabel="Importo" itemValue="0"/>
<f:selectItem itemLabel="Quantita" itemValue="1"/>
<p:ajax update="uc" />
</p:selectOneMenu>
<h:outputText value="Costo Unitario"></h:outputText>
<p:inputText id="uc" disabled="#{selectMenuActions.value == '1'}" value="#{vociCostoBean.selected.CUnitario}" />
<br></br>
</h:form>
</h:body>
</html>
Bean :
#ManagedBean
#ViewScoped
public class SelectMenuActions
{
private String m_sValue;
public void setValue(String p_sValue)
{
m_sValue = p_sValue;
}
public String getValue()
{
return m_sValue;
}
}

JSF 2.1 SelectOneMenu toggling automatically to init values

I have 2 SelectOneMenu as follows in the index.xhtml. The menu1 essentially chooses a language(sp or en) and menu2 displays the possible serial numbers(0 to 3). I have the init constructor(post constructor) which initialises the default values on the two Menus. However for some strange reason, if I select a serial number other than the default serial number for the language other than the default language, somehow the language gets reset to init default :(
<?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"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>My page</title>
</h:head>
<h:body>
<div>
<h4>Change Existing Description</h4>
</div>
<h:form id="myForm">
<h:panelGrid columns="4">
<h:outputLabel value="Language:" />
<h:selectOneMenu value="#{myBean.language}">
<f:selectItems value="#{myBean.languages}" />
<f:ajax listener="#{myBean.doUpdate}" render ="myForm" />
</h:selectOneMenu>
<h:outputLabel value="SerialID:" />
<h:selectOneMenu value="#{myBean.serialID}">
<f:selectItems value="#{myBean.serialIDs}" />
<f:ajax listener="#{myBean.doUpdate}" render ="myForm" />
</h:selectOneMenu>
</h:panelGrid>
</h:form>
</h:body>
</html>
Here is my Bean code. Where is the problem?? please advise!
package bean;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
#ManagedBean(name = "myBean")
//#Stateless
#Stateful
#RequestScoped
public class MyBean {
public static final int PERMISSIONS = 2;
private List<String> languages;
private String language;
private int serialID;
private List<Integer> serialIDs;
/**
* init() method for initializing the bean. Is called after constuction.
*/
#PostConstruct
private void init() {
//public MyBean () {
languages = getAllLanguages();
language = "en"; //defaultLanguage
serialID = 3;
serialIDs = getSerialIDsFromOverview();
}
public List<String> getLanguages() {
System.out.println("getLanguages, language " +language);
return languages;
}
public int getPERMISSIONS() {
return PERMISSIONS;
}
public String getLanguage() {
System.out.println("getLanguage " +language);
return language;
}
public void setLanguage(String language) {
System.out.println("setLanguage " +language);
this.language = language;
}
public int getSerialID() {
System.out.println("getSerialID " +serialID);
return serialID;
}
public void setSerialID(int serialID) {
System.out.println("setSerialID " +serialID);
this.serialID = serialID;
}
public List<Integer> getSerialIDs() {
System.out.println("getSerialIDs language = "+language );
return serialIDs;
}
public List<String> getAllLanguages() {
List<String> results = new ArrayList<String>();
results.add("sp");
results.add("en");
if(results != null){
System.out.println("getting all languages");
}
return results;
}
public void doUpdate() {
System.out.println("doUpdate language " +language);
System.out.println("doUpdate serialID " +serialID);
}
/**
* Returns a list of all serialIDs present in the overview.
* #return
*/
private List<Integer> getSerialIDsFromOverview() {
List<Integer> results = new ArrayList<Integer>();
results.add(0);
results.add(1);
results.add(2);
results.add(3);
return results;
}
}
UPDATES:
After taking suggestions from cubbuk, I sat down and corrected my code with #ViewScoped annotation and making the bean implement Serializable. THIS WORKS. However, the next thing I had to do was include an #EJB annotation to call a stateless bean which calls the Entity manager to fetch the serialIDs from a database instead of "hardcoding" it. That is when I encounter the problem: Not serializable exception "java.io.NotSerializableException: bean.__EJB31_Generated__. How do I solve this? When I made myBean back to RequestScope and remove Serializable, I could run the code without problems however there the toggling of the menu to init values :(
By the way I check this post: #EJB in #ViewScoped managed bean causes java.io.NotSerializableException and set my STATE SAVING METHOD to server but that gives me "empy response from server" pop up message :(
Please help!
Since you are using #RequestScoped bean as your backing bean after each request your init method is getting called and your values are getting reset. To avoid that you need to use #ViewScoped bean as your backing bean. I updated your bean accordingly note that your backing bean now implements Serializable interface. This is needed as this bean will be stored in your servlet and it needs to be flushed to disk if the content can not be hold in the memory. For learning the details of #ViewScoped beans please check the following post:
http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html
Apart from these, for naming conventions I renamed your getAllLanguages and getSerialIDsFromOverview methods to initAllLanguages and initSerialIds as methods starting with get and set can be confusing because they are mostly used for getters and setters.
Lastly when you use f:ajax command by default the UIInput the ajax command is bind to is rendered and executed. Since you don't refresh the h:selectOneMenu menus according to the values of each other you don't need to render the whole form. The following will be enough for this case:
<h:form id="myForm">
<h:panelGrid columns="4">
<h:outputLabel value="Language:" />
<h:selectOneMenu value="#{myBean.language}">
<f:selectItems value="#{myBean.languages}" />
<f:ajax listener="#{myBean.doUpdate}"/>
</h:selectOneMenu>
<h:outputLabel value="SerialID:" />
<h:selectOneMenu value="#{myBean.serialID}">
<f:selectItems value="#{myBean.serialIDs}" />
<f:ajax listener="#{myBean.doUpdate}"/>
</h:selectOneMenu>
</h:panelGrid>
</h:form>
#ManagedBean
#ViewScoped
public class MyBean implements Serializable
{
public static final int PERMISSIONS = 2;
private List<String> languages;
private String language;
private int serialID;
private List<Integer> serialIDs;
/**
* init() method for initializing the bean. Is called after constuction.
*/
#PostConstruct
protected void init()
{
//public MyBean () {
System.out.println("lang: " + language);
System.out.println("serialId: " + serialID);
System.out.println("init is called");
initAllLanguages();
initSerialIds();
language = "en"; //defaultLanguage
serialID = 3;
}
public List<String> getLanguages()
{
return languages;
}
public int getPERMISSIONS()
{
return PERMISSIONS;
}
public String getLanguage()
{
return language;
}
public void setLanguage(String language)
{
this.language = language;
}
public int getSerialID()
{
return serialID;
}
public void setSerialID(int serialID)
{
this.serialID = serialID;
}
public List<Integer> getSerialIDs()
{
return serialIDs;
}
private void initAllLanguages()
{
languages = new ArrayList<String>();
languages.add("sp");
languages.add("en");
}
public void doUpdate()
{
System.out.println("doUpdate language " + language);
System.out.println("doUpdate serialID " + serialID);
}
/**
* Returns a list of all serialIDs present in the overview.
*
* #return
*/
private void initSerialIds()
{
serialIDs = new ArrayList<Integer>();
serialIDs.add(0);
serialIDs.add(1);
serialIDs.add(2);
serialIDs.add(3);
}
}
Cheers

Richfaces 4 datatable rowclick is not hitting the listener method

I am migrating an application from richfaces 3 to 4. And I am stuck at the datatable.
The rowclick sends request to server and renders response, but not invoking the listener method. It is not even evaluating the method. I have tried giving a non-existing method name, it still doesn't complain at run time either. I am using the Richfaces 4.0.0 CR1 library.
Anyone has a clue, please help me.
Here is my datatable code.
<rich:dataTable id="customersTable"
value="#{customerBean.customerList}"
var="customer"
rowKeyVar="rowKey">
<a4j:ajax event="rowclick"
listener="#{customerBean.makeRowEditable}">
</a4j:ajax>
<rich:column>
<f:facet name="header">Id</f:facet>
#{customer.id}
</rich:column>
<rich:column>
<f:facet name="header">Name</f:facet>
#{customer.name}
</rich:column>
</rich:dataTable>
The backing bean
package myapp;
import java.util.ArrayList;
import java.util.List;
import javax.faces.event.AjaxBehaviorEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class CustomerBean {
protected Log log = LogFactory.getLog(this.getClass());
private List<Customer> customerList;
private Customer selectedCustomer;
public CustomerBean() {
log.warn("CustomeBean is instantiated." + this);
this.customerList = new ArrayList<CustomerBean.Customer>();
customerList.add(new Customer(1, "One"));
customerList.add(new Customer(2, "Two"));
customerList.add(new Customer(3, "Three"));
customerList.add(new Customer(1, "Four"));
}
public List<Customer> getCustomerList() {
return customerList;
}
public void setCustomerList(List<Customer> customerList) {
this.customerList = customerList;
}
public Customer getSelectedCustomer() {
return selectedCustomer;
}
public void setSelectedCustomer(Customer selectedCustomer) {
this.selectedCustomer = selectedCustomer;
}
public void makeRowEditable(AjaxBehaviorEvent event) {
log.warn("CustomerBean. makeRowEditable: ");
}
public void selectCustomer(Customer customer) {
this.selectedCustomer = customer;
log.warn("CustomerBean. selectCustomer: customer = " + customer);
}
public void unselectCustomer() {
log.warn("CustomerBean. unselectCustomer: ");
this.selectedCustomer = null;
}
public class Customer {
private int id;
private String name;
public Customer() {
}
public Customer(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
Any help is appreciated :)
Remove this
<a4j:ajax event="rowclick"
listener="#{customerBean.makeRowEditable}">
</a4j:ajax>
if you uses richfaces 4!

Resources