generic set to access fields in a Java object via SSJS

Malin

Is there a way to access in a more flexible way fields on a Java object via SSJS?

So when my Java object is stored in a obj variable I can access the created field via obj.created.

However I would make my solution a bit more flexible so the name of the field will be provided via a property definition on a custom control.

The name of the field I get via:

compositeData.fieldName

How can I bend this to:

var field = compositeData.fieldName;
obj.????

I tried

obj.getField(field);

(source: https://www.tutorialspoint.com/java/lang/class_getfield.htm)

gives me an error:

com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:132)

Is there someone with a suggestion?

Rob Mason

You should be able to access object properties by bracket notation:

obj.fieldName

is the same as

obj[compositeData.fieldName]

You may also want to look at java reflection which may allow you to do:

obj.get(compositeData.fieldName)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java : Object access with private fields

From Dev

Java with Beanshell to access fields and object with clean code

From Dev

Need to set the Launch properties on a new database via SSJS

From Dev

Java generic fields

From Dev

How to set a Generic object within a standard class in Java?

From Dev

SSJS or Java generate PDF

From Dev

Autopopulate a set of generic many to many fields in Django?

From Dev

How to access object fields in a loop?

From Dev

Is there a way to implement a generic class for displaying an object fields?

From Dev

Java Object with optional fields

From Dev

Java object instantiation with fields

From Dev

Java Object with optional fields

From Dev

How to access a generic list and assign the object of generic list to another object

From Dev

Forcing Computed Fields on a Document to Recalculate using SSJS

From Dev

fill an object instance via AutoFixture, but not by a generic but by type

From Dev

fill an object instance via AutoFixture, but not by a generic but by type

From Dev

access to controller object via service

From Dev

Unable to access java fields in clojure

From Dev

Unable to access java fields in clojure

From Dev

Access Java Enum fields in javascript

From Dev

Java supports generic types and methods. Why not generic fields?

From Dev

Java supports generic types and methods. Why not generic fields?

From Dev

Java generic object state comparison

From Dev

Java Generic Type and Object Class

From Dev

XPages to create .txt File via SSJS

From Dev

Non-volatile fields + first object access from another thread (java)

From Dev

How to set up generic owl object relationships

From Dev

How to set a property of a generic object in a list?

From Dev

Can I access fields of an Object in C#

Related Related

  1. 1

    Java : Object access with private fields

  2. 2

    Java with Beanshell to access fields and object with clean code

  3. 3

    Need to set the Launch properties on a new database via SSJS

  4. 4

    Java generic fields

  5. 5

    How to set a Generic object within a standard class in Java?

  6. 6

    SSJS or Java generate PDF

  7. 7

    Autopopulate a set of generic many to many fields in Django?

  8. 8

    How to access object fields in a loop?

  9. 9

    Is there a way to implement a generic class for displaying an object fields?

  10. 10

    Java Object with optional fields

  11. 11

    Java object instantiation with fields

  12. 12

    Java Object with optional fields

  13. 13

    How to access a generic list and assign the object of generic list to another object

  14. 14

    Forcing Computed Fields on a Document to Recalculate using SSJS

  15. 15

    fill an object instance via AutoFixture, but not by a generic but by type

  16. 16

    fill an object instance via AutoFixture, but not by a generic but by type

  17. 17

    access to controller object via service

  18. 18

    Unable to access java fields in clojure

  19. 19

    Unable to access java fields in clojure

  20. 20

    Access Java Enum fields in javascript

  21. 21

    Java supports generic types and methods. Why not generic fields?

  22. 22

    Java supports generic types and methods. Why not generic fields?

  23. 23

    Java generic object state comparison

  24. 24

    Java Generic Type and Object Class

  25. 25

    XPages to create .txt File via SSJS

  26. 26

    Non-volatile fields + first object access from another thread (java)

  27. 27

    How to set up generic owl object relationships

  28. 28

    How to set a property of a generic object in a list?

  29. 29

    Can I access fields of an Object in C#

HotTag

Archive