Sure, I will !

2014-09-18 14:21 GMT+02:00 Thiago H de Paula Figueiredo <thiag...@gmail.com>
:

> On Wed, 17 Sep 2014 20:40:28 -0300, Charlouze <m...@charlouze.com> wrote:
>
>  Hey again !
>>
>
> Hi!
>
>  Sorry for bothering everyone but I just wanted to say that I think I
>> found my perfect solution. I was looking at
>> the EntityApplicationStatePersistenceStrategy class and it just gave me
>> my answer...
>>
>> Maybe my new solution should replace the clumsy
>> EntityPersistentFieldStrategy of tapestry-jpa project:
>>
>
> Could you please post it as a JIRA in the Tapestry's issue tracker?
>
>
>
>> public class BetterEntityPersistentFieldStrategy extends
>> AbstractSessionPersistentFieldStrategy {
>>
>>     private final static String PREFIX = "entity:";
>>
>>     private final EntityManagerManager entityManagerManager;
>>
>>     public BetterEntityPersistentFieldStrategy(final EntityManagerManager
>> entityManagerManager,
>>             final Request request) {
>>         super(PREFIX, request);
>>         this.entityManagerManager = entityManagerManager;
>>     }
>>
>>     @Override
>>     protected Object convertApplicationValueToPersisted(final Object
>> newValue) {
>>         try {
>>             return
>> JpaInternalUtils.convertApplicationValueToPersisted(entityManagerManager,
>>                     newValue);
>>         } catch (final RuntimeException ex) {
>>             return super.convertApplicationValueToPersisted(newValue);
>>         }
>>     }
>>
>>     @Override
>>     protected Object convertPersistedToApplicationValue(final Object
>> persistedValue) {
>>         if (persistedValue instanceof PersistedEntity) {
>>             final PersistedEntity persisted = (PersistedEntity)
>> persistedValue;
>>
>>             return persisted.restore(entityManagerManager);
>>         } else {
>>             return super.convertPersistedToApplicationV
>> alue(persistedValue);
>>         }
>>     }
>> }
>>
>> Sorry again for spamming :)
>>
>> 2014-09-18 0:27 GMT+02:00 Charlouze <m...@charlouze.com>:
>>
>>  Hello everybody,
>>>
>>> I'm really not sure about what I did and I really appreciate a feedback
>>> from people who knows how persistent fields works.
>>>
>>> If i'm not clear enough or anything about my issue, just let me know.
>>>
>>> Cheers,
>>> Charles.
>>>
>>> 2014-09-16 17:13 GMT+02:00 Charlouze <m...@charlouze.com>:
>>>
>>>  As for now, I solved my problem using a new PersistentFieldStrategy and
>>>> I
>>>> want your opinion about it:
>>>>
>>>> public class MultiplePersistentFieldStrategy implements
>>>> PersistentFieldStrategy {
>>>>
>>>>     private final Logger logger;
>>>>
>>>>     private final List<PersistentFieldStrategy> delegates;
>>>>
>>>>     public MultiplePersistentFieldStrategy(final Logger logger,
>>>>             final List<PersistentFieldStrategy> delegates) {
>>>>         this.logger = logger;
>>>>         this.delegates = Lists.newArrayList(delegates);
>>>>     }
>>>>
>>>>     @Override
>>>>     public void postChange(final String pageName, final String
>>>> componentId, final String fieldName,
>>>>             final Object newValue) {
>>>>         for (final PersistentFieldStrategy persistentFieldStrategy :
>>>> delegates) {
>>>>             try {
>>>>                 persistentFieldStrategy.postChange(pageName,
>>>> componentId,
>>>> fieldName, newValue);
>>>>                 return;
>>>>             } catch (final RuntimeException e) {
>>>>                 logger.debug("Error while using a
>>>> PersistentFieldStrategy", e);
>>>>             }
>>>>         }
>>>>         throw new IllegalArgumentException("Unable to find any suitable
>>>> PersistentFieldStrategy");
>>>>     }
>>>>
>>>>     @Override
>>>>     public Collection<PersistentFieldChange> gatherFieldChanges(final
>>>> String pageName) {
>>>>         final List<PersistentFieldChange> persistentFieldChanges =
>>>> Lists.newArrayList();
>>>>         for (final PersistentFieldStrategy persistentFieldStrategy :
>>>> delegates) {
>>>>
>>>> persistentFieldChanges.addAll(persistentFieldStrategy.
>>>> gatherFieldChanges(pageName));
>>>>         }
>>>>         return persistentFieldChanges;
>>>>     }
>>>>
>>>>     @Override
>>>>     public void discardChanges(final String pageName) {
>>>>         for (final PersistentFieldStrategy persistentFieldStrategy :
>>>> delegates) {
>>>>             persistentFieldStrategy.discardChanges(pageName);
>>>>         }
>>>>     }
>>>> }
>>>>
>>>> Thanks again,
>>>>
>>>> Charles.
>>>>
>>>> 2014-09-16 16:29 GMT+02:00 Charlouze <m...@charlouze.com>:
>>>>
>>>>  Hello Tapestry users & devs,
>>>>>
>>>>> I have a component which does lots of ajax requests. Parameters setted
>>>>> at the first render are not available upon ajax requests so I decided
>>>>> to
>>>>> persist them in specific properties.
>>>>> One of those parameter is a database entity (I use tapestry-jpa) so I
>>>>> decided to use the the "entity" strategy so that my entity is reload
>>>>> and
>>>>> managed on every request.
>>>>> My problem is that when I use my component on a non persisted (yet)
>>>>> entity, it crashes as it is a transient entity that cannot be found.
>>>>>
>>>>> Do you think of a better way than creating my own persistence strategy
>>>>> ?
>>>>>
>>>>> Thx in advance :D
>>>>>
>>>>>
>>>>
>>>>
>>>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to