How to get and set attribute from java xpath ?

1
Hi all,   my code are  IMendixObject newEntity = Core.instantiate(contextData,enTity); XPath<IMendixObject> xpath = XPath.create(getContext(), newEntity.getType()); List<IMendixObject> cc= xpath.allMendixObjects(); How to get and set attribute from java xpath ? such as I would like to set attribute “Status” to “Y”.
asked
4 answers
2

Do you mean you want to set and get the values of an attribute on an Entity using Java?

If you do, the easiest way is to import the proxy class for that entity, and then use the getters and settings that have been auto generated for you. For example, if your entity was called MyEntity and it had an attribute called Name, you could do something like this…
 

import myfirstmodule.proxies.MyEntity;

// Create an instance of the entity (or you could do a retrieve to get data from an existing entity)
MyEntity myEntity = new MyEntity(this.getContext());

// Get an attribute from an entity.
String name = myEntity.getName();

// Set a value in an entity.
myEntity.setName("Rob");

Hope this helps.

answered
2

Roberts explanation already has almost everything you need. Be aware of the fact that your xpath is returning IMendixObject objects that can’t be used like this directy. (Just because the system does not know the “real” type of the objects.

But Mendix creates proxies for all the entities in your domain model. You can create such a proxy object from your IMendixObject by using the static initialize method of your proxy.

myEntity.initialize(IContext context, IMendixObject mendixObject)

This will return the proxy object that you need to use the set and get methods as described by Robert

answered
0

Hi Robert Price , Thanks for reply. I mean , I would like to create java action and pass any Entity parameter  that is not specifi and in java code I would like to get and get it. The problem is the entity that pass to java action is a type String.

 

 

answered
0

 Hi Andreas Blaesius,

I can not mapping String type that pass to java action to proxy object.

ex.

this.entityName = MyFirstModule.Person

I don’t know how to mapping it to proxy object.

answered