Skip to content

Commit

Permalink
Rendering field/property errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Feb 24, 2016
1 parent 74e88f4 commit 804fe27
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
5 changes: 2 additions & 3 deletions rapidoid-gui/src/main/java/org/rapidoid/gui/Field.java
Expand Up @@ -103,8 +103,7 @@ private Var<?> initVar(Item item, Property prop) {
return Models.propertyVar(varName, item, prop.name(), initValue);

} catch (Exception e) {
// FIXME x.errors().put(varName, "Invalid value!");
Log.warn("Invalid value for property: " + prop.name(), e);
prop.errors().add("Invalid value!");
return Models.propertyVar(varName, item, prop.name(), null);
}
}
Expand Down Expand Up @@ -164,7 +163,7 @@ protected Tag field(String name, String desc, FieldType type, Collection<?> opti
inputWrap = layout == FormLayout.HORIZONTAL ? div(inp).class_("col-sm-8") : inp;
}

Tag err = span("").class_("field-error");
Tag err = span(U.join(", ", prop.errors())).class_("field-error");
Tag group = lbl != null ? div(lbl, inputWrap, err) : div(inputWrap, err);
group = group.class_("form-group");
return group;
Expand Down
3 changes: 3 additions & 0 deletions rapidoid-gui/src/main/java/org/rapidoid/model/Property.java
Expand Up @@ -6,6 +6,7 @@
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.util.Set;

/*
* #%L
Expand Down Expand Up @@ -43,4 +44,6 @@ public interface Property extends Serializable {

Object get(Item item);

Set<String> errors();

}
@@ -0,0 +1,17 @@
package org.rapidoid.model.impl;

import org.rapidoid.model.Property;
import org.rapidoid.u.U;

import java.util.Set;

public abstract class AbstractProperty implements Property {

private final Set<String> errors = U.set();

@Override
public Set<String> errors() {
return errors;
}

}
Expand Up @@ -24,14 +24,13 @@
import org.rapidoid.annotation.Since;
import org.rapidoid.commons.Str;
import org.rapidoid.model.Item;
import org.rapidoid.model.Property;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;

@Authors("Nikolche Mihajlovski")
@Since("2.0.0")
public class BeanProperty implements Property {
public class BeanProperty extends AbstractProperty {

private static final long serialVersionUID = 7627370931428864929L;

Expand Down
Expand Up @@ -23,14 +23,13 @@
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.model.Item;
import org.rapidoid.model.Property;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;

@Authors("Nikolche Mihajlovski")
@Since("2.2.0")
public class BuiltInProperty implements Property {
public class BuiltInProperty extends AbstractProperty {

private static final long serialVersionUID = -2697490242616488024L;

Expand Down
Expand Up @@ -25,14 +25,13 @@
import org.rapidoid.lambda.Calc;
import org.rapidoid.lambda.Lmbd;
import org.rapidoid.model.Item;
import org.rapidoid.model.Property;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;

@Authors("Nikolche Mihajlovski")
@Since("2.2.0")
public class CalcProperty implements Property {
public class CalcProperty extends AbstractProperty {

private static final long serialVersionUID = -2697490242616488024L;

Expand Down
Expand Up @@ -202,11 +202,7 @@ private static void postProcessRedirect(Resp resp) {
}
}

public static boolean isDevMode(Req x) {
return Conf.dev();
}

public static final void reload(Req x) {
public static void reload(Req x) {
Map<String, String> sel = U.map("body", PAGE_RELOAD);
x.response().json(U.map("_sel_", sel));
}
Expand All @@ -215,8 +211,8 @@ public static String constructUrl(Req x, String path) {
return (Conf.is("https") ? "https://" : "http://") + x.host() + path;
}

public static boolean hasEvent(Req req) {
return false; // FIXME
public static String getCommand(Req req) {
return isPostReq(req) ? (String) req.data("_cmd", null) : null;
}

}

0 comments on commit 804fe27

Please sign in to comment.