Java Code Examples for org.apache.struts.action.ActionErrors#size()

The following examples show how to use org.apache.struts.action.ActionErrors#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionEditAction.java    From unitime with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
private void setHolidays(
		HttpServletRequest request,
		SessionEditForm sessionEditForm,
		ActionErrors errors,
		Session sessn) throws ParseException {
	
	sessionEditForm.validateDates(errors);
	
	if (errors.size()==0) {			
		setSessionData(request, sessionEditForm, sessn);
		request.setAttribute("Sessions.holidays", sessn.getHolidaysHtml());		
	}
	else
		saveErrors(request, new ActionMessages(errors));
}
 
Example 2
Source File: CreateProfileWizardAction.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private boolean validateInput(DynaActionForm form, List fieldNames,
        RequestContext ctx) {
    ActionErrors errs =
            RhnValidationHelper.validateDynaActionForm(this, form, fieldNames);
    boolean retval = errs.size() == 0;

    if (!retval) {
        saveMessages(ctx.getRequest(), errs);
    }
    return retval;
}
 
Example 3
Source File: InstructorEditForm.java    From unitime with Apache License 2.0 5 votes vote down vote up
/** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(
	ActionMapping mapping,
	HttpServletRequest request) {
	
       ActionErrors errors = new ActionErrors();

       if (op.equals(MSG.actionLookupInstructor())) {
   		if ( (fname==null || fname.trim().length()==0) 
   		        && (lname==null || lname.trim().length()==0) 
   		        && (careerAcct==null || careerAcct.trim().length()==0) ) {
			errors.add("fname", 
                    new ActionMessage("errors.generic", MSG.errorSupplyInfoForInstructorLookup()) );
   		}
   		
   		return errors;
       }
       
       if (!screenName.equalsIgnoreCase("instructorPref") ) {
				
		if (lname == null || lname.trim().equals("")) {
			errors.add("Last Name", 
                    new ActionMessage("errors.generic", MSG.errorRequiredLastName()) );
		}
       }
       
	if (errors.size() == 0) {
		return super.validate(mapping, request); 
	} else {
		return errors;
	}
}
 
Example 4
Source File: CreateProfileWizardAction.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
private boolean validateInput(DynaActionForm form, List fieldNames,
        RequestContext ctx) {
    ActionErrors errs =
            RhnValidationHelper.validateDynaActionForm(this, form, fieldNames);
    boolean retval = errs.size() == 0;

    if (!retval) {
        saveMessages(ctx.getRequest(), errs);
    }
    return retval;
}
 
Example 5
Source File: ScheduleKickstartWizardAction.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
protected boolean validateBondSelections(DynaActionForm form,
        RequestContext ctx) {
    if (!StringUtils.isBlank(form.getString(HIDDEN_BOND_SLAVE_INTERFACES))) {
        form.set(BOND_SLAVE_INTERFACES,
                form.getString(HIDDEN_BOND_SLAVE_INTERFACES).split(","));
    }

    String[] slaves = (String[]) form.get(BOND_SLAVE_INTERFACES);
    ActionErrors errors = new ActionErrors();

    // if we are trying to create a bond but have not specified a name or at
    // least one slave interface
    if (form.getString(BOND_TYPE).equals(CREATE_BOND_VALUE) &&
            (StringUtils.isBlank(form.getString(BOND_INTERFACE)) ||
                    slaves.length < 1 || StringUtils.isBlank(slaves[0]))) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                "kickstart.bond.not.defined.jsp"));
    }

    final String ipv4addressPattern = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
            "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
            "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
            "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";

    /*
     * The IPv6 address regex was created by Stephen Ryan at Dartware
     * and taken from this forum: http://forums.intermapper.com/viewtopic.php?t=452
     * It is licenced under a Creative Commons Attribution-ShareAlike 3.0 Unported
     * License. We can freely use it in (even in commercial products) as long as
     * we attribute its creation to him, so don't remove this message.
     */
    final String ipv6addressPattern = "^(((?=(?>.*?::)(?!.*::)))(::)?([0-9A-" +
            "F]{1,4}::?){0,5}|([0-9A-F]{1,4}:){6})(\\2([0-9A-F]{1,4}(::?|$))" +
            "{0,2}|((25[0-5]|(2[0-4]|1\\d|[1-9])?\\d)(\\.|$)){4}|[0-9A-F]{1," +
            "4}:[0-9A-F]{1,4})(?<![^:]:|\\.)\\z";

    if (form.getString(BOND_STATIC).equals(STATIC_BOND_VALUE)) {
        String address = form.getString(BOND_IP_ADDRESS);
        String netmask = form.getString(BOND_NETMASK);
        String gateway = form.getString(BOND_GATEWAY);

        if (!address.matches(ipv4addressPattern) &&
                !address.matches(ipv6addressPattern)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                    "kickstart.bond.bad.ip.address.jsp"));
        }

        if (!netmask.matches(ipv4addressPattern) &&
                !netmask.matches(ipv6addressPattern)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                    "kickstart.bond.bad.netmask.jsp"));
        }

        if (!gateway.matches(ipv4addressPattern) &&
                !gateway.matches(ipv6addressPattern)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                    "kickstart.bond.bad.ip.address.jsp"));
        }
    }

    if (errors.size() > 0) {
        addErrors(ctx.getRequest(), errors);
        return false;
    }
    return true;
}
 
