on ‎2018 Sep 27 2:44 PM
I was trying to create an atomic type in my custom extension.
<atomictype class="com.myextension.somepackage.CustomAtomicType" extends="java.lang.Object" autocreate="true" generate="false"/>
I creating a POJO for my atomic type with constructor in my custom extension
public class CustomAtomicType implements Serializable { private final String attribute1;
private final String attribute2;
public CustomAtomicType (String attribute1,String attribute2) { super(); this.attribute1= attribute1; this.attribute2= attribute2; } //Custom methods
}
But when I am using this atomic type in Customer Model ,the model generation is failing as it is not able to find the dependency of my Custom Atomic Type in platform/gensrc where the Customer Model is getting generated.
<attribute autocreate="true" generate="true" qualifier="customAttribute" type="com.myextension.somepackage.CustomAtomicType"> <modifiers read="true" write="true" search="true" optional="true" /> <persistence type="property" /> < /attribute>
Request clarification before answering.
Couple of years ago it was not possible, add new Atomic type
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try defining your atomic type class using the mycustomextension-beans.xml, this seems how it is done in the platform.
EDIT
Just tested it, it works!
training-beans.xml
<bean class="org.training.data.SomeDTO">
<property name="id" type="String"/>
<property name="flag" type="boolean"/>
</bean>
training-items.xml
<itemtype code="Product" autocreate="false" generate="false">
<attributes>
<attribute qualifier="someProperty" type="org.training.data.SomeDTO">
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
After ant clean all and update running system, the property is available.
Warning all the problems as mentioned in the previous question linked by still apply!
you have no flexible search support
Backoffice etc probably won't be able to display the value
You now have to worry about Java Object Serialization / Deserialization, because that's how the values are stored in the DB. Changing the DTO class may break stuff
Changing nested properties doesn't mark the model as dirty -> changes are not saved on modelService.save
ProductModel product = ...
SomeDTO dto = new SomeDTO()
dto.setId("value")
product.setSomeProperty(dto)
// works, change is saved
modelService.save(product)
dto.setId("new value")
// does NOT work, change is NOT saved
modelService.save(product)
dto = new SomeDTO()
dto.setId("new value")
// change detected because new object instance?
product.setSomeProperty(dto)
// change is correctly saved
modelService.save(product)
That said, I think having the option to return arbitrary objects is great for Dynamic Attributes and maybe for some specific use cases were you may want to precompute and cache values in the database.
But you have to be very sure what you are doing, and I doubt this is officially supported.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you using Ee? Make sure that the custom project sees the platform project (check the Java Build path). Also, make sure that you have refreshed the entire Ee workspace.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.