Commontil.Java


/**

* Tree 구성

* (DataSet, 조직구성할 데이터 컬럼명, Tree에 표시될 컬럼명, 트리최상위표시명칭, 트리최상위이벤트키값, 이벤트스크립트(function 명), 이벤트파람컬럼명 )

* DataSet 정렬 - treeKeyColumn(조직구성할 데이터 컬럼) 기준

* ex) 조직구성할 데이터 컬럼 ( 아래처럼 데이터가 구성되어있어야함. )

* 000001

* 000001_000011

* 000001_000011_000012

* 000002

* 000002_000021

* 이벤트스크립트(function 명) 이 공백이면 void(0)

* @param ds

* @param treeKeyColumn

* @param treeViewColumn

* @param rootTreeNm

* @param eventScript

* @param eventParamColumn

* @return String

* @throws Exception

*/

public static String createTreeMenu( DataSet ds, String treeKeyColumn, String treeViewColumn, String rootTreeNm, String rootTreeKeyVal, String eventScript, String[] eventParamColumn ) throws Exception {

StringBuffer treeTag = new StringBuffer();

String tree_event = "void(0)";

String tree_view_name = "";

String tree_key_path = "";

String []tree_depth_key = null;

int ds_length = 0;

int before_tree_depth = 0;

int tree_depth = 0;

int event_length = 0;

try {

if ( ds != null && ds.getRow() > 0 ) {

ds_length = ds.getRow();

if( !"".equals( eventScript )) {

tree_event = eventScript + "('" + rootTreeKeyVal + "');";

}

treeTag.append("<ul id=\"tree_menu\">")

 .append("<img src=\"/images/common/treeicon/closed_default_folder.png\">")

 .append("<b>")

 .append("<a href=\"javascript:").append( tree_event ).append("\">").append( rootTreeNm ).append("</a>")

 .append("</b>");

for( int i=0; i<ds_length; i++ ) {

ds.next();

if( !"".equals( eventScript )) {

tree_event = eventScript + "('";

event_length = eventParamColumn.length;

if( eventParamColumn != null && event_length > 0 ) {

for( int j=0; j<event_length; j++ ) {

if( j > 0 ) {

tree_event += "','";

}

tree_event += ds.getString( eventParamColumn[j] );

}

}

tree_event += "');";

}

tree_view_name = ds.getString( treeViewColumn );

tree_key_path = ds.getString( treeKeyColumn );

tree_depth_key = tree_key_path.split("_");

tree_depth =tree_depth_key.length;

if( before_tree_depth == tree_depth ) {  //이전 뎁스 == 현재 뎁스

treeTag.append("</li>");

}else if( before_tree_depth < tree_depth ) {//이전 뎁스 < 현재 뎁스

treeTag.append("<ul id=\"in_tree_menu\">");

}else if( before_tree_depth > tree_depth ) {//이전 뎁스 > 현재 뎁스

int create_depth = before_tree_depth - tree_depth;

for( int k=0; k<create_depth; k++ ) {

treeTag.append("</ul>").append("</li>");

}

}

treeTag.append("<li>").append("<a href=\"javascript:").append( tree_event ).append("\">").append( tree_view_name ).append("</a>");

before_tree_depth = tree_depth;

}

treeTag.append("</li>").append("</ul>").append("</ul>");

}else {

treeTag.append("<ul id=\"tree_menu\">")

  .append("<img src=\"/images/common/treeicon/closed_default_folder.png\"><b>").append( rootTreeNm ).append("</b>")

  .append("</ul>");

}

}catch(Exception e) {

e.printStackTrace();

throw e;

}

return treeTag.toString();

}






action.java


map.put("p_sortorder", "TREEIDPATH"); //select 시 order by TREEIDPATH

DataSet data = terrMgr.selectTree( map);


String[] eventParamColumn = {"KEYCODE"};  //상세조회 시 키가 될 조회된 컬럼명

String treeTag = CommonUtil.createTreeMenu( data, "TREEIDPATH", "IDNAME", "조직구성도","000000", "selectDetailTree", eventParamColumn );


map.put("treeTag ", treeTag );


request.setAttribute("map"map);


return ---;





view.jsp


//script, css, img 파일

tree.zip



<link rel="stylesheet" type="text/css" href="/css/back/tree.css" />

<script type="text/javascript" src="/js/common/jquery/jquery.min.js"></script>

<script type="text/javascript" src="/js/common/tree_new.js"></script>


<%

String treeTag = box.getString("OrganTreeTag");

%>

<script type="text/javascript">

/**

 * 상세 내용 조회

 */

function selectDetailTree( v_keycode ) {

var f = document.form1;

if( f.p_compcode.value != "" ) {

parent.menuList ( v_keycode );

}

}

</script>


</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="" style="overflow-x:hidden;overflow-y:auto;">

<form name="form1" method="post">

</form>

<%=treeTag %>

<hr />

</body>

</html>







*. Sample 

jQuery Tree.zip


'JavaScript' 카테고리의 다른 글

[JavaScript] 아이디 저장.  (0) 2014.01.22
[JavaScript] log찍기  (0) 2013.11.08
[JavaScript] IP 유효성체크  (0) 2013.10.18
[JavaScript] SelectBox multiple  (0) 2013.10.17
[JavaScript] 파일용량 제한 체크  (0) 2013.10.04

+ Recent posts