Example 6
Source File: InstructionalOfferingConfigEditForm.java    From unitime with Apache License 2.0 4 votes vote down vote up
/**
 * Checks input fields 
 * @param request
 * @param errors
 * @param sic
 * @param lblMax
 */
private void checkInputfields (
        HttpServletRequest request, 
        ActionErrors errors, 
        SimpleItypeConfig sic, 
        String lblMax,
        boolean unlimited ) {
    
    int mxlpc = sic.getMaxLimitPerClass();
    int mnlpc = sic.getMinLimitPerClass();
    int nc = sic.getNumClasses();
    int nr = sic.getNumRooms();
    int mpw = sic.getMinPerWeek();
    float rc = sic.getRoomRatio();
    
    String lblSubpart = " for <u>" + sic.getItype().getDesc() + "</u>";
    long indx = sic.getId();
    int ct = errors.size();
    
    if (!unlimited) {
     if(mxlpc<0) 
         errors.add("subparts"+indx, new ActionMessage("errors.integerGtEq", lblMax + " per class" + lblSubpart, "0"));
     else {
         if(mxlpc>limit && ApplicationProperty.ConfigEditCheckLimits.isTrue()) {
             if (nc>1)
                 errors.add("subparts"+indx, new ActionMessage("errors.integerLtEq", lblMax + " per class of " + mxlpc + lblSubpart, " Configuration limit of "+limit ));
         }
         else {
             
             if (request.getParameter("varLimits")==null) {
                 mnlpc = mxlpc;
             }
             
             if(mnlpc<0)
                 errors.add("subparts"+indx, new ActionMessage("errors.integerGtEq", "Min limit per class" + lblSubpart, "0"));
             if(mnlpc>mxlpc)
                 errors.add("subparts"+indx, new ActionMessage("errors.integerLtEq", "Min limit per class" + lblSubpart, "Max limit per class"));
             
             // Check no. of classes
             if(nc<=0)
                 errors.add("subparts"+indx, new ActionMessage("errors.integerGt", "Number of classes" + lblSubpart, "0" ));
             
             if(nc>ApplicationProperty.SubpartMaxNumClasses.intValue())
                 errors.add("subparts"+indx, new ActionMessage("errors.integerLtEq", "Number of classes" + lblSubpart, ApplicationProperty.SubpartMaxNumClasses.value() ));

             // Check no. of rooms
             if(nr<0)
                 errors.add("subparts"+indx, new ActionMessage("errors.integerGtEq", "Number of rooms" + lblSubpart, "0" ));
             
             // Check min per week
             if(mpw<0)
                 errors.add("subparts"+indx, new ActionMessage("errors.integerGtEq", "Minutes per week" + lblSubpart, "0" ));
             if(mpw==0 && nr!=0)
                 errors.add("subparts"+indx, new ActionMessage("errors.generic", "Minutes per week " + lblSubpart + " can be 0 only if number of rooms is 0" ));
                 
             // Check room ratio
             if(rc<0)
                 errors.add("subparts"+indx, new ActionMessage("errors.integerGtEq", "Room ratio" + lblSubpart, "0.0" ));
         }
     }               
    }
    else {
        
        // Check no. of classes
        if(nc<=0)
            errors.add("subparts"+indx, new ActionMessage("errors.integerGt", "Number of classes" + lblSubpart, "0" ));
    	
        if(nc>ApplicationProperty.SubpartMaxNumClasses.intValue())
            errors.add("subparts"+indx, new ActionMessage("errors.integerLtEq", "Number of classes" + lblSubpart, ApplicationProperty.SubpartMaxNumClasses.value() ));

        if(mpw<0)
            errors.add("subparts"+indx, new ActionMessage("errors.integerGtEq", "Minutes per week" + lblSubpart, "0" ));
    }
    
    if (errors.size()>ct)
        sic.setHasError(true);
}
 
