Update on JSP

Any one to help with update on JSP

here is my code, I’m getting a value from the textbox.

<%tr = tam.update(employees, employeeNo.setNodeValue(request.getParameter(“updateName”)));

Error:org.apache.jasper.JasperException: Unable to compile class for JSPC:\jakarta-tomcat-3.2.1\work\localhost_8080%2Fexamples_0002ftaminoproject_0002fUpdate_0002ejspUpdate_jsp_46.java:486: Incompatible type for method. Can’t convert void to java.lang.String.
tr = tam.update(employees, employeeNo.setNodeValue(request.getParameter(“updateName”)));
^

In your code you say:

code:

<%tr = tam.update(employees, employeeNo.setNodeValue(request.getParameter(“updateName”)));


Assuming employeeNo is a DOM1 Node, setNodeValue(String) will just set the node value to a value and return void.

You then try to use this void return as a parameter to tam.update(Element,String). But void can’t be converted to a String - hence the error.

I think what you mean to do is
1) employeeNo.setNodeValue(request.getParameter(“updateName”));
and then
2) tr= tam.update(employeeElement,ino:id,collection,doctype );

Still can’t get this to work.

<%@ page language="java" contentType="text/html" %>
<%@ page import="com.softwareag.tamino.api.dom.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="taminoproject.BeanInsert" %>
<%@ page import="taminoproject.Query" %>
<%@ page import = "com.docuverse.dom.*" %>
<% BeanInsert bi = new BeanInsert();%>

<%@ include file="Template.html"%>



<% String modify = request.getParameter("choice"); %>


<%TaminoResult tr = null;
TaminoResult tru = null;
String qname = "";
boolean conf = true;
Element firstname = null;
TaminoClient tam = new TaminoClient("http://localhost/tamino/Employees/Employees");
tam.startSession();
tam.setPageSize(5);%>

<% tr = tam.query("Employees[FirstName=\""+modify+"\"]");%>

<%while(tr.hasMoreElements()){%>

<% firstname = (Element)tr.getNextElement();%>

<%Element nam = (Element)firstname.getElementsByTagName("FirstName").item(0);%>
<%Element nam1 = (Element)firstname.getElementsByTagName("LastName").item(0);%>

Update : <%= nam.getFirstChild().getNodeValue()%> <%=nam1.getFirstChild().getNodeValue()%>




<%Element employeeNo = (Element)firstname.getElementsByTagName("EmployeeNo").item(0);%>



<%Element Name = (Element)firstname.getElementsByTagName("FirstName").item(0);%>

<%="First Name" + Name%>

<%="First Name" + firstname%>


<%Element lastName = (Element)firstname.getElementsByTagName("LastName").item(0);%>



<%Element idno = (Element)firstname.getElementsByTagName("IdNumber").item(0);%>



<%Element dob = (Element)firstname.getElementsByTagName("Date_of_Birth").item(0);%>



<%Element comp_nam = (Element)firstname.getElementsByTagName("Company_Name").item(0);%>



<%Element title =(Element)firstname.getElementsByTagName("Title").item(0);%>



<%Element telephone = (Element)firstname.getElementsByTagName("Telephone").item(0);%>


<%Element fax =(Element)firstname.getElementsByTagName("Fax").item(0);%>


<%Element email =(Element)firstname.getElementsByTagName("Email").item(0);%>


<%Element street =(Element)firstname.getElementsByTagName("Street").item(0);%>


<%Element city =(Element)firstname.getElementsByTagName("City").item(0);%>


<%Element country =(Element)firstname.getElementsByTagName("Country").item(0);%>

Employee Number :
>
First Name :
>
Last Name : <input
type="text" name="updateLastName" value=<%=lastName.getFirstChild().getNodeValue()%>>
Id Number :
>
Date of Birth :
>
Company Name : <input
type="text"name="updateCoName" value=<%=comp_nam.getFirstChild().getNodeValue()%>>
Title :
>
Telephone Number : <input
type="text"name="updateTel" value=<%=telephone.getFirstChild().getNodeValue()%>>
Fax Number :
>
Email Address : <input
type="text"name="updateEmail" value=<%=email.getFirstChild().getNodeValue()%>>
Street Name : <input
type="text"name="updateStreet" value=<%=street.getFirstChild().getNodeValue()%>>
City : <input type="text"name="updateCity"
value=<%=city.getFirstChild().getNodeValue()%>>
Country : <input type="text"name="updateCount"
value=<%=country.getFirstChild().getNodeValue()%>>

<%}%>


