Headless Client Examples

I’ve put together the headless client demos (2 of them) with 2 solutions. You can download from here:

http://developer.servoy.com/downloads/headless_client_examples.zip

Hope this helps inspire you to work with the headless client.

Very nice work Bob 8) … Thanks.
Looking forward putting Headless Clients on a Headless Mac Mini :idea:

I have the two sample solutions up and running. Very impressive. More powerful than I expected and extremely easy for the end user.

One possible bug is that when I go to exit the solution, a dialog appears that states “Application server will be shutdown, please close within 3 minutes.” Then Servoy appears to hang with the following message in the status bar at lower left of screen: “Informing clients about shutdown.” However, all browser clients are already closed and no Servoy Clients are open. I am still not sure how to make the Headless Client work with Servoy’s built-in security.

Otherwise, everything works extremely well. Everyone should be sure to take a look at these two samples. The first one shows a Customer list, Company details, and Orders per Company with sum totals, all viewable in a browser via desktop, laptop or PDA device, using a single JSP page. The second example shows how to edit and update data, and also how to retrieve valuelist information from your solution and build a pop-up menu. Nice stuff!

I have one coding question. In the Contacts detail what would be the syntax for including a list of phone numbers from a related file?

Great job!

Really great feature! Can’t wait to build something nice with it! I do have a slight little problem;
http://localhost:8080/jsp_files/simplelistview.jsp is working perfectly, but I get ```
Access is denied or Error occurred

at http://localhost:8080/jsp_files/headless_client_formtest.jsp.

Could it be that this does not work on OS X? 
I found out that OS X does not have a separate 'tools.jar'....
Would be to bad, 'cause I host my solutions and websites on an OS X Server...

Westy:
I have the two sample solutions up and running. Very impressive. More powerful than I expected and extremely easy for the end user.

AND for the coder! I mean, if you had to write all of that in JSP - it’s tons of work. With Servoy = EASY!

Westy:
One possible bug is that when I go to exit the solution, a dialog appears that states “Application server will be shutdown, please close within 3 minutes.” Then Servoy appears to hang with the following message in the status bar at lower left of screen: “Informing clients about shutdown.” However, all browser clients are already closed and no Servoy Clients are open.

Best thing to do is to log into the Servoy Server (http://yourIP:8080/servoy-admin/) then go to the “clients” tab and DISCONNECT the headless client (click the red “X”). You need to do that when you make changes to your .jsp page or to a method in your solution that gets called by the page. This will force JSP to create a new session.

Westy:
I am still not sure how to make the Headless Client work with Servoy’s built-in security.

I’ll have to write a sample that shows you how to do that - it EASY to create a method and then use the “Security” settings to check a password. :D

Westy:
I have one coding question. In the Contacts detail what would be the syntax for including a list of phone numbers from a related file?

Same as when using a label: relationName.fieldName

freecolours:
I get ```
Access is denied or Error occurred

at http://localhost:8080/jsp_files/headless_client_formtest.jsp.

Could it be that this does not work on OS X?

Does work on OS X - David Workman (servoy magazine) has it working. I haven’t tried it on my mac yet - but will do.

If you look at the code - it means that the application can’t reference that FORM. Did you import both solutions?

bcusick:
Did you import both solutions?

Yes, I did.

Rather than put the LOGIN example in another solution and make you download it - I’m going to just post the code.

To make this example work:

  1. Make a new solution called “example_headless_client_03” and make a form called “login” (doesn’t have to have anything on it).

  2. Make a FORM-BASED method called “login” with this code:

var noPass = "<font color='#990000'><b>Invalid Login.</b> Try again.</font>
"
var isOK = "<font color='#009900'><b>VALID LOGIN!</b> Contratulations.</font>
"
var isEmpty = "<font color='#990000'><b>No criteria entered.</b> Try again.</font>
"

var name = arguments[0]
var pass = arguments[1]

if(name == null || name == '' || pass == null || pass == '')
{
	//something is blank - return false
	return isEmpty
}

var userId = security.getUserId(name)

if(security.checkPassword(userId, pass))
{
	//they were ok
	return isOK
}
else
{
	//no match
	return noPass
}
  1. Create a new text document and paste in the code below and save inside the servoy/server/webapps/root/example/ folder:
<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.dataprocessing.IDataSet" %>
<%@ page errorPage="errorpage.jsp" %>
<%
	ISessionBean servoy_hc = (ISessionBean)session.getAttribute("servoy");
	if (servoy_hc == null)
	{
		servoy_hc = HeadlessClientFactory.createSessionBean(request,"example_headless_client_03");
		session.setAttribute("servoy",servoy_hc);
	}
	boolean ok = servoy_hc.setMainForm("login");
	if (!ok)
	{
		servoy_hc = HeadlessClientFactory.createSessionBean(request,"example_headless_client_03");
		session.setAttribute("servoy",servoy_hc);
	}
	
	String theTable = null;
	String isSubmit = request.getParameter("isSubmit");
	
	if (null!=isSubmit)
	{
		theTable = (String)servoy_hc.executeMethod(null,"login",new Object[]{request.getParameter("username"),request.getParameter("password")});
	}

%>
<html>
<head>

<style type="text/css">

</style>

<title>Servoy Headless Client Login Example</title>
</head>
<body onload="javascript:document.loginform.username.focus()">
  <%
  	if (theTable!=null) out.println(theTable);
%>
  <form name="loginform" method="post" action="simplelogin.jsp">
    <table border="0" cellspacing="0" cellpadding="2">
      <tr>
        <td colspan="2" class="sub"> <b>Login</b></td>
      </tr>
      <tr>
        <td>Username</td>
        <td><input name="username" type="text" id="username" size="15" maxlength="30"></td>
      </tr>
      <tr>
        <td>Password</td>
        <td><input name="password" type="password" id="password" size="15" maxlength="30"></td>
      </tr>
      <tr>
        <td colspan="2" align="right">
          <input name="Submit" type="submit" value="Submit">
		  <input type="hidden" name="isSubmit" value="1">
        </td>
      </tr>
    </table>
  </form>
</body>
</html>
  1. Open a browser and enter the URL: http://yourIP:8080/examples/simplelogin.jsp If you enter ANY valid username and password (in YOUR Servoy Security) - you should get a “Valid Login” message.

Hope this helps.

Hey Bob,

I was wondering if you have a unbroken link to these headless client solutions mentioned above?

garry.mack:
Hey Bob,

I was wondering if you have a unbroken link to these headless client solutions mentioned above?

Headless client examples are an installation option when you install Servoy developer. You’ll find a headless client directory in your “Servoy/application_server/server/webapps/ROOT” directory if installed them.