Example 7
Source File: SessionEditForm.java    From unitime with Apache License 2.0 4 votes vote down vote up
public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
	ActionErrors errors = new ActionErrors();
	
	// Check data fields
	if (academicInitiative==null || academicInitiative.trim().length()==0) 
		errors.add("academicInitiative", new ActionMessage("errors.required", "Academic Initiative"));
	
	if (academicTerm==null || academicTerm.trim().length()==0) 
		errors.add("academicTerm", new ActionMessage("errors.required", "Academic Term"));

	if (academicYear==null || academicYear.trim().length()==0) 
		errors.add("academicYear", new ActionMessage("errors.required", "Academic Year"));
	else {
		try {
			Integer.parseInt(academicYear); 
		}
		catch (Exception e) {
			errors.add("academicYear", new ActionMessage("errors.numeric", "Academic Year"));
		}
	}
	
	validateDates(errors);
	
	if (getStatus()==null || getStatus().trim().length()==0) 
		errors.add("status", new ActionMessage("errors.required", "Session Status"));
	
	
	// Check for duplicate academic initiative, year & term
	if (errors.size()==0) {
		Session sessn = Session.getSessionUsingInitiativeYearTerm(academicInitiative, academicYear, academicTerm);
		if (session.getSessionId()==null && sessn!=null)
			errors.add("sessionId", new ActionMessage("errors.generic", "An academic session for the initiative, year and term already exists"));
			
		if (session.getSessionId()!=null && sessn!=null) {
			if (!session.getSessionId().equals(sessn.getSessionId()))
				errors.add("sessionId", new ActionMessage("errors.generic", "Another academic session for the same initiative, year and term already exists"));
		}
	}
	
	return errors;
}
 
Example 8
Source File: ScheduleKickstartWizardAction.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
protected boolean validateBondSelections(DynaActionForm form,
        RequestContext ctx) {
    if (!StringUtils.isBlank(form.getString(HIDDEN_BOND_SLAVE_INTERFACES))) {
        form.set(BOND_SLAVE_INTERFACES,
                form.getString(HIDDEN_BOND_SLAVE_INTERFACES).split(","));
    }

    String[] slaves = (String[]) form.get(BOND_SLAVE_INTERFACES);
    ActionErrors errors = new ActionErrors();

    // if we are trying to create a bond but have not specified a name or at
    // least one slave interface
    if (form.getString(BOND_TYPE).equals(CREATE_BOND_VALUE) &&
            (StringUtils.isBlank(form.getString(BOND_INTERFACE)) ||
                    slaves.length < 1 || StringUtils.isBlank(slaves[0]))) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                "kickstart.bond.not.defined.jsp"));
    }

    final String ipv4addressPattern = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
            "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
            "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
            "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";

    /*
     * The IPv6 address regex was created by Stephen Ryan at Dartware
     * and taken from this forum: http://forums.intermapper.com/viewtopic.php?t=452
     * It is licenced under a Creative Commons Attribution-ShareAlike 3.0 Unported
     * License. We can freely use it in (even in commercial products) as long as
     * we attribute its creation to him, so don't remove this message.
     */
    final String ipv6addressPattern = "^(((?=(?>.*?::)(?!.*::)))(::)?([0-9A-" +
            "F]{1,4}::?){0,5}|([0-9A-F]{1,4}:){6})(\\2([0-9A-F]{1,4}(::?|$))" +
            "{0,2}|((25[0-5]|(2[0-4]|1\\d|[1-9])?\\d)(\\.|$)){4}|[0-9A-F]{1," +
            "4}:[0-9A-F]{1,4})(?<![^:]:|\\.)\\z";

    if (form.getString(BOND_STATIC).equals(STATIC_BOND_VALUE)) {
        String address = form.getString(BOND_IP_ADDRESS);
        String netmask = form.getString(BOND_NETMASK);
        String gateway = form.getString(BOND_GATEWAY);

        if (!address.matches(ipv4addressPattern) &&
                !address.matches(ipv6addressPattern)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                    "kickstart.bond.bad.ip.address.jsp"));
        }

        if (!netmask.matches(ipv4addressPattern) &&
                !netmask.matches(ipv6addressPattern)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                    "kickstart.bond.bad.netmask.jsp"));
        }

        if (!gateway.matches(ipv4addressPattern) &&
                !gateway.matches(ipv6addressPattern)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                    "kickstart.bond.bad.ip.address.jsp"));
        }
    }

    if (errors.size() > 0) {
        addErrors(ctx.getRequest(), errors);
        return false;
    }
    return true;
}