ComboBox无法正确填充项目

时间:2017-07-20 17:34:03

标签: json data-binding combobox vaadin8

你好吗?我有我的UI并填充了一个来自json的comboBox, 履行 问题是只出现最后一项Vendor json。 https://cve.circl.lu/api/browse当出现约5000时

MyUI类

@CDIUI("")
@Theme("mytheme")
public class MyUI extends UI {
private ComboBox<String> vendors = new ComboBox<String>("Vendors");
private ComboBox<String> products = new ComboBox<String>("Products");
private CVEService cveService = new CVEService();
    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();
        vendors.setEmptySelectionAllowed(false);
        List<String> allVendors = cveService.getAllVendors();
        for(String v : allVendors ) {
        vendors.setItems(v);
        }
        vendors.setItemCaptionGenerator( v -> v == null ? "Empty" : String.valueOf(v));
        layout.addComponents(vendors,products);

        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinCDIServlet {
    @Override
        protected final void servletInitialized() throws ServletException {
            super.servletInitialized();

        }
    }
}

WebTarget类

 import java.util.List;
 public class CVEService {

 private Client client;
 private WebTarget target;
 private static final String URL_CVE_SEARCH_API = 
 "https://cve.circl.lu/api";

 public List<String> getAllVendors() {
   client = ClientBuilder.newClient();
   target = client.target(URL_CVE_SEARCH_API + "/browse");
   return 
  target.request(MediaType.APPLICATION_JSON).get(Vendors.class).getVendor();
 }

 public List<String> getVendorProducts(String vendor) {
   client = ClientBuilder.newClient();
   target = client.target(URL_CVE_SEARCH_API + "/browse/" + vendor);
   return
 target.request(MediaType.APPLICATION_JSON).get(Products.class).
 getProduct();}
}

类供应商

@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"product",
"vendor"
})
public class Vendors {

@JsonProperty("product")
private Object product;
@JsonProperty("vendor")
@Valid
private List<String> vendor = new ArrayList<String>();
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
 * No args constructor for use in serialization
 * 
 */
public Vendors() {
}

/**
 * 
 * @param product
 * @param vendor
 */
public Vendors(Object product, List<String> vendor) {
    this.product = product;
    this.vendor = vendor;
}

/**
 * 
 * @return
 *     The product
 */
@JsonProperty("product")
public Object getProduct() {
    return product;
}

/**
 * 
 * @param product
 *     The product
 */
@JsonProperty("product")
public void setProduct(Object product) {
    this.product = product;
}

public Vendors withProduct(Object product) {
    this.product = product;
    return this;
}

/**
 * 
 * @return
 *     The vendor
 */
@JsonProperty("vendor")
public List<String> getVendor() {
    return vendor;
}

/**
 * 
 * @param vendor
 *     The vendor
 */
@JsonProperty("vendor")
public void setVendor(List<String> vendor) {
    this.vendor = vendor;
}

public Vendors withVendor(List<String> vendor) {
    this.vendor = vendor;
    return this;
}

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this);
}

更新:

我已经解决了@Morfic,但是怎样才能删除组合中的项目? ,Xq我必须在填充之前清理它们

这为我解决了个性化标题

comboBox.setItemCaptionGenerator( p -> p.replace("_"," "));

0 个答案:

没有答案