include jsp

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

include jsp

Postby robrecht » Thu Sep 06, 2012 11:16 am

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
Code: Select all
<%@ 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

Code: Select all
<%
   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
Last edited by robrecht on Thu Sep 06, 2012 11:40 am, edited 1 time in total.
robrecht
 
Posts: 99
Joined: Wed Aug 01, 2012 4:30 pm

Re: include jsp

Postby robrecht » Thu Sep 06, 2012 11:40 am

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.....???
robrecht
 
Posts: 99
Joined: Wed Aug 01, 2012 4:30 pm

Re: include jsp

Postby robrecht » Thu Sep 06, 2012 11:59 am

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

Does anyone know what causes this behaviour?
robrecht
 
Posts: 99
Joined: Wed Aug 01, 2012 4:30 pm

Re: include jsp

Postby ptalbot » Thu Sep 06, 2012 3:34 pm

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
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: include jsp

Postby ROCLASI » Thu Sep 06, 2012 3:36 pm

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

+1 :!:
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

Re: include jsp

Postby robrecht » Fri Sep 07, 2012 9:21 am

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.
robrecht
 
Posts: 99
Joined: Wed Aug 01, 2012 4:30 pm

Re: include jsp

Postby ROCLASI » Fri Sep 07, 2012 12:20 pm

Hi,

robrecht wrote: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 wrote: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..
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

Re: include jsp

Postby david » Wed Nov 21, 2012 4:50 pm

robrecht wrote: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:

Code: Select all
<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>
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.


Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 6 guests