1

两天以来,我遇到了 PrimeFaces 3.5 selectOneMenu 对象的奇怪问题。我正在一个 EJB 项目中使用这种架构 JPA + EJB + JAX-WS,并且我从 Web 项目中的 JAX-WS 服务创建了一个客户端。然后将 Web 服务客户端封装在一个 ManagedBean 中以与我的 PrimeFaces 接口绑定。我的 ManagedBean 如下:

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Named;
import tg.moov.imereport.service.DownStream;
import tg.moov.imereport.service.DownStreamWSService;


@Named
@Stateless
public class DownStreamMBean {
    private DownStreamWSService service;

    public DownStreamMBean() {
        service = new DownStreamWSService();
    }

    public List<DownStream> getDownStreamsService() {
        return service.getDownStreamWSPort().getDownStreams();
    }

}

selectOneMenu 代码如下:

<h:form>
  <p:selectOneMenu value="#{downStreamTotalMBean.ds.IDDownStream}"> 
    <f:selectItems value="#{downStreamMBean.downStreamsService}" var="item"
      itemValue="#{item.IDDownStream}" itemLabel="#{item.nom}"/>                         
  </p:selectOneMenu>
</h:form>

这是 DownStream 类:

package tg.moov.imereport.service;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for downStream complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="downStream">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="IDDownStream" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="IPAddress" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="login" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="nom" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="password" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="path" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "downStream", propOrder = {
    "idDownStream",
    "ipAddress",
    "login",
    "nom",
    "password",
    "path"
})
public class DownStream {

    @XmlElement(name = "IDDownStream")
    protected String idDownStream;
    @XmlElement(name = "IPAddress")
    protected String ipAddress;
    protected String login;
    protected String nom;
    protected String password;
    protected String path;

    /**
     * Gets the value of the idDownStream property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getIDDownStream() {
        return idDownStream;
    }

    /**
     * Sets the value of the idDownStream property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setIDDownStream(String value) {
        this.idDownStream = value;
    }

    /**
     * Gets the value of the ipAddress property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getIPAddress() {
        return ipAddress;
    }

    /**
     * Sets the value of the ipAddress property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setIPAddress(String value) {
        this.ipAddress = value;
    }

    /**
     * Gets the value of the login property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getLogin() {
        return login;
    }

    /**
     * Sets the value of the login property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setLogin(String value) {
        this.login = value;
    }

    /**
     * Gets the value of the nom property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getNom() {
        return nom;
    }

    /**
     * Sets the value of the nom property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setNom(String value) {
        this.nom = value;
    }

    /**
     * Gets the value of the password property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getPassword() {
        return password;
    }

    /**
     * Sets the value of the password property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setPassword(String value) {
        this.password = value;
    }

    /**
     * Gets the value of the path property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getPath() {
        return path;
    }

    /**
     * Sets the value of the path property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setPath(String value) {
        this.path = value;
    }

}

Web 服务正常工作并显示数据,但 selectOneMenu 不显示任何内容。请有人帮助我。如果需要,我可以提供更多信息。

问候。

4

1 回答 1

0

您需要在 selectOneMenu 上为您的自定义类使用转换器。

请参阅 BalusC 他在此处的解释对象在 selectonemenu

在 primefaces 中,<p:selectOneMenu>有一个converter="" 属性,您也可以使用它来链接转换器,而不必使用单独添加它<f:converter>

于 2013-04-24T13:02:57.943 回答