include jsp

Hi,

I am trying to build a webshop with the headless client.
At first I hard coded the menu and everything worked fine.
But then I placed the menu in another .jsp, retreived the menu items from my db and included it in my index file.
Now the data in my main grid isn’t loaded anymore ??

Here is my full code :

index.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.util.*" %>
<%@ 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,"headless_client_demo");
		session.setAttribute("servoy",servoy_hc);
	}
	boolean ok = servoy_hc.setMainForm("article");
	if (!ok)
	{
		out.print("error cannot work on required form");
		return;
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Globis Online</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="header_top"></div>
<div id="container">
  
  <div id="header">
		<div id="header_top"></div>
  		<div id="header_logo">
   		  	  <div id="header_nav">
              		<p class="nav_top"><a href="#">Account</a></p>
                    <p class="nav_top"><a href="#">Zoeken</a></p>
                    <p class="nav_top"><a href="#">Winkelwagen</a></p>
                    <p class="nav_top_nospacer"><a href="#">Inloggen</a></p>
              </div>
              <div id="header_search">
              		<form method="post">
              		<input id="search_field" type="text" name="search_keywords" value=""/>
                    </form>
              </div>
              <div id="header_cart">
              	<h1>WINKELWAGEN</h1>
                Geen artikelen
              </div>
        </div>
  </div>
  
  <div id="content_container">
    	<div id="sidebar">
            <ul id="nav_menu">
                <%@ include file="navigation_maingroups.jsp" %>
            </ul>
            <div id="spotlight">
            </div>
        </div>
        <div id="mainContent">
			<h1 id="titleMain">ARTIKEL CATALOGUS</h1>
			<%
				
				String s;
				int number;
				for (int i = 0 ; i < 70 ; i++)
				{
					number = i%3;
					s = "<div class=\"grid"+number+"\"><h1>"+servoy_hc.getDataProviderValue(null,"article_code")+"</h1>";
					s += "<h2>"+servoy_hc.getDataProviderValue(null,"article_to_articletranslations$full_description$language_code_user.description")+"</h2>";
					s += "<div class=\"detail_link\"><a href=\"article_detail.jsp?id="+servoy_hc.getDataProviderValue(null,"article_id")+"\">Detail</a></div></div>";
					servoy_hc.executeMethod(null,"nextRecord",null);
					
					if(number == 2)
					{
							s += "<div><hr /></div>";
					}
					
					out.print(s);
				}
				
				
			%>
        </div>
  </div>

</div>
</body>
</html>

navigation_maingroups.jsp

<%
	ISessionBean servoy_hc_nav = (ISessionBean)session.getAttribute("servoy");
	if (servoy_hc_nav == null)
	{
		servoy_hc_nav = HeadlessClientFactory.createSessionBean(request,"headless_client_demo");
		session.setAttribute("servoy",servoy_hc_nav);
	}
	boolean ok_nav = servoy_hc_nav.setMainForm("navigation_maingroups");
	if (!ok_nav)
	{
		out.print("error cannot work on required form");
		return;
	}
%>

<ul id="nav_menu">
    <%
    
    int i_nav = 1;
    String s_nav = "";
    servoy_hc_nav.executeMethod(null,"getFirstRecord",null);
    
    while(i_nav<27) 
    {
        servoy_hc_nav.executeMethod(null,"getNextRecord",null);
        s_nav += "<li><a href=\"#\">"+servoy_hc_nav.getDataProviderValue(null,"articlemaingroup_code")+"</a></li>";
        i_nav++;
    }
    out.print(s_nav);
    %>
</ul>

I have no idea what is happening here…Maybe something with the controller?

Thank you.

Robrecht Van Melckebeke

Just tested it a little more and this thing drives me crazy…

When I include “navigation_maingroups.jsp” after I get the article data, everything works fine…???

When I place the article data in another file eg. article_lst.jsp, the problem is solved…

Does anyone know what causes this behaviour?

Oh man! Why bother with JSP when such things are so much easier to do with Velocity?
https://www.servoyforge.net/projects/velocity-report
and the Wiki documentation about the Velocity Web client:
https://www.servoyforge.net/projects/ve … /WebClient

ptalbot:
Oh man! Why bother with JSP when such things are so much easier to do with Velocity?

+1 :!:

Because I went to the Servoy HQ last friday for a consultancy session there and they recommended me to work with JSP instead of Velocity
Besides, I tried Velocity myself before and I didn’t like it that much.

Hi,

robrecht:
Because I went to the Servoy HQ last friday for a consultancy session there and they recommended me to work with JSP instead of Velocity

You also asked how much experience they have with Patrick’s Velocity plugin ?

robrecht:
Besides, I tried Velocity myself before and I didn’t like it that much.

I am pretty sure that after you dabbled long enough in JSP that Velocity will seem like a breath of fresh air to you.

Just saying…

robrecht:
I have no idea what is happening here…Maybe something with the controller?

Included files run in the context of the jsp that they are included on, not in their own context. So, initializing another ISessionBean in your include file is creating a conflict.

Remove the ISessionBean code from your navigation snippet and scope method calls to the form those methods are on:

<ul id="nav_menu">
    <%
    
    int i_nav = 1;
    String s_nav = "";
    servoy_hc.executeMethod("navigation_maingroups","getFirstRecord",null);
    
    while(i_nav<27) 
    {
        servoy_hc.executeMethod("navigation_maingroups","getNextRecord",null);
        s_nav += "<li><a href=\"#\">"+servoy_hc.getDataProviderValue("navigation_maingroups","articlemaingroup_code")+"</a></li>";
        i_nav++;
    }
    out.print(s_nav);
    %>
</ul>