jsf - Omnifaces - ListIndexConverter, principle of operation -


i try understand principle of operation of omnifaces.converter.listindexconverter

@facesconverter("omnifaces.listindexconverter") public class listindexconverter implements converter {  private static final string error_list_index_bounds =         "index {0} value {1} in component {2} out of bounds.";  private static final string error_value_not_in_list =         "object {0} in component {1} not appear present in given list.";  private list<?> list;  @override public object getasobject(facescontext context, uicomponent component, string value) {     int index = integer.valueof(value);     if (index < 0 || index >= list.size()) {         throw new converterexception(             createerror(error_list_index_bounds, index, value, component.getclientid(context))         );     }      return list.get(index); }  @override public string getasstring(facescontext context, uicomponent component, object value) {     (int = 0; < list.size(); i++) {         if (list.get(i).equals(value)) {             return + "";         }     }      throw new converterexception(         createerror(error_value_not_in_list, value == null ? "null" : value.tostring(), component.getclientid(context))     ); }  public void setlist(list<?> list) {     this.list = list; }  } 

i've debugged it, couldn't figure out everything!

here questions:

1) when , whom list member variable filled?

2) in documentation

http://omnifaces.org/docs/javadoc/2.0/org/omnifaces/converter/selectitemsindexconverter.html

the following point mentioned:

this converter has following disadvantage on selectitemsconverter:

the "validation error: value not valid" never occur anymore case available select items has incompatibly changed during postback due developer's mistake. developer should make absolutely sure same list preserved on postback (e.g. making property of view scoped or broader scoped bean).

(selectitemsconverter can replaced listconverter)

could explain bit more in detail? understood, need @requestscoped bean , editable list used datatable, provoke this? so, educational reasons , show other developers.

hope questions clear! lot explanation!

when , whom list member variable filled?

by <o:converter list> attribute, shown in usage section @ showcase.

<p:picklist value="#{bean.duallistmodel}" var="entity" itemvalue="#{entity}" itemlabel="#{entity.someproperty}">     <o:converter converterid="omnifaces.listindexconverter" list="#{bean.duallistmodel.source}" />     <!-- ===================================================^^^^ --> </p:picklist> 

the <o:converter> special taghandler allows setting arbitrary properties on referenced converter instance if bean properties.


the "validation error: value not valid" never occur anymore [...]

could explain bit more in detail?

selected items omnifaces.xxxindexconverter not identified own identifier anymore, position in list. if list changes across postbacks, jsf can way not validate anymore if selected item really part of list , enduser really intends select item. imagine item's position in list has changed due being removed or newer item being added before selected item, end getting wrong item. see answer on validation error: value not valid background explanation.

if security concern, you'd best pick omnifaces.xxxconverter (without index).


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -