示例#1
0
 public String generateValueList(String list) {
   if (StringUtil.isEmpty(list)) {
     return "";
   }
   StringBuilder b = new StringBuilder();
   b.append("<ul>");
   String[] values = StringUtil.splitString(list, '\n');
   for (int i = 0; i < values.length; i++) {
     String s = values[i];
     if (StringUtil.isNotEmpty(s)) {
       String name = s;
       String desc = null;
       int pos = s.indexOf('|');
       if (pos >= 0) {
         name = s.substring(0, pos);
         desc = s.substring(pos + 1);
       }
       b.append("<li>");
       b.append("<b>");
       b.append(TextUtil.toXMLString(name));
       b.append("</b>");
       if (StringUtil.isNotEmpty(desc)) {
         b.append(": ");
         b.append(TextUtil.toXMLString(desc));
       }
       b.append("</li>");
     }
   }
   b.append("</ul>");
   return b.toString();
 }
  public Object getTypeAheadMarkupValue(UITypeAhead typeAhead) {
    IPickerData dp = getDataProvider();
    if (dp != null) {
      int max = typeAhead.getMaxValues();
      if (max <= 0) {
        max = Integer.MAX_VALUE;
      }
      max = Math.min(max, 50); // Put a limit for now...

      // Read the entry
      String value = getStartsValue(FacesContext.getCurrentInstance(), typeAhead, true);
      // Use the Key and not the startKey to filter the right set of
      // values
      int source = 0; // Always the first source?
      SimplePickerOptions options = new SimplePickerOptions(source, 0, max, value, null, null);
      IPickerResult r = dp.readEntries(options);
      List<IPickerEntry> entries = r.getEntries();

      StringBuilder b = new StringBuilder();
      b.append("<ul>"); // $NON-NLS-1$
      int sz = entries.size();
      for (int i = 0; i < sz; i++) {
        IPickerEntry e = entries.get(i);
        Object val = e.getValue();
        if (value != null) {
          b.append("<li>"); // $NON-NLS-1$
          Object label = e.getLabel();
          if (label != null) {
            // Note, use double-quotes instead of single-quotes for
            // attributes, so as to be XHTML-compliant.
            b.append("<span class=\"informal\">"); // $NON-NLS-1$
            b.append(TextUtil.toXMLString(label.toString()));
            b.append("</span>"); // $NON-NLS-1$
          }
          b.append(TextUtil.toXMLString(val.toString()));
          b.append("</li>"); // $NON-NLS-1$
        }
      }
      b.append("</ul>"); // $NON-NLS-1$
      return b.toString();
    }
    return null;
  }