[
https://issues.jboss.org/browse/RF-12053?page=com.atlassian.jira.plugin.s...
]
Andrew Cheung updated RF-12053:
-------------------------------
Forum Reference:
https://community.jboss.org/message/628865#628865 (was:
https://community.jboss.org/message/628865#628865)
I found an explanation to the behaviour: Moving items between the left and right hand
side are client side and therefore the event is not triggered. The event is triggered on
submit.
To the administrator of bug reports : Please cancel this bug report. Thanks.
Picklist : valueChangeListener does not work when user moves items
between left and right sides
-----------------------------------------------------------------------------------------------
Key: RF-12053
URL:
https://issues.jboss.org/browse/RF-12053
Project: RichFaces
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: component-selects
Affects Versions: 3.3.3.Final
Environment: RichFaces 3.3.3Final
JBOSS EPP5.1.1
browsers : Firefox 10.0.2 and IE8
Reporter: Andrew Cheung
Labels: picklist, valueChangeListener
The valueChangeListener for picklist does not fire when a user moves items between the
left and right hand sides of the picklist.
Code as follows:
index.xhtml:
<a4j:form id="ModifyUserForm">
<rich:pickList id="pkAuxOffices" sourceListWidth="377px"
targetListWidth="377px" showButtonsLabel="false"
copyAllVisible="false" removeAllVisible="false"
value="#{myBean.selectedAuxOffices}" converter="sibcvtr"
valueChangeListener="markAuxOfficesModified" >
<f:selectItems value="#{myBean.auxOffices}"/>
</rich:pickList>
<h:commandButton styleClass="btn-go" id="btnSubmit"
action="#{myBean.modifyUser}" value="Go" />
</a4j:form>
-----------------
In the bean (myBean.java):
private List<SIBean> selectedAuxOffices = null; //for picklist right hand side
private ArrayList<SelectItem> auxOffices = null;
public List<SIBean> getSelectedAuxOffices() {
return selectedAuxOffices;
}
public void setSelectedAuxOffices(List<SIBean> selectedAuxOffices) {
this.selectedAuxOffices = selectedAuxOffices;
}
public ArrayList<SelectItem> getAuxOffices() {
return auxOffices;
}
public void setAuxOffices(ArrayList<SelectItem> auxOffices) {
this.auxOffices = auxOffices;
}
public UA() throws java.lang.Exception {
initializeMyBean();
}
private void initializeMyBean() throws java.lang.Exception {
....
auxOffices = demo.createSIList(...); //retrieves the list of available offices
from the database
//get selected attribute values on the right side of the picklist
List<SIBean> userSelectedAuxOffices = createSIBeanList(...); //retrieves the
list of selected offices from the database
if (selectedAuxOffices == null) {
selectedAuxOffices = new ArrayList<SIBean>();
}
if (auxOffices == null) {
auxOffices = new ArrayList<SelectItem>();
}
selectedAuxOffices = userSelectedAuxOffices;
}
public void markOfficesModified(ValueChangeEvent event) {
ArrayList<SIBean> auxOfficesBeanChanged =
(ArrayList<SIBean>)event.getNewValue();
String[] auxOfficesChanged = new String[auxOfficesBeanChanged.size()];
int i = 0;
for (SIBean sib : auxOfficesBeanChanged) {
auxOfficesChanged[i] = sib.getValue();
_Logger.error("DEBUGXXX : auxOfficesChanged = " + auxOfficesChanged[i]);
i++;
}
}
-------------------
Code in SIBean.java :
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.log4j.Logger;
public class SIBean {
private String label;
private String value;
public SIBean(String newlabel, String newvalue){
label = newlabel;
value = newvalue;
}
public SIBean(){
label = "";
value = "";
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public boolean equals(Object obj) {
if (obj == null)
return false;
if (obj == this)
return true;
if (obj.getClass() != getClass())
return false;
SIBean rib = (SIBean) obj;
return new EqualsBuilder().
append(value, rib.value).
isEquals();
}
}
--------------
Code in converter :
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.apache.log4j.Logger;
import demo.SIBean;
public class SIBeanConverter implements Converter {
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
// TODO Auto-generated method stub
int index = arg2.indexOf(':');
if (index == -1) {
return new SIBean(arg2,arg2); //workaround for index out of range
issue (arg2 should contain "label:value"; but sometimes it only contain
"value" due to the bug reported in JIRA)
}
else {
return new SIBean(arg2.substring(0, index), arg2.substring(index + 1));
}
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
// TODO Auto-generated method stub
if (arg2 instanceof SIBean) {
return ((SIBean)arg2).getLabel() + ":" +
((SIBean)arg2).getValue();
}
else {
return arg2.toString();
}
}
}
----------------------
faces-config.xml :
<converter>
<converter-id>sibcvtr</converter-id>
<converter-class>demo.SIBeanConverter</converter-class>
</converter>
<managed-bean>
<description>myBean</description>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>demo.myBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
-------------------------
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira