voyent
SelectManyListbox converter problem  XML
Forum Index -> General Help
Author Message
danmei

Joined: 01/Dec/2006 00:00:00
Messages: 14
Offline


Hi there

The getAsObject Method of a converter registered by a selectManyListbox is never called. I use Icefaces 1.5.2:

The method:

Code:
public Object convertSelectValue(FacesContext facesContext,
                                      UISelectMany uiSelectMany,
                                      String[] newSubmittedValues)


in the class MenuRenderer does not implement a converting function for java.util.List Objects. Instead it returns a List of String objects. I think this part has been forgotten, as for Arrays exists an converting function "convertArray".

What do you think. greetings
daniel
FlyingElvi

Joined: 15/Dec/2006 00:00:00
Messages: 80
Offline


I had similar problems with selectManyCheckBox, I ended up doing the conversion in my backingBean setters and getters :(

Max
danmei

Joined: 01/Dec/2006 00:00:00
Messages: 14
Offline


Hello Elvi

ok, this also possible. Now I am using arrays instead of collections, this works fine too. But I hope they fix it in the next release.

greetings
daniel
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Hi,

For any custom object used in a List, you have to register a custom converter and also implement an equals() method in your custom object.

Thanks,
Philip

.
danmei

Joined: 01/Dec/2006 00:00:00
Messages: 14
Offline


Hello Philip

Yes i think i did that correct.
Code:
 <ice:selectManyListbox id="allFocus" value="#{FocusBean.selectedFocuses}"
 		converter="RdFocus" size="6">
 	<f:selectItems value="#{FocusBean.focusList}" />
 </ice:selectManyListbox>
 


Code:
 public RdFocus[] getSelectedFocuses() {return selectedFocuses;}
 public void setSelectedFocuses(RdFocus selectedFocuses[]) {this.selectedFocuses = selectedFocuses;}
 



Because when i work with Arrays it works fine.
The problem occurs only with collections, then the converter is never called.

Code:
 public ArrayList<RdFocus> getSelectedFocuses() {return selectedFocuses;}
 public void setSelectedFocuses(ArrayList<RdFocus> focuses) {this.selectedFocuses = selectedFocuses;}
 



Maybe im totally wrong but let me explain:

After debugging i reached the method
Code:
 public Object convertSelectValue(FacesContext facesContext,
                                      UISelectMany uiSelectMany,
                                      String[] newSubmittedValues)
 


in the MenuRenderer class.

If you have a quick look at the implementation you see that you make a differtiation between arrays and lists:
Code:
 if (List.class.isAssignableFrom(valueBindingClass)) {
     ArrayList submittedValuesAsList = new ArrayList(newSubmittedValues.length);
     for (int index = 0; index < newSubmittedValues.length; index++) {
        submittedValuesAsList.add(newSubmittedValues[index]);
     }
     return submittedValuesAsList;
 }
 if (valueBindingClass.isArray()) {
    Class componentType = valueBindingClass.getComponentType();
    return convertArray(facesContext, uiSelectMany, componentType,
                                 newSubmittedValues);
 }
 


For the case of arrays there is a convertArray(..) function which converts the strings with the registered converter to the propper objects. But for lists i cant see that, you only create a new ArrayList an put the strings without convertion in that list an return it.

What dou you think?

Greetings
Daniel


ruhko02

Joined: 14/May/2007 00:00:00
Messages: 3
Offline


Hi,

I want to use Seam's convertEntity on a ice:selectManyListbox.Code:
 <s:decorate>
   <ice:selectManyListbox value="#{eventSeriesManager.eventSeries.eventCategories}" partialSubmit="true">
     <s:selectItems value="#{eventSeriesManager.eventCategoriesForSelection}" var="cat" label="#{cat.name}"/>
     <t:convertHibernateEntity/>
   </ice:selectManyListbox>
 </s:decorate>


The conversion didn't work as expected and I tracked the problem down to the very same spot Daniel mentioned.

So I gave it a try and implemented a very simple conversion for lists. Is there a reason why this hasn't been done before or is there a different way to convert selectManyListbox items?

The following code works with the seam example from above but hasn’t been tested with any other use case – so use at your own risk! Also, this could be improved with generics, so that default converter for classes work.Code:
com.icesoft.faces.renderkit.dom_html_basic
 
 public class MenuRenderer extends DomBasicInputRenderer {
 
   public Object convertSelectValue(FacesContext facesContext,
                                      UISelectMany uiSelectMany,
                                      String[] newSubmittedValues)
             throws ConverterException {
   [...]
   if (List.class.isAssignableFrom(valueBindingClass)) {
         	return convertList(facesContext, uiSelectMany, newSubmittedValues);
         }
   [...]
 }
 
   protected List convertList(FacesContext facesContext,
     		UISelectMany uiSelectMany, String[] newSubmittedValues)
     throws ConverterException {
 
     	// if newSubmittedValue is null return zero-length array
     	if (newSubmittedValues == null) {
     		return new ArrayList();
     	}
 
     	// Determine if a converter is explicitly registered with the component
     	Converter converter = uiSelectMany.getConverter();
     	if (converter == null) {
     		throw new ConverterException("Converter is null");
     	}
 
     	List convertedValues = new ArrayList(newSubmittedValues.length);
     	for (int index = 0; index < newSubmittedValues.length; index++) {
 
     		// convert the next element
     		Object nextConvertedElement = converter.getAsObject(facesContext,
     				uiSelectMany,
     				newSubmittedValues[index]);
 
 			convertedValues.add(nextConvertedElement);
     	}
     	return convertedValues;
     }
 }


Regards
Patrick




mark.collette


Joined: 07/Feb/2005 00:00:00
Messages: 1692
Offline


I believe this was fixed in ICEfaces 1.6.1, as part of ICE-1665 : Support Seam tags related to <s:selectItems> to allow more than a String to be returned.

Also, for high quality bug reports such as this, I'd recommend making your own Jira cases directly, so that your recommendations are ensured to get to the proper developers.
[Email]
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


Any news on this? It's the second issue that isn't fixed in 1.7.1.
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team