業務圖形:
準備工作
設定myeclipse的基礎環境:
1.設定編碼。windows--prefer...--general--workspace,修改編碼為utf-8
2.修改jdk的編譯版本。java--compiler,修改jdk的編譯版本為6.0
3.添加自己的jdk。java--installed jres,點擊add,點擊browse,選擇自己安裝的jdk路徑。將預設選中為剛剛添加的jdk。
4.配置myeclipse啟動tomcat。myeclipse--servers--tomcat--tomcat 6.x--jdk,選擇上一步添加的jdk。tomat server選擇enable,tomcat home directory選擇自己的tomcat路徑。
建立一個dhmi的外掛程式工程:
1.右鍵--new--java project。
2.寫入工程名稱,點擊finish。
3.建立一個lib目錄。將ROOT/WEB-INF/lib目錄下的所有jar包,複製到這個目錄下。
4.右鍵工程--prefer...--java build path--libraries--add jars,選擇所有jar包,匯入。
5.匯入j2ee的jar包。java build path--libraries--add library--myeclipse library。找到j2ee 1.4 librarys,勾選,點擊finish。
正式開始
1.建立home.xml,list.xml, detail.xml模板msc形式編寫
注意事項:注意添加頭<dhmi type=response>....</dhmi>
- <dhmi type="response">- <msc type="form" action="?action=query@mdpdhmi&configid=team&m=list@news&name=zhengkaize">- <body> <input type="text" name="username" /> <input type="submit" name="submit" caption="submit" /> </body> </msc> </dhmi>
<dhmi type="response">- <msc type="form" xmlns="http://msc_form.d-heaven.com/UI2.0">- <head> <title>列表</title> </head>- <body margin="0">- <list arrow="true" id="list">- <!-- $BeginBlock List --> - <listcell href="${href}">- <span valign="center"> <font size="xl">${listcellcaption}</font> </span> </listcell>- <!-- $EndBlock List --> </list> </body> </msc> </dhmi>
detail.xml
- <dhmi type="response">- <msc type="form" xmlns="http://msc_form.d-heaven.com/UI2.0">- <head> <title>詳情</title> </head>- <body margin="0"> <span>${title}</span> <span>${content}</span> </body> </msc> </dhmi>
2.配置mdp
<mdp:dhmi-config id="team" source="http://127.0.0.1:8080/dhmi.do" localSource="http://127.0.0.1:8081" appid="BVCXEK"></mdp:dhmi-config>
3.建立模組類
package com.dheaven.dhmi.module;import java.io.IOException;import java.util.List;import org.dom4j.Document;import org.dom4j.Element;import org.dom4j.Node;import com.dheaven.dhmi.framework.module.BaseModule;import com.dheaven.dhmi.framework.templator.MiniTemplator;import com.dheaven.dhmi.framework.templator.MiniTemplator.TemplateSyntaxException;import com.dheaven.dhmi.framework.util.DhmiFramewokUtil;public class TeamNewsModule extends BaseModule {@Overridepublic void execute() {log.debug("進入TeamModule...............");System.out.println("參數名稱:"+this.method);MiniTemplator m = null;if (this.method.equalsIgnoreCase("home")) {try {m = new MiniTemplator(this.getTemplateFilePath("home.xml"));} catch (TemplateSyntaxException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}log.debug("進入home...............");this.documentResponse = m.generateDocumentOutput();this.sendResponse();log.debug("退出home...............");} else if (this.method.equalsIgnoreCase("list")) {try {m = new MiniTemplator(this.getTemplateFilePath("list.xml"));} catch (TemplateSyntaxException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}Document doc = DhmiFramewokUtil.reqUrl("http://192.168.2.134:8088/search.do?name="+ this.getStringData("username"), "");Element titleNode = (Element)doc.selectSingleNode("//memo");m.setVariable("title", titleNode.getStringValue());List<Element> listNameNodes = doc.selectNodes("//list");for (int i = 0; i < listNameNodes.size(); i++) {m.setVariable("href", "?action=query@mdpdhmi&configid=team&m=detail@news&id="+ listNameNodes.get(i).selectSingleNode("./id").getText());m.setVariable("listcellcaption",listNameNodes.get(i).selectSingleNode("name").getText());m.addBlock("list");}this.documentResponse = m.generateDocumentOutput();this.sendResponse();} else if (this.method.equalsIgnoreCase("detail")) {try {m = new MiniTemplator(this.getTemplateFilePath("detail.xml"));} catch (TemplateSyntaxException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}Document doc = DhmiFramewokUtil.reqUrl("http://192.168.2.134:8088/show.do?id="+ this.getStringData("id"), "");log.debug("進入設定...............");m.setVariable("title", doc.selectSingleNode("//memo").getText());m.setVariable("content", doc.selectSingleNode("//content").getText());this.documentResponse = m.generateDocumentOutput();this.sendResponse();log.debug("退出設定...............");}}}
4.在.property檔案中添加模組名稱
news=com.dheaven.dhmi.module.TeamNewsModule
5.添加連結
<grid mode="3"><item caption="home" icon="img/1.png" href="?action=query@mdpdhmi&configid=team&m=home@news" target="_blank" /></grid>
原理總結