on 03-12-2006 11:15 AM
hello all,
I'm trying to modify the Webdynpro Tutorial 17 "Dynamic UI Generation in WebDynpro" in the following way:
Instead of using the data stored in the SomeBackEnd.java Class, my program should read a xml-File on the initialization of the class.
public class ApplicationDescriptor {
/////////////////////////////////////////////////////////
public class FieldDescriptor
{
private String uiType;
private String contextName;
private String contextType;
private String label;
public FieldDescriptor(String uiType, String contextName, String contextType, String label)
{
this.uiType = uiType;
this.contextName = contextName;
this.contextType = contextType;
this.label = label;
}
String getUIType(){ return uiType; };
String getContextName(){ return contextName; };
String getContextType(){ return contextType; };
String getLabel(){ return label; };
}
public class OperationDescriptor
{
private String actionName;
private String displayText;
public OperationDescriptor(String actionName, String displayText)
{
this.actionName = actionName;
this.displayText = displayText;
}
String getActionName(){ return actionName; };
String getDisplayText(){ return displayText; };
}
private int fieldCount = 0;
private int operationCount = 0;
/////////////////////////////////////////////////////////
public class HandelXML extends DefaultHandler
{
private String thisSection = "";
private String inputType = "";
private String contextName = "";
private String contextType = "";
private String label = "";
private String action = "";
public HandelXML()
{
}
public void startDocument() throws SAXException
{
fieldCount = 0;
operationCount = 0;
}
public void startElement(String namespaceURI, String localName, String qName, org.xml.sax.Attributes atts) throws SAXException
{
thisSection = qName;
if (qName.equals("input"))
{
inputType = "InputField";
}
}
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{
if (qName.equals("input"))
{
fields[fieldCount] = new FieldDescriptor(inputType, contextName, contextType, label);
fieldCount = fieldCount + 1;
System.out.println("Field: " + inputType + "|" + contextName + "|" + contextType + "|" + label);
}
if (qName.equals("submit") || qName.equals("exit"))
{
operations[operationCount] = new OperationDescriptor(action, label);
operationCount = operationCount + 1;
System.out.println("Operation: " + action + "|" + label );
}
}
public void characters(char[] ch, int start, int length) throws SAXException
{
String text=new String(ch, start, length);
text=text.trim();
if (text.length() > 0)
{
if (thisSection.equals("caption"))
{
label = text;
}
if (thisSection.equals("value"))
{
contextName = text;
}
if (thisSection.equals("type"))
{
contextType = text;
}
if (thisSection.equals("action"))
{
action = text;
}
}
}
}
/////////////////////////////////////////////////////////
public ApplicationDescriptor()
{
XMLReader xmlReader = null;
try
{
SAXParserFactory spfactory = SAXParserFactory.newInstance();
spfactory.setValidating(false);
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new HandelXML());
InputSource source = new InputSource("TemplateWD.xml");
xmlReader.parse(source);
} catch( SAXException e) {
e.printStackTrace();
System.exit(0);
} catch (Exception e)
{
System.err.println(e);
// System.exit(1);
System.exit(0);
}
}
/////////////////////////////////////////////////////////
int getNumberFields()
{
return fieldCount;
}
FieldDescriptor getField(int index)
{
return (FieldDescriptor)fields[index];
}
int getNumberActions()
{
return operationCount;
}
OperationDescriptor getAction(int index)
{
return (OperationDescriptor)operations[index];
}
private Object[] fields = new Object[64];
private Object[] operations = new Object[64];
/////////////////////////////////////////////////////////
}
this code runs correctly as a separated java-program.
I bound it into the Webdynpro-Program by using
// Create backend connection to ApplicationDescriptor.java
ApplicationDescriptor theDescriptor = new ApplicationDescriptor();
the j2ee Engine was shut down automatically when I ran the Webdynpro-program. There was an exception at the time of loading the xml-file.
The xml-file is in the folder srcpackages..., together with the java-class.
Would someone tell me, what I did wrong? I'm just a beginner in java and I'm still learning it.
Thank you very much in advance.
vivian
Vivian,
1. Place your file directly under src/packages directory in your project.
2. Instead of
InputSource source = new InputSource("TemplateWD.xml");
use this:
InputSource source = new InputSource
(
this.getClass.getClassLoader()
.getResource("TemplateWD.xml")
.toExternalForm()
);
Valery Silaev
EPAM Systems
Message was edited by: Valery Silaev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Valery, hi Sebastian,
thank you for the answers.
I tried the code from Valery, but the same happened again.
I'm watching it in the debugging. The problem seems to be at the step "ApplicationLoader(ClassLoader).loadClassInternal(String)line:302 [local variables unavailable] "
At "InputSource source = new InputSource..." the Debuggingprocess went into the Exception:
"private synchronized Class loadClassInternal(String name)
throws ClassNotFoundException
{
return loadClass(name);
}
"
(the "name" in it is "local/ZDA_WD2"
"ZDA_WD2" is the name of my project,
btw, j2ee is on the same computer. )
and then I got this
"Source not found for ApplicationLoader(ReferencedLoader).loadClass(String)"
Would you pls. tell me what it means?
thank you very much.
regards
vivian
Thank you!
I hope you meant this part of Stack trace:
Thread [ID#0.0] (Suspended)
ApplicationLoader(ReferencedLoader).loadClass(String) line: 332
ApplicationLoader(ClassLoader).loadClassInternal(String) line: 302 [local variables unavailable]
ApplicationDescriptor.<init>() line: 148
ZDA2.wdDoInit() line: 97
InternalZDA2.wdDoInit() line: 105
DelegatingComponent.doInit() line: 95
DelegatingComponent(Controller).initController() line: 215
DelegatingComponent(Controller).init() line: 200
ClientApplication(ClientComponent).init() line: 346
ClientApplication.init() line: 349
WebDynproMainTask.execute() line: 599
HtmlClient(AbstractClient).executeTasks(ITask) line: 59
ClientManager.doProcessing() line: 251
DispatcherServlet.doWebDynproProcessing(Task, HttpServletRequest, HttpServletResponse) line: 154
DispatcherServlet.doContent(HttpServletRequest, HttpServletResponse) line: 116
DispatcherServlet.doGet(HttpServletRequest, HttpServletResponse) line: 48
DispatcherServlet(HttpServlet).service(HttpServletRequest, HttpServletResponse) line: 740
DispatcherServlet(HttpServlet).service(ServletRequest, ServletResponse) line: 853
HttpHandlerImpl.runServlet(String, HttpParameters, ApplicationContext) line: 391
HttpHandlerImpl.handleRequest(String, HttpParameters) line: 265
RequestAnalizer.startServlet(String) line: 345
RequestAnalizer.startServlet(MessageBytes) line: 323
RequestAnalizer.invokeWebContainer() line: 865
RequestAnalizer.handle() line: 240
Client.handle() line: 92
Processor.request(int, int, byte[], int, int) line: 148
ApplicationSessionMessageListener.process(int, int, byte[], int, int, int) line: 37
UnorderedChannel$MessageRunner.run() line: 71
ActionObject.run() line: 37
AccessController.doPrivileged(PrivilegedAction, AccessControlContext) line: not available [native method]
SingleThread.execute(ThreadContextImpl) line: 94
SingleThread.run() line: 162
I also got this :
Debugger Source Lookup
The source of the type 'com.sap.engine.frame.core.load.ReferencedLoader' could not be shown as the type was not found."
??
vivian
In my first post above is the the complete class ApplicationDescriptor.
its constructor again: (details pls see my first post)
public ApplicationDescriptor()
{
XMLReader xmlReader = null;
try
{
SAXParserFactory spfactory = SAXParserFactory.newInstance();
spfactory.setValidating(false);
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new HandelXML());
InputSource source = new InputSource("TemplateWD.xml");
xmlReader.parse(source);
} catch( SAXException e) {
e.printStackTrace();
System.exit(0);
} catch (Exception e)
{
System.err.println(e);
// System.exit(1);
System.exit(0);
}
}
I've taken the completete programm from the Webdynpro tutorial 17 "Dynamic UI Generation in WebDynpro" it ran correctly, before I add some code in the class "ApplicationDescriptor" for the upload of the data from xml-file into the arrays
the class "ApplicationDescriptor" is the same as the class "SomeBackEnd.java", except the part for the xml-handling.
here the original coding of the class "SomeBackEnd.java"
public class SomeBackEnd {
public class FieldDescriptor
{
public FieldDescriptor(String uiType, String name, String type, String label, String tooltip, Object init)
{
this.uiType = uiType;
this.name = name;
this.type = type;
this.label = label;
this.tooltip = tooltip;
this.init = init;
}
String getUIType(){ return uiType; };
String getName(){ return name; };
String getType(){ return type; };
String getLabel(){ return label; };
String getTooltip(){ return tooltip; };
Object getInit(){return init; };
private String uiType;
private String name;
private String type;
private String label;
private String tooltip;
private Object init;
}
public class OperationDescriptor
{
OperationDescriptor(String name, String displayText, String tooltip)
{
this.name = name;
this.displayText = displayText;
this.tooltip = tooltip;
}
String getName(){ return name; };
String getDisplayText(){ return displayText; };
String getTooltip(){ return tooltip; };
private String name;
private String displayText;
private String tooltip;
}
int getNumberFields()
{
return fields.length;
}
FieldDescriptor getField(int index)
{
return (FieldDescriptor)fields[index];
}
int getNumberActions()
{
return operations.length;
}
OperationDescriptor getAction(int index)
{
return (OperationDescriptor)operations[index];
}
private Object[] fields = {
new FieldDescriptor("InputField","firstName","com.sap.dictionary.string","First Name","Enter first name here",""),
new FieldDescriptor("InputField","lastName","com.sap.dictionary.string","Last Name","Enter last name here",""),
new FieldDescriptor("InputField","birthday","com.sap.dictionary.date","Date of Birth","Enter date here", null),
new FieldDescriptor("DropDownByKey","country","com.sap.tut.wd.dynamic.simpletype.Country","Country","Choose your country here",""),
new FieldDescriptor("RadioButtonGroupByKey","sex","com.sap.tut.wd.dynamic.simpletype.Sex","Sex","Choose your sex here",""),
new FieldDescriptor("CheckBox","isManager","com.sap.dictionary.boolean","Is a Manager","Checked if person is a manager", new Boolean(false))
};
private Object[] operations = {
new OperationDescriptor ("delete", "Delete", "Delete your input."),
new OperationDescriptor ("save", "Save", "Save current record."),
};
}
<b>I'm very sorry, that was the code from my first post. Now the code in the program.</b>
public ApplicationDescriptor()
{
XMLReader xmlReader = null;
try
{
SAXParserFactory spfactory = SAXParserFactory.newInstance();
spfactory.setValidating(false);
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new HandelXML());
InputSource source = new InputSource
(
this.getClass().getClassLoader().getResource("TemplateWD.xml").toExternalForm()
);
xmlReader.parse(source);
} catch( SAXException e) {
e.printStackTrace();
System.exit(0);
} catch (Exception e)
{
System.err.println(e);
System.exit(0);
}
}
Vivian,
Then,
1. NEVER USE THIS:
try
{
...
} catch (Exception e)
{
System.err.println(e);
<b>System.exit(0);</b>
}
Instead do something like this:
try
{
...
} catch (Exception e)
{
System.err.println(e);
<b>throw new RuntimeException(ex);</b>
}
Otherwise you are stopping web server.
2. Try to place "TemplateWD.xml" to nested folder, say /src/packages/<b>xslt/TemplateWD.xml</b> -- JDK 1.4 doesn't like "default" package, so probably this causes such magic error. Also replace line with InputSource to
InputSource source = new InputSource
(
ApplicationDescriptor.class.getClassLoader()
.getResource("xslt/TemplateWD.xml")
.toExternalForm()
);
VS
Hi,
thank you for the hint about shutting down the Server. Now I don't have to wait for the restart of the server.
I tried different ways to provide the path of the xml-file. it still failed to find it
"at com.sap.fy.zda2.ApplicationDescriptor.<init>(ApplicationDescriptor.java:153)"
I got during debugging the popup "Debugger Source Lookup"
for "The source of the type 'com.sap.engine.frame.core.load.ReferencedLoader' could not be shown as the type was not found."
and then the message
"Source not found for ApplicationLoader(ResourceLoader).getResource(String)line:163"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vivian,
please provide some more info. Post the stacktrace of your exception.
regards
Sebastian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.