On 14 August 2013 18:51, GESCONSULTOR - Óscar Bou <[email protected]>wrote:
> Hi, James. > > There is no attachment (I think they are not allowed). Simply > copy-and-paste. > Correct, they aren't. > > Default is like a "reserved" prefix. If Isis finds any method starting > with it, it will assume it to be a default value for a property or an > action param [1]. > > If you have implemented a "newTransaction(...)" action and want to specify > default values for parameters, do it as in [1] (remember to specify the > param number correctly (remember the first parameter will be number 0 - a > 0-based list -). > > As Oscar says. > If you simply want to initialize the properties of the Transaction inside > the "newTransaction(...)" you have different options: > - simply set them on the action's code. > - define on the "Transaction" class a defaultXXX () method, being XXX the > name of the property. > These are fine. > - initialize it by assigning a value directly to the field (I wouldn't > recommend this for default values on entity creation. Perhaps it could lead > to "conflicts" with the persistence ORM when re-creating the entity from > the database). > > Don't do this... one should distinguish between the initial creation of an object (prior to it being persisted) vs the rehydration of an already persisted object. ~~~ There is also another alternative, which I tend to prefer, using the created() callback. This is mentioned on the website [1]. I've also added a new page [2] that summarises other callback methods, and added a new page to make this overall topic easier to find [3]. HTH Dan [1] http://isis.apache.org/applib-guide/how-tos/how-to-07-010-How-to-set-up-the-initial-value-of-a-property-programmatically.html [2] http://isis.apache.org/applib-guide/how-tos/how-to-07-070-How-to-hook-into-the-object-lifecycle-using-callbacks.html [3] http://isis.apache.org/applib-guide/how-tos/how-to-03-017-How-to-specify-default-value-of-an-object-property.html > If that's not what you intented, please, copy the code. > > Hope this helps, > > Oscar > > > > PS: Seems there's no link for defining a default for a property on [2] ? > > [1] > http://isis.apache.org/applib-guide/how-tos/how-to-03-050-How-to-specify-default-values-for-an-action-parameter.html > > [2] http://isis.apache.org/applib-guide/how-tos/about.html > > > > El 14/08/2013, a las 19:23, james agada <[email protected]> escribió: > > > I have created an action in a service Transactions.java attached and > added the defaultNewTransaction method in ordr to populate default values. > It compiles alright but when I try to run, I get this error > > > > [exec] 1) Error in custom provider, > org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException: > 1: dom.todo.Transactions#defaultNewTransaction has prefix default, has > probably been orphaned. If not an orphan, then rename and use @Named > annotation > > > > May be I am doing it wrong but can some one help. Is it only inside > entity that you can use default? > >
