What is the difference between genericModel and defaultModel in wicket? - wicket

I am new to wicket. There is a confusion in Model, ModelObject defaultModel, genericModel. I need to know the difference between ModelObject and Model, defaultModel and genericModel. Please help me to clear about it.

defaultModel[Object] and genericModel[Object] is the same object, behind the scenes.
Each Component has an IModel and this model brings an java.lang.Object inside. This is the defaultModelObject.
Some specializations of Component, like FormComponent, Form, GenericPanel, etc. use Java generics to make the user code more concrete. For this Wicket uses genericModel[Object] - it is the same Object but casted to its actual type. The casting is in Wicket code, not in the application code.

Related

Right way to convert a model to entity in Flutter, MVVM architecture?

I'm a beginner in MVVM architecture and I'm stuck on an issue in a product app.
The issue: Mapping a Model to an Entity
Let me explain my code structure;
Domain > Respository > order_repo.dart
This order_repo.dart is an abstract class OrderRepo that declares a function getOrders that returns OrderEntity.
Data > Repo Implementation > order_repo_impl.dart
The order_repo_impl.dart contains a class OrderRepoImpl that defines the function getOrders that returns OrderModel that extends OrderEntity.
Domain > Usecase > order_usecase.dart
The order_usecase.dart contains a class that uses OrderUsecase that uses an instance of OrderRepo to call getOrders. Both the getOrders and call functions return OrderEntity.
The problem is that when I call the usecase, I expect it to return OrderEnity but the runtimeType is OrderModel. I tried to parse it as OrderModel but I could not do that because I get this warning, Unnecessary Cast, because at compile time the compiler is also expecting OrderEntity.
One solution I found is to define a Translator, that would convert OrderModel to OrderEntity inside usecase, but I'm confused regarding the right place for its definition, because I cannot use OrderModel inside the Domain layer as per Clean Architecutre to keep Domain independent of other layers and if I define the Tanslator inside Data layer, I still cannot call it in the usecase, because of the same reason.
It is bad practice
The order_repo_impl.dart contains a class OrderRepoImpl that defines the function getOrders that returns OrderModel that extends OrderEntity.
Not always model can extend entity f.e. (Code-Generated Model)
The domain layer should not know about implementation and about the data layer, because Implementation can change but Business logic will not as long as there is no changes in business logic.
I found is to define a Translator that would convert OrderModel to OrderEntity inside usecase
It is good practice
It is good practice to convert it inside implementation of repository. Because, repository is kind of binding between domain and data layers,
Or even, You can create converter class that translate entity to model and vice verca and the instance of the class will be to the constructor of repository implementation.
Why it is better to follow these advices.
Implementation quite often can change but abstraction rarely changes.
Easy to switch from one implementation to another one.
You follow SOLID principles
P.s. I hope I could answer to your question. Whether you have feel free to ask it on comments

Are UE4 Blueprints the same with a C++ class? If so, how will I implement a class design?

