Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 504 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AEM: reading a value from a node in java which is value of a multifield

#1
I am reading a set of node in java. each node is of one country. each node has property "country" and for some countries like US has "states" property node too. This "states" is part of a multifield hence each item has one state which is all together in one node something like this:

country = "US"
, states = [{"statename":"District of Columbia"}, {"statename":"Rhode Island"},{"statename":"South Dakota"}]

I want to populate them as a json in the page through a servlet call like this:

[To see links please register here]


{
country: "India"
{
statename:"Delhi",
statename:"Punjab",
statename:"Haryana"
}
}

{
country: "Turkey"
}


following is my code:

while (nodeItr.hasNext()) {
Node cNode = nodeItr.nextNode();
if (cNode.hasProperty("country")) {
JSONObject jsonData = new JSONObject();
jsonData.put("country", childNode.getProperty("countryname").getValue().getString());
jsonArray.put(jsonData);
if (cNode.hasProperty("states")) {
// This should display array of all states as an when it is encountered.
LOG.info(childNode.getProperty("states").getValue().getString());





Following happens:
1. I get all the country list except the first country for which states property is exits.
2. No other country where statelist is there, is displayed.

What am I doing wrong ?
Reply

#2
Try the following:

if (cNode.hasProperty("states")) {
Property statesProperty = cNode.getProperty("states");
if (statesProperty.isMultiple()) {
Value[] statesValues = states.getValues();
for (Value stateValue : stateValues) {
LOG.info(stateValue.getString());
}
}
}

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through