<%if (request.getMethod().equals("POST")) { %>
<%try{%>
<%while(tr.hasMoreElements()){%>
<%Element el = (Element) tr.nextElement();
tr = tam.update(el,"Employees","Employees");
tam.commit(true);%>
<%}%>
<% tam.endSession();%>
<%}%><%catch(IOException e){%>
<%= e.getMessage() %>

<%}%>
<%}%>






In your code you didn’t update anything.
In the update section:

code:

Element el = (Element) tr.nextElement();
tr = tam.update(el,“Employees”,“Employees”);


you get the nextElement of the tamino result (which is not the Element you displayed to the user) and you update it without changing it.

Attached is a small working example using the supplied RealEstate demo data.I think it does what you need.
To see the example,


  • set the url of Tamino RealEstate data into the jsp page, and
  • invoke the base URL of the jsp page with parameter "?choice=CASAN00001"

Hope it helps.

[This message was edited by Bill Leeney on 22 Oct 2001 at 17:44.]
APITest.jsp (1.85 KB)

I get a nullPointerException. I rechecked the code and everything is corret. when I click the update button the error occurs.

You get this if the property you ask for does not exist, or has no price (there is no error checking in the example).
Please check that:


  • The database, collection and doctype are specified correctly in the Tamino Client instantiation, the query and the update statement in your jsp
  • You have loaded some example Property data
  • The URL parameter ‘?choice=’ specifies an existing ‘PropertyReference’ attribute value
  • The chosen Property has a price element

For me, this URL works:
http://localhost:8080/Property/APITest.jsp?choice=CASAN00001

This URL gets the Property record:
<A HREF="http://natserv2/tamino/RealEstate/Property?_XQL=Property[@PropertyReference=“CASAN00001"” TARGET=_blank>http://natserv2/tamino/RealEstate/Property?_XQL=Property[@PropertyReference=“CASAN00001”

[This message was edited by Bill Leeney on 23 Oct 2001 at 11:25.]

Your Example works fine I’ve changed your connections and queries to Tamino in order to query my database I get the results but the problem occurs where I have to Update. When I h ref to another page the …Confirm.jsp?updated=null, I guess the value does not update. the reason I say this is I pass the updated value to the next page ad I use the value to query the database. I dried in SQL (though they not the same with tamino) and it works fine. Here is the code:

<%@ page language=“java” contentType=“text/html” %>
<%@ page import=“com.softwareag.tamino.api.dom." %>
<%@ page import="org.w3c.dom.
” %>
<%@ page import=“com.docuverse.dom." %>
<%@ page import="javax.servlet.
”%>


<% String modify = request.getParameter(“choice”); %>


