Example usage for org.apache.wicket.markup.html.form FormComponent getModel

List of usage examples for org.apache.wicket.markup.html.form FormComponent getModel

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form FormComponent getModel.

Prototype

@SuppressWarnings("unchecked")
default IModel<T> getModel() 

Source Link

Document

Typesafe getter for the model

Usage

From source file:net.ftlines.wicket.validation.bean.ValidationForm.java

License:Apache License

protected void addPropertyValidators() {
    final ValidationContext validation = ValidationContext.get();

    visitChildren(FormComponent.class, new IVisitor<FormComponent<?>, Void>() {
        @SuppressWarnings({ "rawtypes", "unchecked" })
        @Override/*w w  w . j a va 2  s. c  o  m*/
        public void component(FormComponent<?> component, IVisit<Void> visit) {
            if (!hasPropertyValidator(component)) {
                IProperty property = validation.resolveProperty(component.getModel());
                if (property != null) {
                    component.add(new PropertyValidator(null, groups));
                }
            }
        }
    });
}

From source file:org.opensingular.form.wicket.WicketBuildContext.java

License:Apache License

protected static String resolveSimpleLabel(FormComponent<?> formComponent) {
    IModel<?> model = formComponent.getModel();
    if (model instanceof ISInstanceAwareModel<?>) {
        SInstance instancia = ((ISInstanceAwareModel<?>) model).getSInstance();
        return instancia.asAtr().getLabel();
    }/*  ww  w.j  a v a 2s  . com*/
    return "[" + formComponent.getId() + "]";
}

From source file:org.opensingular.form.wicket.WicketBuildContext.java

License:Apache License

/**
 * Calcula o caminho completo de labels do campo, concatenando os nomes separados por ' > ',
 * para ser usado em mensagens de erro.//from  w  w  w  . j a  va2s . com
 * Exemplo: "O campo 'Contato > Endereos > Endereo > Logradouro'  obrigatrio"
 */
protected static String resolveFullPathLabel(FormComponent<?> formComponent) {
    IModel<?> model = formComponent.getModel();
    if (model instanceof ISInstanceAwareModel<?>) {
        SInstance instancia = ((ISInstanceAwareModel<?>) model).getSInstance();
        List<String> labels = new ArrayList<>();
        while (instancia != null) {
            labels.add(instancia.asAtr().getLabel());
            instancia = instancia.getParent();
        }
        labels.removeIf(it -> Strings.defaultIfEmpty(it, "").trim().isEmpty());
        Collections.reverse(labels);
        if (!labels.isEmpty())
            return Strings.join(" > ", labels);
    }
    return "[" + formComponent.getId() + "]";
}