Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Convert DSResponse to Java

    I'm trying to use the JSOHelper class to convert DSResponse data back to Java. The data coming back is a simple List of POJOs. I know I can get the items back as a record list, but is there an easy way to get the Java objects back? Here's what I'm trying to do:

    Code:
    DataSource.get("MyDataSource").fetchData(null, (dsResponse, o, dsRequest) -> {
        List<MyPojo> data = (List<MyPojo>) JSOHelper.converTtoJava(dsResponse.getDataAsObject());
    }
    Should I be converting to a list first then iterating? I'm not seeing how the JSOHelper.convertToJava() function is supposed to work.

  • #2
    There is little point in instantiating your pojos, as you need to use various subclasses of Record with our DataBoundComponents. Even if you could instantiate your pojos and use them with our components, this would force all the logic in your pojos to be limited to the range of Java that GWT can translate to JavaScript, so any kind of non-trivial validation logic quickly forces you into separate client-side and server-side pojos, with heavily duplicated logic.. we consider this entire approach an anti-pattern.

    Instead, if there is an any client-side logic related to your pojos that does not fit into framework concepts such as declarative validators, just make it into a static utility method that takes a Record argument. In most applications, you will write just a couple of such methods, and sometimes none at all.

    For completeness: if you ignore best practices and try to use pojos on the client side, then you need to write a method that simply calls every setter on your pojo after retrieving that data from a Record.

    Comment


    • #3
      Isomorphic , thanks for the response, that makes sense. Just one more question then, what does the JSOHelper.convertToJava do?

      Comment


      • #4
        What it's documented to do - did you not see that it has documentation including a link to a long topic on JS > Java conversion?

        Comment

        Working...
        X