Error message using the Java API for X-application

X-Application Version: 3.1.2, 3.1.1
Tamino Version : 3.1.1
Platform : Win2k,
WebContainer : Tomcat 4.0
JDK Version : 1.3.1

Hey all,
I’m having a problem while using the Java API with X-app.
The Problem occurs when I use the read() method. One of the parameters it accepts is a document string which I cannot figure out what to name as. Also the second string is an ID which is passed.
I am creating an application to help a user select a particular car, and then help him select a list of accessories using checkboxes, which we have already been able to link with the site. The next step is to compute the total cost of all the accessories that the user selects with the checkboxes and displays the results. We used the following lines of code but havea few errors creeping up.
<% SessionContext sessionContext = ServletSessionContext.getSessionContext(pageContext);

BusinessDocumentWorkspace ws = sessionContext.getWorkspace();

double sum=0;
for (int i = 0; i < values.length; i++) {
BusinessDocument doc = ws.read(“current”, “/car/accessory[ino:id=”+ values[i] + “]”);
sum += Double.parseDouble(doc.getRoot().getDescendant(“accprice”).getValue());
}
%>

I am getting the following error,
javax.servlet.ServletException: more than one element found in database: /car/accessory[ino:id=‘1’]


The structure of the XML is :


|
|




|
|



|
|




I am including all the files i am using in the project. Can someone please tell me where I am going astray?
Thanks,
Parth

I don’t understand why you get this particular error message, but the query looks weired to me. The ino id is an attribute of the root element, thus the query should be
/car/accessory[ino:id=‘1’]

Michael

Software AG Germany, Darmstadt

X-Application Version: 3.1.2, 3.1.1
Tamino Version : 3.1.1
Platform : NT, Win2k, Solaris, …
WebContainer : Tomcat 3.3
JDK Version : 1.3.1

Hello Parth,

the first parameter of the read operation is the name of the document you can get it from workspace after the operation is processed, e.g.

ws.read(?myDoc?, …);

doc = ws.lookup(?myDoc?);

For your checkbox problem: Accessory is a sub-element of car. There are no accessory documents you can request. Therefore you cannot use the ino:id to identify with accessories the user selected. But I have seen you have accID. Use this element to fill the select box this values and look for these accID on server side.

BusinessDocument doc = ws.lookup(?current?);
BusinessNode accessories = doc.getRoot().getDescendantByContent(?accessory?);
for (int i = 0; i < values.length; i++) {
for (int j = accessories.getChildCount() - 1; j >= 0; j–) {
BusinessNode accessory = accessories.getChild(i);
if (values[i].equals(accessory.getDescedant(?accID?).getValue()) {
sum += Double.parseDouble(accesseory.getDescedant(?accprice?));
break;
}
}

Remark: the name of the document is ?current? if you didn?t use the attribute ?document? to name document the user currently use for selecting the accessories. If you used the document attribute replace ?current? by its value to look up the document.

I hope you will have success with this approach.

Bye,
Christian.