This commit is contained in:
Francesco 2023-09-25 15:41:10 +02:00
parent ef99c3e0ed
commit d5371b307d
4 changed files with 59 additions and 13 deletions

View File

@ -20,6 +20,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
@ -201,6 +202,7 @@ public class DbAdmin {
ManyToMany manyToMany = f.getAnnotation(ManyToMany.class);
ManyToOne manyToOne = f.getAnnotation(ManyToOne.class);
OneToOne oneToOne = f.getAnnotation(OneToOne.class);
Lob lob = f.getAnnotation(Lob.class);
String fieldName = determineFieldName(f);
@ -212,6 +214,10 @@ public class DbAdmin {
DbFieldType fieldType = null;
try {
fieldType = DbFieldType.fromClass(f.getType());
if (fieldType != null && lob != null && fieldType == DbFieldType.STRING) {
fieldType = DbFieldType.TEXT;
}
} catch (DbAdminException e) {
// If failure, we try to map a relationship on this field
}

View File

@ -124,6 +124,10 @@ public class DbField {
return format;
}
public boolean isText() {
return type == DbFieldType.TEXT;
}
@Override
public String toString() {
return "DbField [name=" + dbName + ", javaName=" + javaName + ", type=" + type + ", field=" + field

View File

@ -163,6 +163,28 @@ public enum DbFieldType {
return List.of(CompareOperator.CONTAINS, CompareOperator.STRING_EQ);
}
},
TEXT {
@Override
public String getHTMLName() {
return "textarea";
}
@Override
public Object parseValue(Object value) {
return value;
}
@Override
public Class<?> getJavaClass() {
return String.class;
}
@Override
public List<CompareOperator> getCompareOperators() {
return List.of(CompareOperator.CONTAINS, CompareOperator.STRING_EQ);
}
},
BOOLEAN {
@Override
public String getHTMLName() {

View File

@ -43,19 +43,33 @@
</div>
</th:block>
<th:block th:unless="${field.isForeignKey()}">
<input th:if="${!field.isBinary()}" placeholder="NULL" th:type="${field.getType().getHTMLName()}"
th:name="${field.getName()}"
th:value="
${create ? (params != null ? params.getOrDefault(field.getName(), '') : '')
: (object != null ? object.get(field).getValue() : '' )}
"
class="form-control" th:id="|__id_${field.getName()}|"
th:classAppend="${field.isPrimaryKey() && object != null ? 'disable' : ''}"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
step="any"
oninvalid="this.setCustomValidity('This field is not nullable.')"
oninput="this.setCustomValidity('')">
<th:block th:if="${field.isText()}">
<textarea placeholder="NULL"
th:name="${field.getName()}"
th:text="
${create ? (params != null ? params.getOrDefault(field.getName(), '') : '')
: (object != null ? object.get(field).getValue() : '' )}
"
class="form-control" th:id="|__id_${field.getName()}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
oninvalid="this.setCustomValidity('This field is not nullable.')"
rows="5"
oninput="this.setCustomValidity('')"></textarea>
</th:block>
<th:block th:if="${!field.isText()}">
<input th:if="${!field.isBinary()}" placeholder="NULL" th:type="${field.getType().getHTMLName()}"
th:name="${field.getName()}"
th:value="
${create ? (params != null ? params.getOrDefault(field.getName(), '') : '')
: (object != null ? object.get(field).getValue() : '' )}
"
class="form-control" th:id="|__id_${field.getName()}|"
th:classAppend="${field.isPrimaryKey() && object != null ? 'disable' : ''}"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
step="any"
oninvalid="this.setCustomValidity('This field is not nullable.')"
oninput="this.setCustomValidity('')">
</th:block>
<!--/*--> Binary field <!--*/-->
<th:block th:if="${field.isBinary()}">