Can I associate EntityProxy with another RequestContext? And should I?

I have a small form that edits my essence. I create this object using one instance of RequestContext, and then in the handler of the Save button. I am trying to save it using another instance of RequestContext.

A save attempt fails with the expected exception: java.lang.IllegalArgumentException: Attempting to edit an EntityProxy previously edited by another RequestContext

Questions:

  • Can I associate EntityProxy with another RequestContext?
  • Is this right to do? Or should I reuse one RequestContext storing it as a property of my class?
+4
source share
1 answer

Reuse existing. If you need a new one, combine them. But in fact, it makes no sense to create a new one. That's why:

When making an RF call to the server, it goes through several stages, since it is oriented mainly in the direction of how to read and save objects, as well as various valuable properties they work.

  • Create or load any of the instances that will be processed.
  • Apply the settings to these instances, new or existing, and confirm them.
  • Run utility calls either as methods called for entities, static calls, or service calls.

These three steps are performed in this order to ensure that the object, modified and then passed to the service call, makes sense when it gets there. Future calls (i.e., Other requests) probably do not have to make the same changes to the same objects, and if they do, they must make the changes themselves.

In this case, the RequestContext consists of all these things. If you had two requests, and one represented the setter to be called (edits from the form), and the other a service request, shooting one means only calling the setters, but not calling the service to save it, while firing the other means only the call is saved without calling a service.

After EntityProxy been flagged as being edited by one query context, trying to use it in another case is almost certainly an error, so the exception you see is thrown. Use an existing one or use RequestContext.append , if necessary, to switch to a new type of RequestContext to actually start the save operation.

RequestFactory is not RPC - your objects are not only Java Beans, but a proxy (either EntityProxy or ValueProxy ) of some server object, and requests are used to manipulate their asynchronous. >

+3
source

Source: https://habr.com/ru/post/1397720/


All Articles