selectManyListbox for jaxb collection

时间:2012-10-15 17:46:56

标签: jaxb

我有一个由JAXB生成的集合,我希望将其关联到selectManyListbox以进行多选。

这是JSF:

<h:selectManyListbox value="#{field.textValueLookup.value}"                         size="5" >
 <f:selectItems value="#{consultaController.getOpcionesLookup(field.queryField)}"/>
</h:selectManyListbox>

这是JAXB的TextValueLookup类generateb

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2012.10.15 at 06:52:09 PM CEST 
//


package es.ine.iria2.query.jaxb.complexQuery;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element ref="{http://iria.ine.es/schemas/complexQuery.xsd}value" maxOccurs="unbounded" minOccurs="0"/>
 *       &lt;/sequence>
 *       &lt;attribute name="operator" use="required" type="{http://iria.ine.es/schemas/complexQuery.xsd}TextLookupFilterOperatorType" />
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "value"
})
@XmlRootElement(name = "textValueLookup")
public class TextValueLookup {

    protected List<String> value;
    @XmlAttribute(required = true)
    protected TextLookupFilterOperatorType operator;

    /**
     * Gets the value of the value property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the value property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getValue().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link String }
     * 
     * 
     */
    public List<String> getValue() {
        if (value == null) {
            value = new ArrayList<String>();
        }
        return this.value;
    }

    /**
     * Gets the value of the operator property.
     * 
     * @return
     *     possible object is
     *     {@link TextLookupFilterOperatorType }
     *     
     */
    public TextLookupFilterOperatorType getOperator() {
        return operator;
    }

    /**
     * Sets the value of the operator property.
     * 
     * @param value
     *     allowed object is
     *     {@link TextLookupFilterOperatorType }
     *     
     */
    public void setOperator(TextLookupFilterOperatorType value) {
        this.operator = value;
    }

}

问题是jaxb类生成的值集合缺少setter值,并且当提交selectManyListbox时(ajax或form),它会抛出此错误:

目标无法访问,'null'返回null:javax.el.PropertyNotFoundException:/consultaCompleja/seleccionCamposFiltro.xhtml @ 39,18 value =“#{field.textValueLookup.value}”:目标无法访问,'null'返回null < / p>

任何解决方法?

1 个答案:

答案 0 :(得分:0)

好的,xsd中的这个注释可以解决问题:

<xs:annotation>
    <xs:appinfo>
            <jaxb:property collectionType="indexed" />
    </xs:appinfo>
</xs:annotation>

现在集合是一个String [](不是List),并且有getter和setter。

这种方式我只定义了我的模式的一个集合作为索引,但是使用其他注释我们可以为所有集合指定它:

<xs:annotation>
    <xs:appinfo>
            <jaxb:globalBindings collectionType="indexed" />
    </xs:appinfo>
</xs:annotation>

希望得到这个帮助。

再见