rich:pickList does not revert after failed validation
sheriffpony Oct 8, 2010 3:43 PMHi. I am using RichFaces 3.3.3 and JSF 2.0 and am having an issue with the rich:pickList facelet not re-rendering properly after validation fails.
I am trying to limit the number of selections to no more than 4 entries. I have a custom validator class that is being called and validation is indeed failing.
If I select one, two, three or four items from the source (left) list, they appear in the target list. If I select a fifth item, it appears in the target list, and the validation error message is displayed. However, the five items are still on the target (right) list. If I refresh the page, the original four items will be there. For some reason, using a4j:support to re-render the picklist does not do this.
I am using a4j:support event="onlistchanged" to rerender the pickList. I have tried wrapping the component in a a4j:region and re-rendering that too, but it still shows 5 items.
Here is my code:
[JSF]
<h:form>
<rich:messages for="picklist" />
<rich:pickList id="picklist"
value="#{multiPickListBean.targetList}"
validator="#{multiSelectValidator.validate}">
<f:attribute name="maxSelections" value="4"/>
<f:selectItems value="#{multiPickListBean.sourceList}" />
<a4j:support event="onlistchanged" reRender="picklist"/>
</rich:pickList>
</h:form>
[Java Lists Bean]
public class MultiPickListBean {
private List<SelectItem> sourceItemList = new ArrayList<SelectItem>();
private List<SelectItem> targetItemList = new ArrayList<SelectItem>();
public MultiPickListBean() {
sourceItemList.add(new SelectItem("value1", "item1"));
sourceItemList.add(new SelectItem("value2", "item2"));
sourceItemList.add(new SelectItem("value3", "item3"));
sourceItemList.add(new SelectItem("value4", "item4"));
sourceItemList.add(new SelectItem("value5", "item5"));
sourceItemList.add(new SelectItem("value6", "item6"));
}
public List<SelectItem> getSourceList() {
return this.sourceItemList;
}
public List<SelectItem> getTargetList() {
return this.targetItemList;
}
public void setTargetList(List <SelectItem> list) {
this.targetItemList = list;
}
}
[Java Validator]
public class MultiSelectRangeValidator implements Validator {
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
int maxSelections = Integer.parseInt((String) component.getAttributes().get("maxSelections"));
if (((List<String>) value).size() > maxSelections) {
FacesMessage message = new FacesMessage("Cannot exceed " + maxSelections + " selections.");
throw new ValidatorException(message);
}
}
}
I have attached a screenshot of what it looks like. Is there some other way to make the picklist re-render itself after failing validation?
Edit: I forgot to mention that this was working fine for me in 3.3.1.GA and JSF 1.2.
-
example.JPG 8.2 KB