Triggering a method

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

Triggering a method

Postby Morley » Wed Jun 28, 2006 10:29 pm

In debugging a routine I've narrowed the JSP code down to the following:

Code: Select all
<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.dataprocessing.IDataSet" %>
<%@ page errorPage="error.jsp" %>
<%

   // start a headless client session
   ISessionBean servoy_hc = HeadlessClientFactory.createSessionBean(request,"newClient");
   session.setAttribute("servoy",servoy_hc);

   boolean ok = servoy_hc.setMainForm("scraNewClient");
   if (!ok)
   {
      out.print("error cannot work on required form");
      return;
   }
   
   // add the record
   servoy_hc.executeMethod(null,"newRecord",null);
   
   servoy_hc.saveData();

%>
Result. A session is created in the newClient.servoy solution. However no new record is triggered. Using Developer I can manually trigger scraNewClient.newRecord but the JSP isn't running the method.

Can someone spot what I'm missing?

Thanks,
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Joas » Thu Jun 29, 2006 11:33 am

Do you get any errors or exceptions when browsing to the page?
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Postby Jan Aleman » Thu Jun 29, 2006 1:50 pm

A mistake I often make is not having a saveData in the newrecord method. In headless you need to explicitely call saveData to 'commit' any changes.
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Morley » Thu Jun 29, 2006 3:16 pm

jaleman wrote:A mistake I often make is not having a saveData in the newrecord method. In headless you need to explicitely call saveData to 'commit' any changes.
Revised newRecord method to:
Code: Select all
controller.newRecord();
controller.saveData();
A session is created. No new record is created.

Errors:
2006-06-29 09:05 : Error occured informing client plugin udp, error: java.lang.NullPointerException
2006-06-29 09:05 : Error occured informing client plugin udp, error: java.lang.NullPointerException
2006-06-29 09:19 : Error occured informing client plugin udp, error: java.lang.NullPointerException

I've double checked for typos. The form indeed is called scraNewClient and the method is called newRecord.

This is very puzzling indeed.
Last edited by Morley on Thu Jun 29, 2006 3:26 pm, edited 1 time in total.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Jan Aleman » Thu Jun 29, 2006 3:25 pm

Try this:

add one line to your method:

Code: Select all
return "ok"


change your page to this:

Code: Select all
<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.dataprocessing.IDataSet" %>
<%@ page errorPage="error.jsp" %>
<%

   // start a headless client session
   ISessionBean servoy_hc = HeadlessClientFactory.createSessionBean(request,"newClient");
   session.setAttribute("servoy",servoy_hc);

   boolean ok = servoy_hc.setMainForm("scraNewClient");
   if (!ok)
   {
      out.print("error cannot work on required form");
      return;
   }
   
   // add the record
   String vresult = (String)servoy_hc.executeMethod(null,"newRecord",null);
    out.println(vresult);

%>
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Morley » Thu Jun 29, 2006 3:43 pm

jaleman wrote:Try this:

add one line to your method:

Code: Select all
return "ok"


change your page to this:

Code: Select all
<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.dataprocessing.IDataSet" %>
<%@ page errorPage="error.jsp" %>
<%

   // start a headless client session
   ISessionBean servoy_hc = HeadlessClientFactory.createSessionBean(request,"newClient");
   session.setAttribute("servoy",servoy_hc);

   boolean ok = servoy_hc.setMainForm("scraNewClient");
   if (!ok)
   {
      out.print("error cannot work on required form");
      return;
   }
   
   // add the record
   String vresult = (String)servoy_hc.executeMethod(null,"newRecord",null);
    out.println(vresult);

%>

Revised both the method and the JSP as recommended and then rebooted the Server. Result is OK printed to the web page. A session is created. No new record. No errors in the server log.

In my experiments prior to posting here I occasionally got server errors like this one:
2006-06-29 09:05 : Error occured informing client plugin udp, error: java.lang.NullPointerException


Kind regards,
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Morley » Thu Jun 29, 2006 3:53 pm

At first there's no server error, but if I check again two or three minutes later, here's the log:
2006-06-29 09:32 : Loading servoy.properties from /Applications/Servoy/servoy.properties
2006-06-29 09:32 : Loading - Done
2006-06-29 09:32 : Using RMI registry on port 1099
2006-06-29 09:47 : Error occured informing client plugin udp, error: java.lang.NullPointerException
2006-06-29 09:47 : Error occured informing client plugin udp, error: java.lang.NullPointerException
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby ROCLASI » Thu Jun 29, 2006 6:04 pm

Hi Morley,

