Skip to main content

Composite component with selectManyListBox throws UpdateModelException

6 replies [Last post]
vdweij
Offline
Joined: 2010-02-01
Points: 0

I want to include a selectManyListBox in a composite component, but cannot succesfully pass the listbox's value as a interface attribute. A conversion exception occures during the update model phase.
javax.faces.component.UpdateModelException: java.lang.IllegalArgumentException: Cannot convert [Ljava.lang.Object;@45033fb5 of type class [Ljava.lang.Object; to interface java.util.List
I'm using jsf 2.1.0-b06
The list contains pojo's and I made a converter for them.
When I extract the code from the component and include it directly in a facelets it all works ok.
Has anyone succesfully integrated a selectManyListBox in a composite component?
I hava a little maven based proof of concept/failure available.
       <!-- http://docs.sun.com/app/docs/doc/820-7627/giqzr?l=en&amp;a=view -->     <composite interface="">  <composite name="source" required="true" attribute=""></composite> <composite name="target" required="true" attribute=""></composite> <composite name="converterId" attribute=""></composite> </composite>  <composite implementation="">  <h value="#{cc.attrs.target}" selectmanylistbox=""> <f converterid="#{cc.attrs.converterId}" rendered="#{cc.attrs.converterId != null}" converter=""></f> <f var="item" value="#{cc.attrs.source}" itemlabel="#{item.name}" selectitems=""></f> </h>  </composite>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rcasha
Offline
Joined: 2003-12-09
Points: 0

Did you find a solution to this problem or file a bug report?

vdweij
Offline
Joined: 2010-02-01
Points: 0

No solution yet. I decided work around this by using a different ui-design. Version 2.1.0-b06 is relatively old and perhaps newer versions do not have this issue anymore. Which version are you using?
I did not file a bug report for this issue since I was waiting for a response in this forum or some sort of confirmation.
I'll try my proof of concept with the latets jsf version and get back on this asap. If it still fails we could consider reporting this bug (if it hasn't been done yet).

vdweij
Offline
Joined: 2010-02-01
Points: 0

Ran the test with latest available release (2.1.1-b04) and it still fails. I'll browse the issue list and see whether it has been reported and do so if it is missing.

vdweij
Offline
Joined: 2010-02-01
Points: 0

It has already been reported:
http://java.net/jira/browse/JAVASERVERFACES-2047
Vote if you whish for it to be fixed.

vdweij
Offline
Joined: 2010-02-01
Points: 0

Code belonging to proof of concept/failure
Facelet content:

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
    xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
    xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
    xmlns:c=&quot;http://java.sun.com/jstl/core&quot;
    xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
    xmlns:own=&quot;http://java.sun.com/jsf/composite/custom/&quot;&gt;
   
    &lt;h:head&gt;
        &lt;title&gt;Composite Component Test&lt;/title&gt;   
    &lt;/h:head&gt;

    &lt;h:body&gt;
        &lt;h:form&gt;
            &lt;own:listBox source=&quot;#{orderPage.availableLines}&quot; target=&quot;#{orderPage.order.lines}&quot; converterId=&quot;lineConverter&quot;/&gt;
            &lt;h:commandButton value=&quot;try with cc&quot; action=&quot;#{orderPage.persist}&quot;/&gt;
        &lt;/h:form&gt;
       
        &lt;h:form&gt;
            &lt;h:selectManyListbox value=&quot;#{orderPage.order.lines}&quot;&gt;
                &lt;f:converter converterId=&quot;lineConverter&quot; /&gt;
                &lt;f:selectItems var=&quot;item&quot; value=&quot;#{orderPage.availableLines}&quot; itemLabel=&quot;#{item.name}&quot;/&gt;
            &lt;/h:selectManyListbox&gt;
            &lt;h:commandButton value=&quot;try without cc&quot; action=&quot;#{orderPage.persist}&quot;/&gt;
        &lt;/h:form&gt;
    &lt;/h:body&gt;
&lt;/html&gt;

Composite component content:
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
    xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
    xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
    xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
    xmlns:composite=&quot;http://java.sun.com/jsf/composite&quot;&gt;
  
    &lt;composite:interface&gt;
        &lt;composite:attribute name=&quot;source&quot; required=&quot;true&quot;/&gt;
        &lt;composite:attribute name=&quot;target&quot; required=&quot;true&quot;/&gt;
        &lt;composite:attribute name=&quot;converterId&quot;/&gt;
    &lt;/composite:interface&gt;

    &lt;composite:implementation&gt;
        &lt;h:selectManyListbox value=&quot;#{cc.attrs.target}&quot;&gt;
            &lt;f:converter converterId=&quot;#{cc.attrs.converterId}&quot; rendered=&quot;#{cc.attrs.converterId != null}&quot; /&gt;
            &lt;f:selectItems var=&quot;item&quot; value=&quot;#{cc.attrs.source}&quot; itemLabel=&quot;#{item.name}&quot;/&gt;
        &lt;/h:selectManyListbox&gt;             
    &lt;/composite:implementation&gt;
&lt;/html&gt;

OrderPage Managed Bean
package cc;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean(name=&quot;orderPage&quot;)
@ViewScoped
public class OrderPage {

    private Order order;
   
    private List&lt;Line&gt; availableLines;
   
    @PostConstruct
    protected void init() {
        order = new Order(1);
       
        availableLines = LineStore.getAvailableLines();
    }
   
    public void persist() {
        //here we would normally call persistence logic
        System.out.println(&quot;Persiting order&quot; + order);
        if (order.getLines() != null &amp;&amp; order.getNrOflines() &gt; 0) {
            System.out.println(&quot;Order has following lines:&quot;);
            for (Line line : order.getLines()) {
                System.out.println(line);
            }
        } else {
            System.out.println(&quot;Order has no lines&quot;);
        }
    }
   
    public Order getOrder() {
        return order;
    }
   
    public void setOrder(Order order) {
        this.order = order;
    }
   
    public List&lt;Line&gt; getAvailableLines() {
        return availableLines;
    }
}

Order
package cc;

import java.util.List;

public class Order {

private int id;
private List&lt;Line&gt; lines;

public Order(int id) {
this.id = id;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Order) {
return getId() == ((Order) obj).getId();
}
return false;
}

@Override
public int hashCode() {
return id;
}

@Override
public String toString() {
return String.format(&quot;Order [id=%s] [number of lines: %s]&quot;, id, getNrOflines());
}

public int getNrOflines() {
if (lines != null) {
return lines.size();
} else {
return 0;
}
}

public int getId() {
return id;
}

public List&lt;Line&gt; getLines() {
return lines;
}

public void setLines(List&lt;Line&gt; lines) {
this.lines = lines;
}
}