Good day! I am new to using Unreal Engine 4 and I have a few questions about how exactly blueprints work. From my understanding of it, every blueprint works like a class. By that I mean one blueprint is much like one class in an OOP programming language.
Please educate me as to - if my assumption is correct or wrong. If wrong, then maybe you could help me achieve what I want in a different method/perspective. I am willing to learn and accept suggestions.
If at some point my understanding is correct - that blueprints are actually individual classes - I would really appreciate it if you could (please) guide as to where to go and how to implement a design that I want to create. This is from a programmers perspective (PHP OOP Programming). Forgive the approach, I'm just using PHP to logically express how I want the class to work. Plus, it is the only OOP programming I know atm.
I want to create a class named: Items. class Item {}
This class is going to handle everything item related, thus we will have to give it a lot of properties/variable. (Below is just an example; Again I'm using PHP as an example.)
class Item {
var $id;
var $name;
var $description;
var $type;
var $subType;
var $mesh;
var $materials;
}
3.) I would like to initiate this class by having two variables as its construct arguments. (We will require itemID and itemType). This is because I will use these two variables to retrieve the item's data which is already available in a data table. I will use those data in the table to populate the class properties/variables. (I'm not sure if I said that right. I hope you understood my point anyway.)
class Item {
var $id;
var $name;
var $description;
var $type;
var $subType;
var $mesh;
var $materials;
function _construct($cons_itemID, $cons_itemType) {
/*-- Start getting the item Data here based on what item and type provided. Then, push that data into the class properties/variables. We will use individual methods/functions to fill other properties/variables later. --*/
}
}
4.) Basically with that design I could easily pass on an item ID to the class and then get the item's name, description, mesh, materials and etc using pointers.
Example:
$weapon = new Item('10001','Weapon');
$weaponMesh = $weapon->getMesh();
$armor = new Item('12345','Armor');
$armorName = $armor->getName();
I'm just having a lot of trouble working with blueprint and achieve this method or even something similar to it. I'm not trying to avoid C++, I would love to learn it but I just don't have the time freedom right now.
Few things I have tried to make it work:
Casting / Casting to class (But I couldn't figure out what the target object will be and how was I going to add input arguments into the class that way? There isn't any input there that I could use.)
Spawn Actor (This one is very promising, I need to dig in deeper into this)
Blueprint Macros? Blueprint Interfaces? (I'm just lost.)
For all those who will help or answer. Thank you!
~ Chris
So far as I know, yes, we can assume that each blueprint can be viewed as class. (Moreover, since UE 4.12 (in UE 4.11 that functionality is marked as experimental I think) you can check Compile blueprints under Project settings -> Packaging. That will create native class for each blueprint.)
You can create either Blueprint or C++ class based on Object (UObject in C++). Then you can specify all properties (or variables in UE editor terminology). In BP you have small advantage: you can mark some properties as Visible at spawn (they must be Public and Visible). So when you are creating new instance of that class, you can explicitly pass values to that properties.
And in BP Construct event, that properties are correctly filled, thus you can set another properties values based on given ID and Type.
In C++ class having different arguments than FObjectInitializer is not possible, thus you don't have that values in time when constructor is executed. But it is not so hard to achieve same functionality, you can find example here: https://answers.unrealengine.com/questions/156055/passing-arguments-to-constructors-in-ue4.html.
Something about list of what you had tried:
Spawn actor - derive from actor only if you intend to have that BP in scene. Actors are subjects to game updates and rendering, so having actor only as data container is very wrong.
BP Macro is same as BP Function except function will be called just like function (so executing necesary actions by function call conventions) and macro will replace it's implementation in place, where you are calling that macro. More exhausting explanation here.
If I would implement your code, I'd do it like I said and then I'll have that class as property in some component and that component would be attached to some actor, which would be placed in scene.

A way to persist TreeNode from Primefaces with JPA

Is there anyway i can use the primefaces TreeNode/DefaultTreeNode class with JPA for persistence?
I'm trying to do it, but i'm completely lost.
I think I might have to implement my own TreeNode class to do that, but I did want to use primefaces class for using with the p:treeNode component.
I would not persist treenodes for since most likely the only way you can get them persisted is to have them serialized which will (99% chance) lead to problems in the future if PF changes something in the DefaultTreeNode.
More generically, I would never persist objects not from my own model!
As you can see in this example in the PF showcase you can add your own entities to the treenode when building them
TreeNode documents = new DefaultTreeNode(new Document("Documents", "-", "Folder"), root);
On selection you can get the object back by node.getData()

EXT GWT BaseModel needs to have DTO reference?

I am very new to GWT.
I am using ext-gwt widgets.
I found many places in my office code containing like,
class A extends BaseModel{
private UserAccountDetailsDto userAccountDetailsDto = null;
//SETTER & GETTER IN BASEMODEL WAY
}
Also, the DTO reference is unused.
public class UserAccountDetailsDto implements Serializable{
private Long userId=null;
private String userName=null;
private String userAccount=null;
private String userPermissions=null;
//NORMAL SETTER & GETTER
}
Now, I am able to get the result from GWT Server side Code and things Work fine, but when I comment the DTO reference inside the class A, I am not getting any Result.
Please explain me the need of that.
Thanks
Well the problem is in implementation of GXT BaseModel and GWT-RPC serialization.
BaseModel is based around special GXT map, RpcMap. This map has defined special serialization rules, which let's avoid RPC type explosion, but as side effect, only some simple types stored in map will be serialized. E.g. you can put any type inside the map, but if you serialize/deserialize it, only values of type Integer, String ,Double,Byte, Float and Short (and arrays of this types) will be present. So the meaning behind putting reference to the DTO inside BaseModel, is to tell GWT-RPC that this type is also have to be serialized.
Detailed explanation
Basically GWT-RPC works like this:
When you define an interface for service, GWT-RPC analyzes all the classes used in parameters/ return type, to create serializers/deserializers. If you return something like Map<Object,Object> from your service, GWT-RPC will have to create a serializer for each class which implements Map and Serializable interfaces, but also it will generate serializers for each class which implements Serializable. In the end it is quite a bad situation, because the size of your compiled js file will be much biggger. This situation is called GWT-RPC type explosion.
So, in the BaseModel, all values are stored in RpcMap. And RpcMap has custom written serializer (RpcMap_CustomFieldSerializer you can see it's code if you interested how to create such things), so it doesn't cause the problem described above. But since it has custom serializer GWT dosn't know which custom class have been put inside RpcMap, and it doesn't generate serializers for them. So when you put some field into your BaseModel class, gwt knows that it might need to be able to serialize this class, so it will generate all the required stuff for this class.
Porting GXT2 Application code using BaseModel to GXT3 Model is uphill task. It would be more or less completely rewrite on model side with ModelProviders from GXT3 providing some flexibility. Any code that relies on Model's events, store, record etc are in for a rewrite.

Wicket: how to use the BodyTagAttributeModifier class?

i'm trying to dynamically add the class attribute to the body tag, and i came across this class. but i can't seem to understand how to use this class. i have something like this in my page class (or panel class, as i tried with that too):
add(new BodyTagAttributeModifier("class", "homepage", this));
this doesn't even compile, saying there's something wrong with the 2nd parameter. but i think String is automatically considered a Model in wicket, like the Label class. am i missing something here?
What if you just add an wicket:id to the body attribute and use the AttributeAppender class? Or, if the body attribute already has an id, can't you just use this class?
http://wicket.sourceforge.net/apidocs/wicket/behavior/AttributeAppender.html
Some Wicket Components have this String-to-model-shortcut (like Label), but it's not a general feature. You have to convert your String into a Model manually:
add(new BodyTagAttributeModifier("class", Model.of("homepage"), this));