First, the UDP plugin error has nothing to do with your problem. You can ignore it.
Can you show us what your newRecord method looks like ? Maybe the issue is in there.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Postby Morley » Thu Jun 29, 2006 8:57 pm

ROCLASI wrote:First, the UDP plugin error has nothing to do with your problem. You can ignore it.
Can you show us what your newRecord method looks like ? Maybe the issue is in there.
Here's the whole of it.
Code: Select all
controller.newRecord();
controller.saveData();
return 'ok';
The return of OK appears on the web page, thus demonstrating the method is indeed being triggered.

I've set Servoy Developer's preferences to pull data from the server via the net rather than locally. Due to other needs, I've switched back to localhost and back again. Consistently no new records have been created in that table today.

Given the positioning of Jan's OK signal, it would be reasonable to assume (I think) Servoy has at least attempted to send a new record command to the back end. If that assumption is correct, then why is the backend accepting the method when run via Developer (which it does) but not when triggered by the JSP?

Are there other commands to add to the newRecord method which will tease out what's going on here? Are there additional logs to be examined?

Thanks for your attention to this problem,
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Jan Aleman » Thu Jun 29, 2006 9:02 pm

Do the security settings on the solution allow creation of record to anonymous users?
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Jan Aleman » Thu Jun 29, 2006 9:02 pm

Do the security settings on the solution allow creation of record to anonymous users?
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Morley » Thu Jun 29, 2006 11:07 pm

jaleman wrote:Do the security settings on the solution allow creation of record to anonymous users?
There's no log-in required on this solution as yet. I'll cross that bridge once I've got the basics running.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Jan Aleman » Fri Jun 30, 2006 9:42 am

Can you try adding a loadAllRecords before you create?
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Morley » Fri Jun 30, 2006 7:49 pm

jaleman wrote:Can you try adding a loadAllRecords before you create?
The newRecord method is now:
Code: Select all
controller.loadAllRecords();
controller.newRecord();
controller.saveData();
return 'ok';
I run the JSP. Session is launched, OK is returned, no new record is created.

In the hope of getting more info on what's going on I now revise newRecord to:
Code: Select all
controller.loadAllRecords();
var vSize1 = foundset.getSize();
return vSize1;
controller.newRecord();
controller.saveData();
var vSize2 = foundset.getSize();
return vSize2;
return 'ok';
I restart the server and then re-run the JSP. Instead of saying OK, the web page now reports
Access is denied or Error occurred:
The server log was checked before running the JSP and I've checked it again (clicking Refresh) after the JSP run. It remains unchanged before and after:
2006-06-30 13:29 : Loading servoy.properties from /Applications/Servoy/servoy.properties
2006-06-30 13:29 : Loading - Done
2006-06-30 13:30 : Using RMI registry on port 1099
2006-06-30 13:31 : Error occured informing client plugin udp, error: java.lang.NullPointerException

====
I've been getting that mysterious client plugin udp error message erratically throughout my recent attempts to get newClient to function. For instance, earlier today I uploaded a new version of newClient (with your recommended addition to the newRecord method) and then restarted the server (in order to flush anything left over from the previous run).

The log now presented me with:
2006-06-30 12:55 : Loading servoy.properties from /Applications/Servoy/servoy.properties
2006-06-30 12:55 : Loading - Done
2006-06-30 12:55 : Using RMI registry on port 1099
2006-06-30 12:55 : Error occured informing client plugin udp, error: java.lang.NullPointerException
This is before running the JSP or doing anything.

Given the fact this error turns up when just uploading a new version of the newClient solution and doing nothing else I'm assuming this error has nothing to do with the failure of the newRecord method.

Earlier today I checked Batch Processors to see what might be running there. I found two, the solution called dailyUpdate.servoy (which launches some chrons to massage the database daily). That's been in place for some time and has always worked flawlessly without error messages. The second one was newClient (which does nothing but wait for a JSP to send it instructions.)

As I write this report following the two experiments reported above I can see there are two clients running -- dailyUpdate and newClient. But if I go to Batch Proessors dailyUpdate is running and newClient is not running. Not sure of the significance, if any.

I mention all this in an effort to be thorough in reporting. Let me know if this helps in understanding what's going on here.

Cheers,
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Morley » Fri Jun 30, 2006 10:39 pm

In order to further simplify the situation I'd like to (temporarily) remove the batch process dailyUpdate already operational on the server. The Batch Processors screen says:
To remove an existing batch process click delete after the process name.
But there's no Delete button or that word anywhere on this screen. The Remove button stops the process, but if I restart the server the dailyUpdate bach process gets relaunched. How do I stop it completely?
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Next

Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 8 guests