Line
package cc;

public class Line {
   
    private int id;
    private String name;
   
   
    public Line(int id, String name) {
        this.id = id;
        this.name = name;
    }
   
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Line) {
            return getId() == ((Line) obj).getId();
        }
        return false;
    }
   
    @Override
    public int hashCode() {
        return id;
    }
   
    @Override
    public String toString() {
        return String.format(&quot;Line [id=%s][name=%s]&quot;, id, name);
    }
   
    public int getId() {
        return id;
    }
   
    public String getName() {
        return name;
    }
   
    public void setName(String name) {
        this.name = name;
    }
}

LineStore
package cc;

import java.util.ArrayList;
import java.util.List;

public class LineStore {

    private static List&lt;Line&gt; availableLines;
   
    static {
        availableLines = new ArrayList&lt;Line&gt;();
       
        availableLines.add(new Line(1, &quot;line 1&quot;));
        availableLines.add(new Line(2, &quot;line 2&quot;));
        availableLines.add(new Line(3, &quot;line 3&quot;));
        availableLines.add(new Line(4, &quot;line 4&quot;));
    }
   
    public static List&lt;Line&gt; getAvailableLines() {
        return availableLines;
    }
   
    public static Line findLine(int id) {
        for (Line line : availableLines) {
            if (line.getId() == id) {
                return line;
            }
        }
        return null;
    }
   
}

LineConverter
package cc;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;


@FacesConverter(forClass=LineConverter.class, value=&quot;lineConverter&quot;)
public class LineConverter implements Converter {

@Override
public Object getAsObject(FacesContext fc, UIComponent comp, String str) {
return LineStore.findLine(Integer.valueOf(str));
}

@Override
public String getAsString(FacesContext fc, UIComponent comp, Object obj) {
return Integer.toString(((Line) obj).getId());
}

}
36 Guest
Offline
Joined: 2010-11-10
Points: 0

I want to include a selectManyListBox in a composite component, but cannot
succesfully pass the listbox's value as a interface attribute. A conversion
execption occures during the update model phase.

javax.faces.component.UpdateModelException:
java.lang.IllegalArgumentException: Cannot convert
[Ljava.lang.Object;@45033fb5 of type class [Ljava.lang.Object; to interface
java.util.List

I'm using jsf 2.1.0-b06

The list contains pojo's and I made converter for them.

When I extract the code from the component and include it directly in a
facelts it all works ok.

Has anyone succesfullt integrated a selectManyListBox in a composite
component?

I hava a little maven based proof of concept/failure available.