valueChangeListener on h:selectOneMenu not working
raovenu Dec 5, 2014 12:18 PMWe are in the process of upgrading our application from richFaces 3.3.2 and MyFaces 1.2 to richFaces 4.2.2.Final and MyFaces 2.0. I am having issues to get valueChangeListener to execute on a picklist. I followed the example on RichFaces showcase but still not able to get it to work. Here is the 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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:s="http://myfaces.apache.org/sandbox"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:c="http://java.sun.com/jsp/jstl/core"
>
<h:body>
<ui:composition template="/WEB-INF/layout/layout.xhtml">
<ui:define name="title">
NAMS - Device Type
</ui:define>
<ui:define name="content">
<a4j:region>
<h:form id="deviceTypeForm">
<div>
<div style="font: 15pt/16pt Georgia, serif;color: #555753">
<h1>Maintain Device Type
</h1>
</div>
<rich:panel id="headerPanel">
<f:facet name="header">Select DeviceType</f:facet>
<h:outputText value=""/> <f:verbatim><br/></f:verbatim><h:outputText value=""/>
<h:panelGrid id="deviceTypePanelGrid" columns="3" styleClass="detail" columnClasses="label">
<h:outputText value="Device Type" />
<h:selectOneMenu id="deviceTypeList"
value="#{deviceTypeBean.selectedType}"
converter="#{deviceTypeConverter}" onchange="submit()"
valueChangeListener="#{deviceTypeBean.valueChanged}">
<f:selectItem itemValue="#{deviceTypeBean.defaultType}"
itemLabel="New" />
<f:selectItems value="#{deviceTypeBean.types}" />
<a4j:ajax event="change" execute="@this" render="deviceTypeDetails" />
</h:selectOneMenu>
<h:message for="deviceTypeList" />
</h:panelGrid>
</rich:panel>
<rich:panel id="detailsPanel">
<f:facet name="header">DeviceType Details</f:facet>
<a4j:outputPanel id="deviceTypeDetails" layout="block">
<h:panelGrid id="typePanelGrid" columns="3" styleClass="detail" columnClasses="label">
<h:outputLabel for="deviceName">
<h:outputText value="Name" />
<h:outputText style="color: #DD0707" value=" * " />
</h:outputLabel>
<h:inputText id="deviceName"
style="width: 300px"
maxlength="40"
required="true"
disabled="#{securityBean.privMap['deviceTypeFormDeviceName']}"
binding="#{deviceTypeBean.nameComp}"
value="#{deviceTypeBean.selectedType.name}">
</h:inputText>
<h:message for="deviceName" id="deviceNameError"
styleClass="errorMessage" />
<h:outputLabel for="description">
<h:outputText value="Description" />
</h:outputLabel>
<h:inputTextarea id="description"
rows="2"
cols="50"
disabled="#{securityBean.privMap['deviceTypeFormDescription']}"
value="#{deviceTypeBean.selectedType.description}">
<f:validateLength maximum="100"
minimum="0"/>
</h:inputTextarea>
<h:message id="deviceTypeDescriptionError" for="description"
styleClass="errorMessage" />
</h:panelGrid>
</a4j:outputPanel>
</rich:panel>
<div>
<h:panelGroup styleClass="buttonBar">
<h:commandButton id="btnSave"
value="Save"
disabled="#{securityBean.privMap['deviceTypeFormBtnSave']}"
onclick="return shuttle.setSelected();"
action="#{deviceTypeBean.update}"
styleClass="button" />
<h:commandButton id="btnDelete"
value="Delete"
action="#{deviceTypeBean.delete}"
disabled="#{deviceTypeBean.disableDeleteButton}"
onclick="return confirmDelete('deviceTypeForm','deviceName');"
styleClass="button" />
</h:panelGroup>
</div>
</div>
</div>
</h:form>
</a4j:region>
</ui:define>
</ui:composition>
</h:body>
</html>
Backing Bean Code:
package com.test.nmt.nams.view.bean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlInputText;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataIntegrityViolationException;
@ManagedBean(name = "deviceTypeBean")
@ViewScoped
public class DeviceTypeBean
{
public static final String SHOW_FORM_ACTION = "showDeviceTypeForm";
/** The Constant logger. */
public static final String NEW_NAME = "New";
public static final String ROUTER = "Network Infrastructure - Router";
private final static Log logger = LogFactory.getLog(DeviceTypeBean.class);
/** The disable delete button. */
private boolean disableDeleteButton;
// managers
/** Device type manager */
private DeviceTypeManager deviceTypeManager;
/** Role Manager */
private RoleManager roleManager;
private LoginManager loginManager;
private UtilityManager utilityManager;
/** bean property */
private List<SelectItem> userRoles = Collections.EMPTY_LIST;
private List<NamsRole> userRolesSelected = Collections.EMPTY_LIST;
private List<SelectItem> deviceRoles = Collections.EMPTY_LIST;
private List<NamsRole> deviceRolesSelected = Collections.EMPTY_LIST;
private HtmlInputText nameComp;
// properties
/** bean property */
private DeviceType selectedType;
private SecurityBean securityBean;
private Map<String, Boolean> privMap = new HashMap<String, Boolean>();
private String changeDate;
private String changeUser;
/**
* Always return new, empty DeviceType
*
* @return the defaultType
*/
public DeviceType getDefaultType()
{
//return new DeviceType();
DeviceType dt = null;
try
{
dt = (DeviceType) NamsUtils.deepInstance(DeviceType.class, 1);
} catch (Exception e)
{
throw new ViewException("Unable to create address block registry instance");
}
return dt;
}
public DeviceType getSelectedType()
{
return this.selectedType;
}
public List<SelectItem> getTypes()
{
List<SelectItem> types = new ArrayList<SelectItem>();
types = new ArrayList<SelectItem>();
final List<DeviceType> allTypes = this.deviceTypeManager.getDeviceTypeList();
for (final DeviceType type : allTypes)
{
types.add(new SelectItem(type, type.getName()));
}
return types;
}
/**
* Selects type from dropdown list
*/
public void valueChanged(ValueChangeEvent event)
{
logger.debug("select ");
this.userRoles.clear();
this.deviceRoles.clear();
if (this.selectedType.getId() != 0)
{
resetFacesContext();
if(privMap.get("deviceTypeFormBtnDelete") != null && privMap.get("deviceTypeFormBtnDelete"))
{
this.disableDeleteButton = true;
}else
{
this.disableDeleteButton = false;
}
}else
{
this.disableDeleteButton = true;
}
setChangeInfo(selectedType);
}
/**
* @param defaultType
* the defaultType to set
*/
public void setDefaultType(final DeviceType defaultType)
{
// ignore the assignment
logger.debug("Attempt to assing " + defaultType + " to default type is ignored");
}
public void setSelectedType(final DeviceType selectedType)
{
this.selectedType = selectedType;
}
}
Here are the libraries I am using:
richfaces-components-api-4.2.2.Final.jar
richfaces-components-ui-4.2.2.Final.jar
richfaces-core-api-4.2.2.Final.jar
richfaces-core-impl-4.2.2.Final.jar
myfaces-api-2.0.0.jar
myfaces-impl-2.0.0.jar
I would appreciate anyone providing me some direction on where I am going wrong.
Thanks,
RaoV