Example usage for org.apache.wicket.validation IValidatable getValue

List of usage examples for org.apache.wicket.validation IValidatable getValue

Introduction

In this page you can find the example usage for org.apache.wicket.validation IValidatable getValue.

Prototype

T getValue();

Source Link

Document

Retrieves the value to be validated.

Usage

From source file:ar.edu.udc.cirtock.view.intranet.negocio.FormularioInsumo.java

License:Apache License

public FormularioInsumo(final PageParameters parameters) {

    super(parameters);

    add(new FeedbackPanel("feedbackErrors", new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR)));
    formulario = new Form("formulario_insumo");

    nombre = new RequiredTextField<String>("nombre", new Model());

    nombre.add(new IValidator<String>() {
        @Override//from ww  w  .j ava  2 s. c  om
        public void validate(IValidatable<String> validatable) {
            String nombre = validatable.getValue().trim().toUpperCase();
            if (!nombre.matches("^[\\w\\s]{3,20}$")) {
                ValidationError error = new ValidationError();
                error.setMessage("El campo 'nombre' no es valido");
                validatable.error(error);
            }
        }

    });
    formulario.add(nombre);

    descripcion = new RequiredTextField<String>("descripcion", new Model());

    descripcion.add(new IValidator<String>() {
        @Override
        public void validate(IValidatable<String> validatable) {
            String descripcion = validatable.getValue().trim().toUpperCase();
            if (!descripcion.matches("^[A-Za-z  ]{3,50}$")) {
                ValidationError error = new ValidationError();
                error.setMessage("El campo 'descripcion' no es valido");
                validatable.error(error);
            }
        }

    });
    formulario.add(descripcion);

    cantidad = new NumberTextField<Integer>("cantidad", new Model());
    cantidad.setType(Integer.class);
    cantidad.add(new IValidator<Integer>() {
        @Override
        public void validate(IValidatable<Integer> validatable) {
            Integer cantidad = validatable.getValue();
            if (cantidad < 0) {
                ValidationError error = new ValidationError();
                error.setMessage("El campo 'cantidad' no es valido");
                validatable.error(error);
            }
        }
    });

    formulario.add(cantidad);

    formulario.add(new Button("enviar") {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public void onSubmit() {
            String desc = (String) descripcion.getModelObject();
            String nomb = (String) nombre.getModelObject();
            Integer cant = cantidad.getModelObject();
            Connection conn = null;
            try {

                conn = CirtockConnection.getConection("cirtock", "cirtock", "cirtock");
                Insumo ins = new Insumo();
                ins.setDescripcion(desc);
                ins.setNombre(nomb);
                ins.setCantidad(cant);
                ins.insert("", conn);

            } catch (CirtockException e) {
                System.out.println("Error al acceder a la base de datos");
            } finally {
                try {
                    conn.close();
                } catch (SQLException e) {
                    ;
                }
            }
            setResponsePage(InsumoPage.class);
        };
    });

    add(formulario);
}

From source file:au.org.theark.lims.web.component.subjectlims.subject.form.SubjectValidator.java

License:Open Source License

public void validate(IValidatable<Long> arg0) {
    if (arg0.getValue() != null) {
        Calendar calendar = Calendar.getInstance();
        int calYear = calendar.get(Calendar.YEAR);
        if (arg0.getValue() > calYear) {
            //TODO : this is doing nothing
            //ValidationError ve = new ValidationError().addMessageKey("error.found");
            // ve.setVariables(vars);
        }/*from   ww  w.  j a  v  a 2 s . com*/
    }

}

From source file:au.org.theark.study.web.component.managestudy.StudyLogoValidator.java

License:Open Source License

