圈子首页 java JSF 论坛

Java Studio Creator 做的动态树型菜单Demo,很实用

julycn 2007-06-27
JSF/EJB3技术交流群:36885039[我要开源]

贴一个 java studio creator 从数据取数据,动态生成树型菜单的Demo:

public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// *before* managed components are initialized
// TODO - add your own initialiation code here

List treeGroup=tree1.getChildren();
int tripTypeId=8;
String tree="";
String group="";
try{
CachedRowSetXImpl cxi=getSessionBean().getTripRowSet();
cxi.setInt(1, tripTypeId);
cxi.execute();

int nodeNum=0;
boolean hasNext=getSessionBean().getTripDataProvider().cursorFirst();
while(hasNext){
hasNext=getSessionBean().getTripDataProvider().cursorNext();
TreeNode newGroup=new TreeNode();
if(!tree.equals(cxi.getString("NAME"))){
newGroup.setText(cxi.getString("NAME"));
newGroup.setImageURL("/resources/tree_document.gif");
nodeNum=tree1.getChildCount()+1;
newGroup.setId("newTree"+nodeNum);
newGroup.setExpanded(true);
treeGroup.add(newGroup);
tree=cxi.getString("NAME");
}

while(tree.equals(cxi.getString("NAME"))){
List treeChildren=newGroup.getChildren();
TreeNode newTree=new TreeNode();
if(!group.equals(cxi.getString("DESTCITY"))){
newTree.setText(cxi.getString("DESTCITY"));
newTree.setImageURL("/resources/hyperlink_icon.gif");
nodeNum++;
newTree.setId("newTree"+nodeNum);
treeChildren.add(newTree);
group=cxi.getString("DESTCITY");
}
cxi.next();
}

}
}catch(Exception e){
e.printStackTrace();
}
// <editor-fold defaultstate="collapsed" desc="Creator-managed Component Initialization">
// Initialize automatically managed components
// *Note* - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("Page1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
// </editor-fold>
// Perform application initialization that must complete
// *after* managed components are initialized
// TODO - add your own initialization code here

}

/**
* <p>Callback method that is called after the component tree has been
* restored, but before any event processing takes place. This method
* will <strong>only</strong> be called on a postback request that
* is processing a form submit. Customize this method to allocate
* resources that will be required in your event handlers.</p>
*/
~~~~~~~~~~~~~~~~~~SQL Script~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT ALL TRAVEL.PERSON.NAME,
TRAVEL.TRIP.DESTCITY
FROM TRAVEL.TRIP
INNER JOIN TRAVEL.PERSON ON TRAVEL.TRIP.PERSONID = TRAVEL.PERSON.PERSONID
WHERE TRAVEL.TRIP.TRIPTYPEID < ?
ORDER BY TRAVEL.PERSON.NAME ASC,
TRAVEL.TRIP.DESTCITY ASC
lyqgenius 2007-06-28
汗,用的哪個包?這個都代碼如果不詳細還不如不要發
julycn 2007-06-29
这个是用Sun Java Studio Creator Update 2做的,所有的包都是系统自动加的!开发jsf非常方便
ReaiJava 2008-07-09
给个实例 出来 不是更好吗 看到效果
kimmking 2008-07-09
无图无真相

相关讨论