views:

217

answers:

2

Hi,
if i want to bind the value-attribute of a h:selectmanycheckbox to a map, with the ri of the jsf 2.0.3 i would do something like the following

the bean:

private Map<String, String[]> values = new HashMap<String, String[]>();

public Map<String, String[]> getValues() {
    return values;
}

public void setValues(Map<String, String[]> values) {
    this.values = values;
}

and the xhtml page:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"&gt;
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>

    <h:form>
        <h:selectManyCheckbox
            id="test"
            value="#{testController.values['foo']}">
                <f:selectItem itemLabel="1" itemValue="1_1" />
                <f:selectItem itemLabel="2" itemValue="1_2" />
                <f:selectItem itemLabel="3" itemValue="1_3" />
                <f:selectItem itemLabel="4" itemValue="1_4" />                    
        </h:selectManyCheckbox>           
        <h:commandButton value="Send" />

    </h:form>

</h:body>

This works fine, but in my application I need more control over the location of every single checkbox, so i replaced the standard <h:selectManyCheckbox> tags with their icefaces-equivalent <ice:selectManyCheckbox> and the <ice:checkbox>.
The bean stays the same and the xhtml-page now looks like that:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ice="http://www.icesoft.com/icefaces/component"
  xmlns:f="http://java.sun.com/jsf/core"&gt;
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <h:form>
        <ice:selectManyCheckbox
            id="test"
            layout="spread"
            value="#{testController.values['foo']}">
                <f:selectItem itemLabel="1" itemValue="1_1" />
                <f:selectItem itemLabel="2" itemValue="1_2" />
                <f:selectItem itemLabel="3" itemValue="1_3" />
                <f:selectItem itemLabel="4" itemValue="1_4" />                    
        </ice:selectManyCheckbox>           
        <table border="1">
            <tr>
                <td><ice:checkbox id="c1" for="test" index="0" /></td>
                <td><ice:checkbox id="c2" for="test" index="1" /></td>
            </tr>
            <tr>
                <td><ice:checkbox id="c3" for="test" index="2" /></td>
                <td><ice:checkbox id="c4" for="test" index="3" /></td>
            </tr>
        </table>
        <h:commandButton value="Senden" />            
    </h:form>

</h:body>

Now whenever I send the form I get a conversion-error and I can't figure out why.

If I bind the <ice:selectManyCheckbox>'s value-attribute to a simple stringarray it forks fine, but because I don't know how many checkbox-groups there will be I need it to work with a map.

I use the icefaces 2.0.0 beta 1 together with the sun ri 2.0.3 and the el 2.2 on tomcat 6.0.26.

Does anybody know a solution to my problem?

A: 

did u tried to implement a converter ?

dustin.b
Thanks for the quick response.In fact I did, but it's rather strange. I implemented a custom converter and included a println() to see its progress and while the `getAsString()` method is called successfully multiple times, the `getAsObject()`method gets never called.any ideas?
not really, but maybe this isn't the right way anyway..
dustin.b
A: 

u can try to put as many dummy mapelemts u need to "initialize" your map

dustin.b
That seems to do the trick, but considering that I don't have to do that with the ri, I guess it could be considered a bug.
maybe u can bugreport this ... they love to read bugreports in beta phase :)
dustin.b