public void validate(IValidatable<List<FileUpload>> pValidatable) {

    List<FileUpload> fileUploadList = pValidatable.getValue();

    for (FileUpload fileUploadImage : fileUploadList) {

        String fileExtension = StringUtils.getFilenameExtension(fileUploadImage.getClientFileName());
        ValidationError error = new ValidationError();

        try {//from   ww w  .j  a  v a  2  s . c o  m
            // Check extension ok
            if (fileExtension != null && !fileExtensions.contains(fileExtension.toLowerCase())) {
                error.addMessageKey("study.studyLogoFileType");
                error.setVariable("extensions", fileExtensions.toString());
                pValidatable.error(error);
            } // Check size ok
            else if (fileUploadImage.getSize() > fileSize.bytes()) {
                error.addMessageKey("study.studyLogoFileSize");
                pValidatable.error(error);
            } else {
                // Read image, to work out width and height
                image = new SerializableBufferedImage(ImageIO.read(fileUploadImage.getInputStream()));

                if (image.getHeight() > 100) {
                    error.addMessageKey("study.studyLogoPixelSize");
                    pValidatable.error(error);
                }
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
            error.addMessageKey("study.studyLogoImageError");
            pValidatable.error(error);
        }

    }

}

From source file:ca.travelagency.components.validators.DuplicateValidator.java

License:Apache License

@Override
public void validate(IValidatable<String> validatable) {
    super.validate(validatable);
    T daoEntity = form.getModelObject();
    daoEntity.setName(validatable.getValue());
    if (daoSupport.duplicated(daoEntity)) {
        ValidationError error = new ValidationError(this);
        validatable.error(decorate(error, validatable));
    }/* w ww  . j a  va2 s  .c  o m*/
}

From source file:ca.travelagency.components.validators.PhoneNumberValidator.java

License:Apache License

@Override
public void validate(IValidatable<String> validatable) {
    if (!PhoneNumberUtils.isValid(validatable.getValue())) {
        ValidationError error = new ValidationError(this);
        validatable.error(decorate(error, validatable));
    }//from  w w  w  . ja va2s .  co m
}

From source file:com.alfredmuponda.lostandfound.util.ItemNumberValidator.java

License:Apache License

@Override
public void validate(IValidatable validatable) {
    final String itemNumber = (String) validatable.getValue();
    final String itemType = (String) ITEM_TYPE.getConvertedInput();

    if (itemType.equals("Passport")) {
        if (!PASSPORT.matcher(itemNumber.toUpperCase()).matches())
            error(validatable, "passport-format");
    } else if (itemType.equals("National ID")) {
        if (!NATIONAL_ID.matcher(itemNumber.toUpperCase()).matches())
            error(validatable, "national_id-format");
    } else if (itemType.equals("Drivers Licence")) {
        if (!DRIVERS_LICENSE.matcher(itemNumber.toUpperCase()).matches())
            error(validatable, "drivers_licence-format");
    }/*from w  w  w. j  a v  a  2  s  . com*/
}

From source file:com.alfredmuponda.lostandfound.util.PhoneNumberValidator.java

License:Apache License

@Override
public void validate(IValidatable validatable) {
    final String phoneNumber = (String) validatable.getValue();
    if (!(CELL.matcher(phoneNumber).matches() || LAND.matcher(phoneNumber).matches()))
        error(validatable, "phone_number-format");
}

From source file:com.alfredmuponda.lostandfound.util.UsernameValidator.java

License:Apache License

@Override
public void validate(IValidatable validatable) {
    final String username = (String) validatable.getValue();
    if (!search.verifyUsername(username))
        error(validatable, "username-taken");
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.HeaderConfigUI.java

License:Apache License

/**
 * Create the DataType drop down. When the data type is changed, the offsets will be recalculated and updated.
 *///  w w w .  j  a  va  2s  . c  om
private DropDownChoice<HeaderDataType> getDataTypeDropdown() {
    DropDownChoice<HeaderDataType> dropDown = new DropDownChoice<HeaderDataType>("dataType",
            HeaderDataType.getOptions(), new EnumChoiceRenderer<HeaderDataType>(this)) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (hasErrorMessage()) {
                String style = "background-color:#ffff00;";
                String oldStyle = tag.getAttribute("style");
                tag.put("style", style + oldStyle);
            }
        }
    };

    dropDown.setRequired(true);

    // When the data type is changed, the offsets are recalculated and displayed
    dropDown.add(new OnChangeAjaxBehavior() {
        @SuppressWarnings("unchecked")
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // Recalculate and display the offsets
            updateOffsets(target);

            // Disable value field when DataType does not use a value.
            DropDownChoice<HeaderDataType> choice = (DropDownChoice<HeaderDataType>) getComponent();
            MarkupContainer parent = choice.getParent();
            HeaderDataType dataType = choice.getConvertedInput();
            target.add(
                    parent.get("rawValue").setEnabled(dataType.isHasValue()).setVisible(dataType.isHasValue()));
            target.add(parent.get("size").setEnabled(dataType.isArrayAllowed()));
        }
    });

    dropDown.add(new UniqueListItemValidator<HeaderDataType>(dropDown) {
        @Override
        public String getValue(IValidatable<HeaderDataType> validatable) {
            return String.valueOf(validatable.getValue().name());
        }
    }.setMessageKey("dataType.SpecialTypesValidator").setFilterList(HeaderDataType.getSpecialItemNames()));

    return dropDown;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

private DropDownChoice<TagLengthType> getTagLengthTypeDropDown() {
    DropDownChoice<TagLengthType> dropDown = new DropDownChoice<TagLengthType>("tagLengthType",
            TagLengthType.getOptions(), new EnumChoiceRenderer<TagLengthType>(this)) {
        @Override/*www.j  av a2s  . c o m*/
        public boolean isVisible() {
            return currentMessage.isVariableLength();
        }
    };

    dropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(feedback);
        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            target.add(feedback);
        }
    });

    dropDown.setOutputMarkupId(true);
    dropDown.setOutputMarkupPlaceholderTag(true);

    dropDown.add(new UniqueListItemValidator<TagLengthType>(dropDown) {
        @Override
        public String getValue(IValidatable<TagLengthType> validatable) {
            return String.valueOf(validatable.getValue().name());
        }
    }.setMessageKey("tagLengthType.OnlyOnePackedBasedValidator")
            .setFilterList(new String[] { TagLengthType.PACKET_BASED.name() }));

    return dropDown;
}