Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4101396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:41:31+00:00 2026-05-20T20:41:31+00:00

I’m currently developing a web application using Struts2 framework. This application requires to dynamically

  • 0

I’m currently developing a web application using Struts2 framework. This application requires to dynamically update the objects on the screen based on data received from another application.

At the moment, I would like to implement a dynamic tree view which nodes are updated periodically with data provided by an Action class. I’m trying to do so using the dojo.dijit.tree object from the dojo toolkit. I’m aware that I can do so using the dojo tags which are part of the struts framework, however, it lacks much of the functionality that I need (persistence, open and close branches dynamically, etc) therefore, I have opted for using the dojo toolkit instead.

My problem with the dojo.dijit.tree is that I don’t know how to provide its data using a JSON result type. I have already created a class which returns a JSON result type with the same structure needed by the dojo tree component. I have tested the generation of a dojo tree using a file “test.txt” which was generated by the class and it works as expected. However, I would like to pass the JSON data directly to the dojo.dijit.tree component without saving a file on disk. When I execute the application I get a “save as” window to save the returned JSON result.

This is my struts.xml file:

<struts>
<constant name="struts.devMode" value="true" />

<package name="default" namespace="/" extends="struts-default">                     

    <action name="devResult" class="gui.JsonAction">                        
        <result name="success">/start1.jsp</result>                         
    </action>

</package>


<package name="example" namespace="/" extends="json-default">              

    <result-types>
        <result-type name="json" class="org.apache.struts2.json.JSONResult"></result-type>
    </result-types>  

    <action name="getJSONResult" class="gui.JsonAction">
        <result type="json"/>           
    </action>

</package>

This is the jsp file which displays the tree:

<head>
<title>Testing Tree</title>    

<style type="text/css">
  @import "js/dojo/dojo/resources/dojo.css";
  @import "js/dojo/dijit/themes/nihilo/nihilo.css";
</style>

<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js"
        djConfig="isDebug: true,parseOnLoad: true">
</script>

<script type="text/javascript">
    dojo.require("dojo.data.ItemFileReadStore");
    dojo.require("dijit.Tree");
    dojo.require("dojo.parser");        
</script>

<body class="nihilo">
    The Tree:<br><br>

    <s:url id="devResult" action="jsonAction.action"></s:url>
    <div dojoType="dojo.data.ItemFileReadStore" href="%{devResult}" jsid="popStore" />
    <div dojoType="dijit.Tree" store="popStore" labelAttr="sname" label="Tree" />
</body>

This is the Action class which produces the JSON result:

public class JsonAction extends ActionSupport {

private static final long serialVersionUID = 7392602552908646926L;
private String label = "name";
private String identifier = "name";
private List<ChildrenClass> items = new ArrayList<ChildrenClass>();

public JsonAction() {
    ChildrenClass item1 = new ChildrenClass("name1", "cat");
    ChildrenClass item2 = new ChildrenClass("name2", "cat");
    ChildrenClass item3 = new ChildrenClass("name3", "cat");
    ChildrenClass item4 = new ChildrenClass("name4", "cat");

    items.add(item1);
    items.add(item2);
    items.add(item3);
    items.add(item4);
}

public String execute() {       
    return SUCCESS;
}

public void setLabel(String label) {
    this.label = label;
}

public String getLabel() {
    return label;
}

public void setIdentifier(String identifier) {
    this.identifier = identifier;
}

public String getIdentifier() {
    return identifier;
}   

public void setItems(List<ChildrenClass> lists) {
    this.items = lists;
}

public List<ChildrenClass> getItems() {
    return items;
}

}

This is the ChildrenClass which is used in the class above:

public class ChildrenClass {

private String name;
private String type;
private ChildrenClass[] children; 

public ChildrenClass() {
    name = "DefaultName";
    type = "DefaultType";
}

public ChildrenClass(String aName, String aType) {
    name = aName;
    type = aType;
}

public void setName(String name) {
    this.name = name;
}

public String getName() {
    return name;
}

public void setType(String type) {
    this.type = type;
}

public String getType() {
    return type;
}

public void setChildren(ChildrenClass[] children) {
    this.children = children;
}

public ChildrenClass[] getChildren() {
    return children;
}

}

I would like to ask to the stackoverflow reader to please indicate me how to do to read the JSON data in the jsp file in order to populate the dojo tree. In addition, I would like to ask how can I refresh the content of it periodically.

PS: If somebody has a better method to implement something similar to this, I would be glad to receive your comments.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:41:31+00:00Added an answer on May 20, 2026 at 8:41 pm

    I have found out a way to pass data directly from a JSON result to a dojo.dijit.tree component. Setting the “url” parameter to the action name which returns the json result type.

    This is my new body of the .jsp file:

    Simple Tree:<br><br>
    <div dojoType="dojo.data.ItemFileReadStore" url=getJSONResult handleAs="json" jsid="popStore" />
    <div dojoType="dijit.Tree" store="popStore" labelAttr="sname" label="PID 512" />                        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have a JSP page retrieving data and when single or double quotes are
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.