Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


visiau

1 post

Wannabe Geek


#39997 23-Aug-2009 03:12
Send private message

I'm newbie in jsp .....
I try to make little program using menu tree with jsp, struts tiles
but it can't view the last node of tree menu called in the next page.it's only call root of menu
the tree always reload when a page is called so that next position node of tree is different from a page before
I'm sorry..my posting is very long
please help me..

thanks a lot

================= dynamicTree.jsp ==================================

dojo.addOnLoad(function() {

dojo.lang.mixin(dojo.widget.byId('treeController'), dojo.widget.TreeControllerExtension.prototype);

});


<div dojoType="TreeLoadingController" widgetId="treeController" RPCUrl="tree_gettreenodes.action"></div>

<dojo:TreeSelector widgetId="treeSelector_contentTree" eventNames="select:treeSelected;" > </dojo:TreeSelector>
<div dojoType="Tree" id="contentTree" selector="treeSelector_contentTree" controller="treeController" toggle="fade">
<div dojoType="TreeNode" title="<sroperty value="#request.rootNode.name"/>"
id="<sroperty value="#request.rootNode.id"/>" isFolder="true"> </div>
</div>

===================struts.xml=====================================


<package name="system" extends="tiles-default">
<action name="Home" method="gettree" class="ptdh.mis.icma.action.HomeAction">
<result name="success" type="tiles">homePage</result>
</action>

<action name="tree_*" method="{1}"
class="ptdh.mis.icma.action.HomeAction">
<result>/WEB-INF/jsp/dynamicTree.jsp</result>
</action>


<action name="SearchEmployee" class="ptdh.mis.icma.action.PtdhCardAction" method="searchEmployee">
<result name="input" type="tiles">overrideSearchEmployee</result>
</action>

===============================myTilesConfigFile.xml ===============

<tiles-definitions>
<definition name="homePage" template="/WEB-INF/jsp/template.jsp">
<put-attribute name="header" value="/WEB-INF/jsp/defaultHeader.jsp" />
<put-attribute name="menu" value="/WEB-INF/jsp/dynamicTree.jsp" />
<put-attribute name="body" value="/WEB-INF/jsp/home_body.jsp" />
<put-attribute name="footer" value="/WEB-INF/jsp/defaultFooter.jsp" />
</definition>

<definition name="overrideSearchEmployee" extends="homePage">
<put-attribute name="body" value="/WEB-INF/jsp/searchEmployeeForm.jsp" />
</definition>


</tiles-definitions>

========================category.java============================
static {
new Category(1, "Root ", "",
new Category(2, "PTDH Card ", "",
new Category(3, " <a href='SearchEmployee.action'> "+"Create News ", " "),
new Category(4, " <a href='SearchPtdhCard.action'> "+"Search/Update ", " ")),
new Category(5, "Sub Contractor Card ","",
new Category(6, " <a href='AddSubconUser.action'> "+"Create New ", " "),
new Category(7, " <a href='SearchSubconCard.action'> "+"Search/Update ", " ")),

new Category(8, "Report", "",
new Category(9, " <a href='PtdhCardActiveExecution.action'> "+"PTDH Active Report ", " "),
new Category(10, " <a href='SubconCardActiveExecution.action'> "+"Sub Contractor Active Report ", " "))

);
}


public static Category getById(long id) {
return catMap.get(id);
}


public Category(long id, String name, String linkAddress,Category... children) {
this.id = id;
this.name = name;
this.linkAddress = linkAddress;
this.children = new ArrayList<Category>();
for (Category child : children) {
this.children.add(child);
}

catMap.put(id, this);
}

=========================HomeAction.java =======================


public String gettree(){
Category rootNode = Category.getById(1);
request.setAttribute("rootNode", rootNode);
return SUCCESS;
}

public String gettreenodes(){
JSONObject jsonData,node;
PrintWriter writer;
try {

jsonData = new JSONObject(data);
node = jsonData.getJSONObject("node");
String nodeId = node.get("widgetId").toString();
Category category = Category.getById(Long.parseLong(nodeId));
JSONStringer stringer = new JSONStringer();

stringer.array();
List<Category> children = category.getChildren();
for (int i=0;i<children.size();i++){
Category childCategory = children.get(i);
stringer.object();
stringer.key("id");
stringer.value(childCategory.getId());
stringer.key("title");
stringer.value(childCategory.getName());
stringer.key("isFolder");
stringer.value(childCategory.getChildren().size()>0 ? true : false);
stringer.endObject();
}
stringer.endArray();

writer = response.getWriter();
writer.write(stringer.toString());

} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}


}
============================================================

Create new topic
Ragnor
8279 posts

Uber Geek
+1 received by user: 585

Trusted

  #249836 23-Aug-2009 16:25
Send private message

Use http://pastie.org/ for posting code snippets, I'm unlikely to spend the time dechipering your post in it's current state.

Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.