You asked to update the name:<%=modify%>
<% TaminoResult tr = null;
TaminoClient tam = new TaminoClient(“http://localhost/tamino/Employees”);
tam.setPageSize(5);
tam.startSession();
tr = tam.query(“Employees[FirstName=”"+modify+""]",“Employees”);
Element doc = (Element) tr.nextElement();
NodeList empNo_node = doc.getElementsByTagName(“EmployeeNo”);
NodeList fNam_node = doc.getElementsByTagName(“FirstName”);
NodeList lNam_node = doc.getElementsByTagName(“LastName”);
NodeList idNo_node = doc.getElementsByTagName(“IdNumber”);
NodeList dob_node = doc.getElementsByTagName(“Date_of_Birth”);
NodeList coNam_node = doc.getElementsByTagName(“Company_Name”);
NodeList title_node = doc.getElementsByTagName(“Title”);
NodeList tel_node = doc.getElementsByTagName(“Telephone”);
NodeList fax_node = doc.getElementsByTagName(“Fax”);
NodeList email_node = doc.getElementsByTagName(“Email”);
NodeList street_node = doc.getElementsByTagName(“Street”);
NodeList city_node = doc.getElementsByTagName(“City”);
NodeList country_node = doc.getElementsByTagName(“Country”);
NodeList zip_node = doc.getElementsByTagName(“ZIP”);

Node empEl = empNo_node.item(0);
Node fNamEl = fNam_node.item(0);
Node lNamEl = lNam_node.item(0);
Node idNoEl = idNo_node.item(0);
Node dobEl = dob_node.item(0);
Node coNamEl = coNam_node.item(0);
Node titleEl = title_node.item(0);
Node telEl = tel_node.item(0);
Node faxEl = fax_node.item(0);
Node emailEl = email_node.item(0);
Node streetEl = street_node.item(0);
Node cityEl = city_node.item(0);
Node countryEl = country_node.item(0);
Node zipEl = zip_node.item(0);

%>
<%
if (request.getMethod().equals(“POST”)) {
empEl.getFirstChild().setNodeValue(request.getParameter(“empNo”));
fNamEl.getFirstChild().setNodeValue(request.getParameter(“Fnam”));
lNamEl.getFirstChild().setNodeValue(request.getParameter(“lnam”));
idNoEl.getFirstChild().setNodeValue(request.getParameter(“idno”));
dobEl.getFirstChild().setNodeValue(request.getParameter(“dob”));
coNamEl.getFirstChild().setNodeValue(request.getParameter(“coname”));
titleEl.getFirstChild().setNodeValue(request.getParameter(“tit”));
telEl.getFirstChild().setNodeValue(request.getParameter(“tel”));
faxEl.getFirstChild().setNodeValue(request.getParameter(“fax”));
emailEl.getFirstChild().setNodeValue(request.getParameter(“email”));
streetEl.getFirstChild().setNodeValue(request.getParameter(“street”));
zipEl.getFirstChild().setNodeValue(request.getParameter(“zip”));
cityEl.getFirstChild().setNodeValue(request.getParameter(“city”));
countryEl.getFirstChild().setNodeValue(request.getParameter(“country”));
try {
tr = tam.update(doc,“Employees”,“Employees”);
System.out.println(tr);
tam.commit(true);
}
catch(IOException e){
System.err.println(e.getMessage());
}
}
%>

<form method=“POST” action=“Confirm.jsp?updated<%=request.getParameter(“Fnam”)%>”>











































Employee No :
<input type=text" name=“updatePrice” value=<%=empEl.getFirstChild().getNodeValue()%>>
First Name :
<input type=“text” name=“Fnam” value=<%=fNamEl.getFirstChild().getNodeValue()%>>
Last Name :
<input type=“text” name=“lnam” value=<%=lNamEl.getFirstChild().getNodeValue()%>>
Id Number :
<input type=“text” name=“idno” value=<%=idNoEl.getFirstChild().getNodeValue()%>>
Date Of Birth :
<input type=“text” name=“dob” value=<%=dobEl.getFirstChild().getNodeValue()%>>
Company Name :
<input type=“text” name=“coname” value=<%=coNamEl.getFirstChild().getNodeValue()%>>
Title :
<input type=“text” name=“tit” value=<%=titleEl.getFirstChild().getNodeValue()%>>
Telephone:
<input type=“text” name=“tel” value=<%=telEl.getFirstChild().getNodeValue()%>>
Fax Number :
<input type=“text” name=“fax” value=<%=faxEl.getFirstChild().getNodeValue()%>>
Emai Address :
<input type=“text” name=“email” value=<%=emailEl.getFirstChild().getNodeValue()%>>
Street :
<input type=“text” name=“street” value=<%=streetEl.getFirstChild().getNodeValue()%>>
Zip :
<input type=“text” name=“zip” value=<%=zipEl.getFirstChild().getNodeValue()%>>
City :
<input type=“text” name=“city” value=<%=cityEl.getFirstChild().getNodeValue()%>>
Country :
<input type=“text” name=“country” value=<%=countryEl.getFirstChild().getNodeValue()%>>








Your code:
<form method=“POST” action=“Confirm.jsp?updated<%=request.getParameter(“Fnam”)%>”>
is missing an equals sign. It should be:
<form method=“POST” action=“Confirm.jsp?updated=<%=request.getParameter(“choice”)%>”>

It doesn’t make a difference I Tested with the = sign

What’s in Confirm.jsp? (please attach it to your next post).

Confirm is the result page. After updating then you can see the values you’ve updated. The funny part is if I don’t pass to the confirm.jsp it works, but as soon as I pass the parameter and handle it in the Confirm.jsp after, I run a query with the same value I came with (request.getParameter()). If the record has been updated I should get the value.
Confirm.jsp (4.63 KB)

In “Confirm.jsp” you retrieve a request parameter called “modified”:
%String updated = request.getParameter(“modified”);%>
…but in the calling page, you pass parameter “updated”:
<form method=“POST” action=“Confirm.jsp?updated=<%=request.getParameter(“Fnam”)%>”>

If you make them both the same it should work.

Thanks for the patience