@Override public void validate() throws Exception { int countAddressees = 0; // Users Integer userCount = getParameterInteger("users"); for (int i = 0; i < userCount; i++) { Pair<String, String> kvp = getParameterTypeAhead("user_" + i); if (kvp != null && !Util.isEmpty(kvp.getKey())) { User u = UserStore.getInstance().loadByLoginName(kvp.getKey()); if (u == null) { throw new WebFormException( "user_" + i, getString("admin:AdHocMessage.InvalidLoginName", kvp.getValue())); } countAddressees++; } } // Groups Integer groupCount = getParameterInteger("groups"); for (int i = 0; i < groupCount; i++) { Pair<String, String> kvp = getParameterTypeAhead("group_" + i); if (kvp != null && !Util.isEmpty(kvp.getKey())) { UserGroup lg = UserGroupStore.getInstance().loadByName(kvp.getKey()); if (lg == null) { throw new WebFormException( "group_" + i, getString("admin:AdHocMessage.InvalidGroupName", kvp.getValue())); } countAddressees++; } } // Check number of recipients if (countAddressees == 0) { throw new WebFormException( new String[] {"groups", "users"}, getString("admin:AdHocMessage.NoRecipients")); } // Channels int countChannels = 0; for (String channel : Channel.getAll()) { if (isParameter(channel)) { countChannels++; } } if (countChannels == 0) { throw new WebFormException(Channel.getAll(), getString("common:Errors.MissingField")); } // Subject and body boolean mandateSubject = isParameter(Channel.EMAIL); validateParameterString("subject", mandateSubject ? 1 : 0, 128); String html = getParameterRichEdit("body"); if (Util.isEmptyHTML(html)) { throw new WebFormException("body", getString("common:Errors.MissingField")); } // Date validateParameterDate("date"); }