ralscha / extclassgenerator Goto Github PK
View Code? Open in Web Editor NEWExt JS code generator. Creating model js classes from java classes
License: Apache License 2.0
Ext JS code generator. Creating model js classes from java classes
License: Apache License 2.0
Hi,
I just discovered what I think could be a bug.
I have a
@Pattern(regexp="^/\\w.*\\.\\w.*")
on a java Json object
The generator produces
matcher : /^/\w.*\.\w.*/
instead it should be
matcher : /^\/\w.*\.\w.*/
when I test the pattern with http://regexpal.com/ with following ones
^\/\w.*\.\w.* or ^/\w.*\.\w.*
both works, it matches what I want
/index.html
With the second pattern it fails with yuicompressor 2.4.7, I don' pretend familiarity with regular expression, but I guess the slash "/" should be escaped
Ext JS 5 added a new unique properties to the field config
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.field.Field-cfg-unique
Ext Js 5 warns when using validator and not specify the validators in the requires config option
[W] [Ext.Loader] Synchronously loading 'Ext.data.validator.Presence'; consider adding Ext.require('Ext.data.validator.Presence') above Ext.onReady Util.js?_dc=1403671653161:692
[W] [Ext.Loader] Synchronously loading 'Ext.data.validator.Email'; consider adding Ext.require('Ext.data.validator.Email') above Ext.onReady Util.js?_dc=1403671653161:692
Example of a model with requires
Ext.define("SimpleApp.model.User", {
extend : "Ext.data.Model",
requires : ["Ext.data.validator.Presence", "Ext.data.validator.Email"],
fields : [ {
name : "id",
type : "string"
}, {
name : "firstName",
type : "string",
convert : null
}, {
name : "lastName",
type : "string",
convert : null,
validators : [ {
type : "presence"
} ]
}, {
name : "email",
type : "string",
convert : null,
validators : [ {
type : "email"
} ]
}, {
name : "department",
type : "string",
convert : null
} ]
});
By default the model generator tries to figure out the type of a field when no ModelField annotation is present.
The performance can be improved when the server sends the data in the correct format and the type is set to 'auto'. For 'auto'-fields Ext Js skips the per-field processing.
To use this pattern every field has to be annotated with @ModelField(type = ModelType.AUTO)
. This is cumbersome if the bean contains a lot of fields.
We could improve this situation by adding a autodetectTypes boolean to the Model annotation. By default this attribute is true which corresponds to the current behaviour.
When this attribute is set to false, the type of every field that is not annotated with ModelField is set to auto.
Although int and float are valid values for the type property, the generator should write integer and number instead. This makes the link to the new "classes" Ext.data.field.Integer and Ext.data.field.Number more obvious.
This change only affects the Ext Js 5 output.
Hi,
I just discovered a bug related to your introduced feature ModelValidation with ExtJs 4.2.2
ch.rasc.extclassgenerator.validation.GenericValidation
I have a config such as
@ModelValidation(propertyName = "prop", value = ModelValidationType.GENERIC, parameters={@ModelValidationParameter(name="type", value= "notUnique"), @ModelValidationParameter(name="update", value= "true")})
JavaScript code generated is
validations : [ {
type : "notUnique",
field : "prop",
type : "notUnique",
update : "true"
}]
type is duplicated
the bug is coming from following code in AbstractValidation.createValidation
case GENERIC:
String type = getParameterValue(modelValidationAnnotation.parameters(), "type");
Map<String, Object> options = new LinkedHashMap<String, Object>();
for (ModelValidationParameter parameter : modelValidationAnnotation.parameters()) {
options.put(parameter.name(), parameter.value());
}
return new GenericValidation(type, propertyName, options);
it should be instead
case GENERIC:
String type = getParameterValue(modelValidationAnnotation.parameters(), "type");
Map<String, Object> options = new LinkedHashMap<String, Object>();
for (ModelValidationParameter parameter : modelValidationAnnotation.parameters()) {
if(!parameter.name().equals("type"))
options.put(parameter.name(), parameter.value());
}
return new GenericValidation(type, propertyName, options);
or whatever other way you want, to not include this parameter name ' type'
Thanks for this implementation, and give opportunity to developers to add their own validations rules.
According to the extjs 5 upgrade guide writeAllFields is now false by default.
http://docs.sencha.com/extjs/5.0.0/whats_new/5.0/extjs_upgrade_guide.html
But most of the time I need all fields sent from the client to the server. I need a way to set this config option to true. Add attribute in the Model annotation
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.field.Field-cfg-critical
Add new critical
attribute to the ModelField annotation.
I want to use Sourcegraph for extclassgenerator code search, browsing, and usage examples. Can an admin enable Sourcegraph for this repository? Just go to https://sourcegraph.com/github.com/ralscha/extclassgenerator. (It should only take 30 seconds.)
Thank you!
Ext JS 5 added a new config option versionProperty in the Model object.
Similar to idProperty
... but the class generator does not scan methods for annotations, only types and fields. Not sure which needs to be updated the ModelField annotation or the class generator ;-)
This is related to #28 . Sorry it took me some time to detect this.
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.Model-cfg-clientIdProperty
Set clientIdProperty config option on the model and on the proxy writer config.
I want to use Sourcegraph for extclassgenerator code search, browsing, and usage examples. Can an admin enable Sourcegraph for this repository? Just go to https://sourcegraph.com/github.com/ralscha/extclassgenerator. (It should only take 30 seconds.)
Thank you!
Hello,
ModelGenerator still refers to javax.servlet instead of jakarta.servlet in version 2.0.0.
The field config option useNull does not exist in Ext Js 5.
It was renamed allowNull.
Touch 2 allows both but useNull is deprecated.
Ext Js 4 only supports useNull.
Ext JS 5 changed the way validators are configured. The config option is now called validators and the field name is the key.
Ext JS 5
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.Model-cfg-validators
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string' },
{ name: 'age', type: 'int' },
{ name: 'phone', type: 'string' },
{ name: 'gender', type: 'string' },
{ name: 'username', type: 'string' },
{ name: 'alive', type: 'boolean', defaultValue: true }
],
validators: {
age: 'presence',
name: { type: 'length', min: 2 },
gender: { type: 'inclusion', list: ['Male', 'Female'] },
username: [
{ type: 'exclusion', list: ['Admin', 'Operator'] },
{ type: 'format', matcher: /([a-z]+)[0-9]{2,3}/i }
]
}
});
Ext JS 4
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'phone', type: 'string'},
{name: 'gender', type: 'string'},
{name: 'username', type: 'string'},
{name: 'alive', type: 'boolean', defaultValue: true}
],
validations: [
{type: 'presence', field: 'age'},
{type: 'length', field: 'name', min: 2},
{type: 'inclusion', field: 'gender', list: ['Male', 'Female']},
{type: 'exclusion', field: 'username', list: ['Admin', 'Operator']},
{type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/}
]
});
ExtJS 5 has a new way of declaring model associations using a reference attribute of a model field. Are there any plans to support it? (Does this even work?)
Add new attribute extend to the Model annotation. This allows an application to overwrite the default 'Ext.data.Model'.
This could be useful because in ext js 5 there is this new schema concept. A "super class" can specify the schema config and all the model "classes" inherit this.
Ext.define('MyApp.model.Base', {
extend: 'Ext.data.Model',
schema: {
namespace: 'MyApp.models'
}
});
Ext.define("MyApp.model.Author", {
extend : "MyApp.models.Base",
.....
Consider
adding support for schemas and defining associations in the new way:
https://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.data.schema.Association
Hi,
I use the ModelAnnotationProcessor within Intellij IDEA using the "gradle-apt-plugin", the console print some error message:
Warning: No SupportedSourceVersion annotation found on ch.rasc.extclassgenerator.ModelAnnotationProcessor, returning RELEASE_6.
Warning: 来自注释处理程序 'ch.rasc.extclassgenerator.ModelAnnotationProcessor' 的受支持 source 版本 'RELEASE_6' 低于 -source '1.8'
注: Running ModelAnnotationProcessor
Error com.jdsoft.studio.Author
Error: com.jdsoft.studio.Book
Error: com.jdsoft.studio.model.Project
Error: com.jdsoft.studio.model.SampleProject
注: Running ModelAnnotationProcessor
Warning: 以下选项未被任何处理程序识别: '[createBaseAndSubclass, surroundApiWithQuotes]'.
Then i debug the gradle,i found the inner exception is ClassNotFoundException,see pickure below:
It seems like the classloader can't find the my Model class ,how shoud i handle this problem?
Thanks!
In Ext Js 5 the range validation is now a builtin validation.
http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.data.validator.Range
Need a way to specify the identifier config property on the model
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.Model-cfg-identifier
Hi,
It seems that the @ModelAssociation has not support ExtJ6.2.
This is my generated model define.
The Entity has many EntityAttribute
In client the Entity instance has a "attributes" method already,but the Entity can't load nesting EntityAttribute data.
Studio.model.entity.Entity.load("com.jdsoft.entity.TestEntity",{callback:function(ent){window.ent=ent}})
'ent.attributes().getCount()'
the ent.attributes().getCount() return 0;
I changed the association define using Ext6 format, it will load the nesting data.
I want know that the @ModelAssociation can used in ExtJS6 ? If not, is there a plan to support Extjs6?
Here is a quote from this blog post: Deep Dive Into Ext JS 5 Data
"While eliminating field declarations is convenient at times and an easy way to eliminate per-field processing, this is not always possible. For example, the defaultValue and convert configs require processing for the field on which they are declared. When adding validators and references on fields, you can still avoid this processing by using the default field type “auto” (and avoiding the configs just mentioned)."
In the current release the generator tries to figure out the type of the field when the type AUTO is used
@ModelField(type = ModelType.AUTO)
public String name;
For this example the generator writes this field config
{name:"name",type:"string"}
We should change this so the type from the annotation is always used and only if the attribute is omitted autodetect the type.
'auto' is the default type, therefore the generator does not need to write the type config in this case.
Is there a reason why annotations on property getters are not supported? It would allow generating model classes off an interface with JSR-303 annotations on it rather than the implementation. Hence, allowing sharing of the interface and validation constraints, but, not the implementation of the interface.
For example:
@Model
public interface User {
UUID getId();
@NotEmpty
@Email
@Size(max=128)
String getEmail();
...
}
Introduce three new field annotations
@ModelId
@ModelClientId
@ModelVersion
These are alternatives to @Model.idProperty, @Model.clientIdProperty and @Model.versionProperty
If a class has both the new annotations takes precedence.
Example:
@Model(value = "MyApp.Employee", identifier = "negative", idProperty="eId",
versionProperty="version", clientIdProperty="clientId")
public class Employee {
public int eId;
public String version;
public String clientId;
}
OR
@Model(value = "MyApp.Employee", identifier = "negative")
public class Employee {
@ModelId
public int eId;
@ModelVersion
public String version;
@ModelClientId
public String clientId;
}
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.field.Field-cfg-allowBlank
Although it is a private property the documentation for the reference property says
"If a reference is not nullable, set the allowBlank property to false."
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.field.Field-cfg-reference
I want to use Sourcegraph for extclassgenerator code search, browsing, and usage examples. Can an admin enable Sourcegraph for this repository? Just go to https://sourcegraph.com/github.com/ralscha/extclassgenerator. (It should only take 30 seconds.)
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.