Пример #1
0
  public String create() {
    boolean valid = true;
    if (pollEJB.findByTitle(poll.getTitle()) != null) {
      // TODO: slugify/normalize poll title
      ControlUtil.reportError("title", "Poll with this title already exists");
      valid = false;
    }

    Set<String> descriptions =
        Sets.newHashSet(Splitter.on(";").trimResults().omitEmptyStrings().split(answers));
    if (descriptions.size() < 2) {
      ControlUtil.reportError("answers", "At least two answers should be specified");
      valid = false;
    }

    if (!valid) {
      return null;
    }

    poll.setAuthor(loginControl.getCurrentUser());
    pollEJB.persist(poll);
    for (String description : descriptions) {
      answerEJB.persist(new Answer(poll, description));
    }
    //        pollEJB.merge(poll);
    return "/polls/view.xhtml?id=" + poll.getId() + "&faces-redirect=true";
  }
Пример #2
0
  public static StringBuffer makeConditionCtrl(SysQueryFieldBO bo, Object def_V) {
    StringBuffer sb = new StringBuffer();
    if (def_V == null) {
      def_V = "";
    }
    String ctrlType = bo.getCtrltype();
    if (ctrlType == null) {
      sb.append(bo.getId().getColalias()).append("没有配置控件类型!");
      return sb;
    }
    if ("none".equals(ctrlType)) {

    } else if ("text".equals(ctrlType)) {
      sb.append("<input type='text' name='").append(bo.getId().getColalias()).append("'");
      sb.append(" value='").append(def_V).append("'");
      sb.append(" value='").append(def_V).append("'");
      int maxlength = bo.getCtrllen() == null ? DEFAULT_MAXLEN : bo.getCtrllen().intValue();
      int width = 0;
      width = bo.getDisplen() == null ? DEFAULT_DISPLEN : bo.getDisplen().intValue();
      width = width * FONTSIZE;
      width = width > MAX_DISPLEN ? MAX_DISPLEN : width;
      width = width < MIN_DISPLEN ? MIN_DISPLEN : width;
      sb.append(" maxlength='").append(maxlength).append("'");
      sb.append(" style='width:").append(width).append("px;'");
      sb.append("></input>");
    } else if ("select".equals(ctrlType)) {
      sb.append("<select ").append("name='").append(bo.getId().getColalias()).append("'>");
      sb.append(ControlUtil.makeOptionsByDict(bo.getCtrltype(), def_V.toString(), true));
      sb.append("</select>");
    } else {
      // TODO 其他控件,例如calender
    }
    return sb;
  }
Пример #3
0
 private static Object makeTdWrapedSelect(
     String value, String ctrlname, String dictType, boolean nullable) {
   value = StringUtil.trim(value);
   StringBuffer ret = new StringBuffer();
   ret.append("<td class='output'>");
   ret.append("<select ").append("name='").append(ctrlname).append("'>");
   ret.append(ControlUtil.makeOptionsByDict(dictType, value, nullable));
   ret.append("</select>");
   ret.append("</td>");
   return ret;
 }
Пример #4
0
 public static StringBuffer inputHiddens(Map<String, Object> param) {
   StringBuffer sb = new StringBuffer();
   Iterator<Entry<String, Object>> it = param.entrySet().iterator();
   Entry<String, Object> entry;
   while (it.hasNext()) {
     entry = it.next();
     // sb.append("<input type ='hidden'");
     // sb.append(" name = '"+entry.getKey()+"'");
     // sb.append(" value = '"+entry.getValue()+"'");
     // sb.append("></input>");
     sb.append(ControlUtil.makeInput(entry.getValue(), entry.getKey(), "hidden"));
   }
   return sb;
 }
Пример #5
0
 private static StringBuffer makeTdWrapedInput(String value, String ctrlname, boolean editable) {
   value = StringUtil.trim(value);
   String type;
   StringBuffer ret = new StringBuffer();
   ret.append("<td class='output'>");
   if (editable) {
     type = "text";
   } else {
     type = "hidden";
     ret.append(value);
   }
   ret.append(ControlUtil.makeInput(value, ctrlname, type));
   ret.append("</td>");
   return ret;
 }