Having issues with rich:autocomplete R4 M6
rlcaswell Feb 24, 2011 12:23 PMI'm using Richfaces 4.0.0.20110209-M6 on Glassfish with jsf-api and jsf-impl 2.0.3-b03. running on windows XP.
I've got a list of beans to use in an autocomplete list to populate a bean value in a jsf managed bean from the onchange event using <a4j:ajax/> tag.
However, the dropdown list is populated with what appears to be the converted value and the toString value of the beans in the list. The selected value appears to populate correctly. But the selected value is never populated in the managed bean when I tab out of the field also the debugger is never hitting the getAsObject method of the converter. I'm not sure what is going on here. I'm not sure if this is a bug in the <rich:autocomplete/> tag or if I'm doing something wrong here.
Here is the snippet from the xhtml:
<h:form >
<h:inputText value="#{exampleController.field1}" >
<a4j:ajax event="change" render="testPanel" execute="@this"/>
</h:inputText>
<rich:autocomplete id="artistInput" value="#{exampleController.bean}" mode="client" minChars="0"
autofill="false"
showButton="true"
autocompleteList="#{exampleController.autoCompleteBeans}"
converter="#{autocompleteBeanConverter}"
itemConverter="#{autocompleteBeanConverter}"
>
<a4j:ajax event="change" render="testPanel" execute="@this"/>
</rich:autocomplete>
<h:inputText value="#{exampleController.field2}" >
<a4j:ajax event="change" render="testPanel" execute="@this"/>
</h:inputText>
<h:panelGrid id="testPanel" columns="3">
<rich:panel>
<h:outputText value="#{exampleController.field1}"/>
</rich:panel>
<rich:panel>
<h:outputText value="#{exampleController.beanField}" />
</rich:panel>
<rich:panel>
<h:outputText value="#{exampleController.field2}"/>
</rich:panel>
</h:panelGrid>
</h:form>
Here are the java classes with accessors ommitted for space sake:
public class AutocompleteBean {
String field;
}
@ManagedBean(name="autocompleteBeanConverter")
@SessionScoped
public class AutocompletBeanConverter implements Converter, Serializable {
List<AutocompleteBean> beans =
Arrays.asList(new AutocompleteBean("1bean"),new AutocompleteBean("2bean"),
new AutocompleteBean("3bean"));
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
if (StringUtils.isBlank(value)) {
return null;
} else {
AutocompleteBean bean = null;
String fieldValue = StringUtils.trim(value);
for(AutocompleteBean thisBean: beans){
if(thisBean.getField().equals(fieldValue)){
bean= thisBean;
}
}
return bean;
}
}
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
if (value != null) {
AutocompleteBean bean = (AutocompleteBean) value;
return bean.getField();
} else {
return null;
}
}
}
@ManagedBean(name="exampleController")
@SessionScoped
public class ExampleController {
AutocompleteBean bean;
String field1;
String field2;
public AutocompleteBean getBean() {
return bean;
}
public void setBean(AutocompleteBean bean) {
this.bean = bean;
}
public String getBeanField(){
if(bean!=null){
return bean.getField();
}
else {
return null;
}
}
public List<AutocompleteBean> getAutoCompleteBeans(){
return Arrays.asList(new AutocompleteBean("1bean"),new AutocompleteBean("2bean"),
new AutocompleteBean("3bean"));
}
}
-
autocompletbug-1.0.war 6.0 MB