0

On an XPage I have in a viewScope an arraylist with json objects which I want to submit to a managed bean:

function createPersons(){
    var json:java.util.ArrayList = viewScope.get("persons");
    personBean.createPersons(json);
}

here is an example of the viewscope content:

[0] 
area    Compliance
mandatory   true
newArea false
person  Patrick Kwinten/Web
prio    2
[1] 
area    Credits
mandatory   true
newArea false
person  Patrick Kwinten/Web
prio    2
[2] 
area    Food
mandatory   true
newArea true
person  Patrick Kwinten/Web
prio    2

Now I would like to define in my java class the method:

public void createPersons(ArrayList json){ utils.printToConsole(this.getClass().getSimpleName().toString() + " - createPersons() json"); utils.printToConsole("size json = " + json.size()); //todo; }

but I get the error message:

Description Resource Path Location Type JsonJavaObject cannot be resolved to a type personBean.java

Any advice anyone?

1
  • Did you make sure that the personBean class is in your build path and compiles correctly? Commented Jan 12, 2018 at 9:57

1 Answer 1

1

I would recommend to use a custom Java object in your view scope instead of relying on the Json serialization. You create a Java class, roughly like this:

    public class AreaInfo {
        private String area;
        private boolean mandatory;
        private boolean newArea;
        private String person;
        private int prio;

        public String getArea() {
            return area;
        }
        public void setArea(String area) {
            this.area = area;
        }
        public boolean isMandatory() {
            return mandatory;
        }
        public void setMandatory(boolean mandatory) {
            this.mandatory = mandatory;
        }
        public boolean isNewArea() {
            return newArea;
        }
        public void setNewArea(boolean newArea) {
            this.newArea = newArea;
        }
        public String getPerson() {
            return person;
        }
        public void setPerson(String person) {
            this.person = person;
        }
        public int getPrio() {
            return prio;
        }
        public void setPrio(int prio) {
            this.prio = prio;
        }


    }

Use that one in your ArrayList in the viewscope. You could also consider having a class around the list if you want to fetch e.g. by Area name etc. Makes it much easier to deal with.

Let me know if that works for you

Sign up to request clarification or add additional context in comments.

1 Comment

yes I think you are right. a bit more work because I am not actually interested how the json objects look like, I just want to transfer them. thanks for your guidance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.