Hi,
One more novice question -- more of a java related, I suppose.
I have included the code I have after this message , where all models are
in the same file. Since Menu model changes constantly (every time there is
a new page, it has to be added in the menu!), I realized that it would be
far more convenient to have MenuDamModel class in separate file. So, I
tried to make separate files for MenuDamModel and HeadFootModel. But I
either get Class not resolve (obviously, Classpath related!) and
MeuDamModel duplicated (or something like that!). Can some body provide me
some tips, examples, docs for this?
I am using enhydra5.0, it would be even better if the tips are directly
related to it.
Thanks.
Damar
====== start of the code =========================
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.w3c.dom.*;
import org.enhydra.xml.xmlc.*;
import org.enhydra.barracuda.core.comp.*;
import org.enhydra.barracuda.core.comp.helper.*;
import java.util.Date;
import java.text.DateFormat;
public class MainDam extends ComponentGateway {
public Document handleDefault (BComponent root, ViewContext vc,
HttpServletRequest req, HttpServletResponse resp) {
if (xmlcFactory==null) xmlcFactory = new
XMLCStdFactory(this.getClass().getClassLoader(), new StreamXMLCLogger());
XMLObject page =
xmlcFactory.create(familySite.presentation.MainDamHTML.class);
BTemplate templateComp = new BTemplate();
templateComp.setView(new
DefaultTemplateView(page.getElementById("MainDam")));
templateComp.addModel(new MainDamModel());
templateComp.addModel(new MenuDamModel());
templateComp.addModel(new HeadFootModel());
root.addChild(templateComp);
return page;
}
//---------------MainDamModel ------------------------
class MainDamModel extends AbstractTemplateModel {
//register the model by name
public String getName() {
return "MainDam";
}
public Object getItem(String key) {
ViewContext vc = getViewContext();
if (key.equals("Title")) return "DTS main Page";
else if (key.equals("MainText")) {
XMLObject mainText
=xmlcFactory.create(familySite.presentation.TextDamHTML.class);
Node mainTextNode = mainText.getElementById("mainText");
return
vc.getElementFactory().getDocument().importNode(mainTextNode, true);
}
else return super.getItem(key);
}
}
//---------------MenuDamModel ------------------------
class MenuDamModel extends AbstractTemplateModel {
//register the model by name
public String getName() {
return "MenuDam";
}
//provide items by key
public Object getItem(String key) {
ViewContext vc = getViewContext();
if (key.equals("Menu")){
XMLObject menu =
xmlcFactory.create(familySite.presentation.MenuDamHTML.class);
Node menuNode = menu.getElementById("menu");
return
vc.getElementFactory().getDocument().importNode(menuNode, true);
}
else if(key.equals("DamarMain")){
BLink blink = new BLink(" ", "/mypage", vc);
return blink;
}
else if(key.equals("PattyMain")){
BLink blink=new BLink("","/pattymain", vc);
return blink;
}
else return super.getItem(key);
}
}
//---------------HeadFootModel ------------------------
/**
* HeadFootModel
*/
class HeadFootModel extends AbstractTemplateModel {
//register the model by name
public String getName() {
return "HeadFoot";
}
//provide items by key
public Object getItem(String key) {
ViewContext vc = getViewContext();
if (key.equals("Header")){
XMLObject header =
xmlcFactory.create(familySite.presentation.HeaderHTML.class);
Node headerNode = header.getElementById("header");
return
vc.getElementFactory().getDocument().importNode(headerNode, true);
}
else if (key.equals("Footer")) {
XMLObject footer =
xmlcFactory.create(familySite.presentation.FooterHTML.class);
Node footerNode = footer.getElementById("footer");
return
vc.getElementFactory().getDocument().importNode(footerNode, true);
}
else if(key.equals("Sarine")){
BLink blink1 = new
BLink("","http://otherDomain", vc);
return blink1;
}
else return super.getItem(key);
}
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.