How to show non-persistent fields for an in-memory object in Apache ISIS? - isis

I have an Apache ISIS #Action that creates and returns a list of in-memory objects. When those objects are displayed by Apache ISIS as a collection in the browser - the JodaTime DateTime and String fields become all null.
There is also another field on the object, which is a persistent entity - it does not get reset to null and is displayed on the object.
Is it possible to display values of non-persistent fields of an object?
EDIT: Apparently the String field is displayed. The DateTime are not though. Can this be an issue with DateTime specifically?

The solution here is to use JAXB view models, as per concepts and the programming model.
One thing that isn't documented yet is that, for Joda date/time fields, you'll need to annotated the fields (or properties) with a JAXB XmlAdapter; see this blog post for guidance.
HTH, Dan

Related

fasterxml jackson JSON deserialization - custom adding

I use Jackson FasterXML product to deserialize JSONs. Now, I noticed in profiler that I got a ton of duplicate strings as a result since every time I receive a JSON it deserialize into an object which always contains some String variable which tells me the Type name. (it's answer to Facebook GraphQL query). Now, naturally, I would prefer for .intern() method to be used during deserialization of this specific method. Is that possible? If so, how?
Seems StringDeserializer can provide whttp://stackoverflow.com/questions/17041249/jackson-override-primitive-type-deserialization

Using DataTables.js with editor extension and ASP.NET MVC backend

I am using datatables with the editor extension to post data to an ASP.NET MVC backend. The action I am calling expects a complex object which I would like it to be able to automatically find the property values for using default model binding.
My problem is the default model binding expects the fields to have EXACTLY the same names as the public properties defined by my object. So when the table POSTs the data as data[name]="name" it can't find the value for the property 'Name'.
I can work around this problem by defining a custom model binder, but I have a lot of models I will be working with so would rather be able to reformat the data sent by the table so that the default model binder can find it e.g. name="name".
Can this be done?
Thanks
Nathan
Ok realise there's not much demand for this, but just incase the way to do it is to listen to the 'preSubmit' event and then manipulate the data object given in the parameter to match the structure and the names that you need on the server side.

Spine.js have updateAttributes include new attributes

It seems that Spine's Model.updateAttributes only updates attributes, and does not create new ones in case you supply any.
In my usecase, I have a controller that creates part of the attributes. Then through an Ajax request the server responds with the full object, and I want to update the model instance living in Spine with the additional variables.
For example, I have a model with attributes: name, date_created. Through the controller a user instantiates an object providing only the name. An Ajax request notifies the server which in turn responds with a name and a date_created. This date_created should then be added to the user's model.
Model.updateAttributes doesn't work, and I wouldn't be too fond of deleting the object and creating a new one - that just seems as too much overhead. I could provide default values for variables that are not set upon creation, but that also has a negative side. I guess what I'm looking for is a method that could be called Model.createOrUpdateAttributes. Can anybody recommend a way to achieve this? Thanks!
I might haven't fully understood your usecase, but I'll try to answer.
You need to declare whatever attributes a type of a model has with the configure class method. This declaration helps various model function to do their job later.
After you declare all the attributes you need, you can create model instances with any of the previously declared attributes.
You don't have to provide values for all the declared attributes.
After the ajax call returns, the date_created will be set on your model instance. Until this happens it will be just undefined.
If this solution still can't work for you, please describe why, and I'll gladly try to help.

How do I control which fields get serialized in Axis2?

How do I control which fields get serialized in Axis2? I have some fields (really getter/setter pairs) that I don't want exposed to the client. Also, some are coming across as nullable (e.g. someIntSpecified properties are created) where I want them.
I think there is unfortunately no annotation to exclude attributes from getting serialized.
I think you will need to create Data Transport Objects (DTOs). Otherwise you won't have a clean separation between your core business objects and the objects that you expose as API.

Beans, methods, access and change? What is the recommened practice for handling them (i.e. in ColdFusion)?

I am new to programming (6 weeks now). i am reading a lot of books, sites and blogs right now and i learn something new every day.
Right now i am using coldfusion (job). I have read many of the oop and cf related articles on the web and i am planning to get into mxunit next and after that to look at some frameworks.
One thing bothers me and i am not able to find a satisfactory answer. Beans are sometimes described as DataTransferObjects, they hold Data from one or many sources.
What is the recommended practice to handle this data?
Should i use a separate Object that reads the data, mutates it and than writes it back to the bean, so that the bean is just a storage for data (accessible through getters) or should i implement the methods to manipulate the data in the bean.
I see two options.
1. The bean is only storage, other objects have to do something with its data.
2. The bean is storage and logic, other objects tell it to do something with its data.
The second option seems to me to adhere more to encapsulation while the first seems to be the way that beans are used.
I am sure both options fit someones need and are recommended in a specific context but what is recommended in general, especially when someone does not know enough about the greater application picture and is a beginner?
Example:
I have created a bean that holds an Item from a database with the item id, a name, and an 1d-array. Every array element is a struct that holds a user with its id, its name and its amount of the item. Through a getter i output the data in a table in which i can also change the amount for each user or check a user for deletion from this item.
Where do i put the logic to handle the application users input?
Do i tell the bean to change its array according to the user input?
Or do i create an object that changes the array and writes that new array into the bean?
(All database access (CreateReadUpdateDelete) is handled through a DataAccessObject that gets the bean as an argument. The DAO also contains a gateway method to read more than one record from the database. I use this method to get a table of items, which i can click to create the bean and its data.)
You're observing something known as "anemic domain model". Yes, it's very common, and no, it's not good OO design. Generally, logic should be with the data it operates on.
However, there's also the matter of separation of concerns - you don't want to stuff everything into the domain model. For example, database access is often considered a technically separate layer and not something the domain models themselves should be doing - it seems you already have that separated. What exactly should and should not be part of the domain model depends on the concrete case - good design can't really be expressed in absolute rules.
Another concern is models that get transferred over the network, e.g. between an app server and a web frontend. You want these to contain only the data itself to reduce badnwidth usage and latency. But that doesn't mean they can't contain logic, since methods are not part of the serialized objects. Derived fields and caches are - but they can usually be marked as transient in some way so that they are not transferred.
Your bean should contain both your data and logic.
Data Transfer Objects are used to transfer objects over the network, such as from ColdFusion to a Flex application in the browser. DTOs only contain relevant fields of an object's data.
Where possible you should try to minimise exposing the internal implementation of your bean, (such as the array of user structs) to other objects. To change the array you should just call mutator functions directly on your bean, such as yourBean.addUser(user) which appends the user struct to the internal array.
No need to create a separate DAO with a composed Gateway object for your data access. Just put all of your database access methods (CRUD plus table queries) into a single Gateway object.