PDA

View Full Version : Laszlo and Struts


jawadz
11-03-2004, 01:22 PM
I have a simple action which forwards to an lzx file. I have specified the forward as a relative path like /cml/hello.lzx in the struts-config.xml. However, when I access it, the page loads with laszlo images ad stuff but the application never loads and it just keeps waiting and waiting. This is the entry in the lps.log file:

Any help is appreciated.

03 Nov 2004 15:00:36 () INFO responders.ResponderDATA - Data Cache is at C:\dev\ubes\WAR\WEB-INF\lps\work\dcache
03 Nov 2004 15:00:36 () INFO servlets.LZServlet - Default request type is app_console
03 Nov 2004 15:00:36 (127.0.0.1 1) INFO servlets.LZServlet - Request for C:\dev\ubes\WAR\cml\hello.lzx
03 Nov 2004 15:00:36 (127.0.0.1 1) INFO responders.ResponderCompile - application cache is at C:\dev\ubes\WAR\WEB-INF\lps\work\cache
03 Nov 2004 15:00:36 (127.0.0.1 1) INFO compiler.Compiler - compiling C:\dev\ubes\WAR\cml\hello.lzx...
03 Nov 2004 15:00:38 (127.0.0.1 1) INFO compiler.Compiler - done
03 Nov 2004 15:00:38 (127.0.0.1 1) INFO responders.ResponderAPP_CONSOLE - Responding with HTML wrapper for C:\dev\ubes\WAR\cml\hello.lzx
03 Nov 2004 15:00:39 (127.0.0.1 2) INFO servlets.LZServlet - Request for C:\dev\ubes\WAR\hello.lzx
03 Nov 2004 15:00:42 (127.0.0.1 2) INFO responders.ResponderCompile - /ubes/hello.lzx not found
03 Nov 2004 15:04:56 () INFO servlets.LZServlet - LPS destroyed in context: WAR

rbrown3
11-03-2004, 03:01 PM
Strong suggestion:

Wrap the lzx file in a JSP or HTML file, and instead of the Action going directly to the lzx, have it go to the JSP.

Laszlo apparently has some funky scripting that it does in order to properly set up its applications. From a JSP this is accomplished by the use of some interesting Javascript which your Action does not invoke. In theory, just requesting the lzx file should cause the Laszlo servlet to handle it; in practice for some reason this doesn't work too well.

Of course, an alternative would be to use the Action to generate the HTML and Javascript code. Not the best idea.

Simply use your browser to call up the lzx file, using the &lzt=html parameter. Grab the source and save it as a JSP or HTML file. Then set your forward so that it points to your created file. This should cause everything to work properly.

jawadz
11-04-2004, 07:40 AM
Yep, that did the trick. It is even better actually. I have a layout tile which puts some menus and stuff on the page. In the body tile JSP, I inserted the script tags to include the embed javascript file and the LZX application itself like this:
<script type="text/javascript" src="/ubes/lps/includes/embed.js"></script>
<script type="text/javascript">
lzEmbed({url: '/ubes/cml/hello.lzx?lzt=swf', bgcolor: '#ffffff', width: '500', height: '400'});
</script>

And it loaded as an object in the JSP page.

Thanks a bunch for your reply.

rbrown3
11-04-2004, 07:53 AM
Hey, any time!

Always glad to help another Struts user...

:-)

deweime
11-29-2004, 09:45 AM
Hello,

When using an MVC architecture I've usually had the actions call out to a service layer to generate the data for the view, place this data in a request attribute and forward to a .jsp page to render the content.

Is a similar flow recommended when forwarding to a .lzx file? I didn't see any docs on how to interface Java servlet data structures/session.

Thanks,
Dan

jawadz
11-29-2004, 02:46 PM
I am sure the similiar flow/design will be used for the LZX as well as the understanding is that the URL to the JSP will be the URL SRC of dataset tag in LZX file. The contents of rendered XML output of JSP will be available as data elements in the dataset and can be used by views. Basically, there is another layer on top of JSP which uses JSP output for it's feed.
However, there is no guideline or best practice kind of thing regarding it, or at least I have not seen any.

What I have been doing is that I access the Service connector layer to acquire data, set it in the ActionForm object and forward to JSP. The JSP only spits out the well-formed XML data structure. The LZX file has the dataset tag in it associated with this action handler and creates the dataset object available to the LZX application components.

Although, I must say that I have encountered issues where the dataset was not able to retreive the data because of some socket problems and I have posted questions with no help.

It would be great to find any best practices docs regarding data acquisition.

If you like, I can provide some simple examples of what I am doing using struts framework.

cheers

deweime
11-29-2004, 03:21 PM
Thank you for the suggestion. Yes, I would be very interested in seeing a simple example using Struts.

On a larger scale, is this the correct approach? It seems like replacing each view is not really compatible with the notion of a single page user interface.

Thanks,
Dan

jawadz
11-30-2004, 09:24 AM
Attached is a zip file with a small sample struts app. Please read the README.txt file for configuring the Laszlo related components. I did not put them in the bundle as they were making the zip rather large. You can get the libraries and folders I specified in the README and then try deploying it in tomcat. The source is in WEB-INF\src folder.

I am not sure if it is correct aproach on larger scale. I am still understanding and experimenting with this whole thing and yet to find a good and meaningful documentation resource.

jsundman
11-30-2004, 12:54 PM
I'm gathering information on this subject and hope to prepare a chapter for the Developer's Guide soon.

In the meantime I hope y'all will continue to contribute ideas & experiences to the forums. Frankly, we didn't have too much experience with Structs before Laszlo went open source, but since then there's been a great demand for information on Struts/Laszlo integration. We're working on it.

John, the doc guy

gowdy
12-14-2004, 07:06 PM
Thanks for the Struts file --- it definitely helped.

I was wondering how this would change if I have already obtained the data from my action, eg JSP --> Action --> populate ArrayList --> store in request scope --> JSP. Within the 2nd JSP I then want to use that ArrayList. Within the dataset name, do I still have to specify the action (eg, <dataset name="mydata" request="true" type="http" src="showData.do" >) or can I simply refer to the ArrayList by the name it is now stored as in the request?

Not looking for code, just an idea of how to proceed.

Thanks

Mark

dgeary
12-15-2004, 12:08 PM
Thanks jawadz, for strutslzx. When I run it, however, I get a very wide and very short window with nothing in it.

I assume that when you load index.jsp, the dataset calls out to the struts handleData action, which populates the data and forwards to data.jsp, which uses Struts tags to generate XML. That XML is the data I should see in the window. But there's nothing there.

I also added a debug statement to DataAction's execute method, but that statement never shows up in the log, so I don't think the action is being invoked. I'm using Laszlo 2.2.1.

jawadz
12-20-2004, 08:14 PM
I am sorry for the delayed reply. I was away and did not check my messages. Also, I have actually gotten busy with some other development tasks. Here are replies to last two posts.

gowdy:
The URL in the dataset element in the lzx application must point to something which will produce valid XML output. The XML output can be displayed using XPath within the Laszlo components. The JSP can use ArrayList to create XML output but the ArrayList stored in the request is of no use to the LZX componets. The URL can point to an action which forwards to a JSP which produces XML, it can go to a servlet which renders XML or it can simpley go to a JSP which outputs XML. I hope I answered your question and i fnot, please let me know and we can always discuss further. Web Services and RPC is another way to acquire data but I have not done that in laszlo environment.

dgeary:
I tried to reproduce your probelm but was not successful. Here are a few things that may help:
1. Make sure that you have all the libraries mentioned in the readme file.

2. I created the app using struts 1.0 so make sure you either have struts 1.0 libraries or modify the app to use latest version of struts.

3. Any log output and messages might be useful to determine where the problem is. It seems that the action is not called at all so I guess struts libraries may be the reason.

If you still are not able to run, pleaser let me know and I shall create a zip file of the app with all the libraries. Let me know your email so I will either email it to you or put it on a server for you to download.

cheers!

jawadz
12-20-2004, 08:24 PM
One more thing, the strutslzx application is created using Laszlo 2.2. That may be the reason for the application not working too. it would help to look at the lps.log file in the /WEB-INF/lps/work/logs folder. I may have the directory structure wrong so try to search for the log file in the /WEB-INF/lps folder of the application.

gowdy
12-23-2004, 04:14 PM
hi jawadz

Thanks for the update. Knowing that I cannot use the request attribute really was a big help (although it would have been fantastic to be able to do so). I will try to play with that over the holiday period and might even look at the JavaRPC area.

gowdy

dgeary
12-24-2004, 03:01 PM
Thanks for the advice, jawadz. I'll give it a try.

k07032
02-28-2005, 09:18 AM
Hi jawadz,

I've tried your sample struts app and got the same window as dgeary described "I get a very wide and very short window with nothing in it".
I have all the libraries mentioned in the readme file copied to WEB-INF. Here is the info from my lps.log file:
INFO servlets.LZServlet - Laszlo Presentation Server, 2.2.1, initialized
INFO servlets.LZServlet - Running in context:Apache Tomcat/5.0.24
INFO servlets.LZServlet - Build: lps-2.2.1-001185-0001
INFO servlets.LZServlet - Built on: 03:38 PM 08-Nov-2004
INFO servlets.LZServlet - Running against JRE 1.4.2_07
INFO servlets.LZServlet - Running with Java CLASSPATH: C:\j2sdk1.4.2_07\lib\tools.jar;C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\bin\bootstrap.jar
INFO servlets.LZServlet - Running on Windows XP 5.1
INFO servlets.LZServlet - Running as user wai
INFO servlets.LZServlet - Max memory: 508.06 MB
INFO servlets.LZServlet - Total memory: 127.12 MB
INFO servlets.LZServlet - Available memory: 110.1 MB
INFO servlets.LZServlet - LPS_HOME is: C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\webapps\strutslzx
INFO responders.ResponderCompile - application cache is at C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\webapps\strutslzx\WEB-INF\lps\work\cache
INFO responders.ResponderMEDIA - Media Cache is at C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\webapps\strutslzx\WEB-INF\lps\work\mcache
INFO data.HTTPDataSource - using connection pool
INFO data.HTTPDataSource - using HTTP 1.1
INFO responders.ResponderDATA - Data Cache is at C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\webapps\strutslzx\WEB-INF\lps\work\dcache
INFO servlets.LZServlet - Default request type is app_console
INFO servlets.LZServlet - Request for C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\webapps\strutslzx\lzxApp.lzx
INFO responders.ResponderCompile - Responding with NOT_MODIFIED
INFO servlets.LZServlet - Request for C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\webapps\strutslzx\lzxApp.lzx
INFO responders.ResponderCompile - Responding with NOT_MODIFIED
INFO servlets.LZServlet - Request for C:\Program Files\Laszlo Presentation Server 2.2.1\Server\tomcat-5.0.24\webapps\strutslzx\lzxApp.lzx
INFO responders.ResponderCache - proxying http://localhost:8080/strutslzx/dataHandler.do, not cacheable on server or client
INFO data.DataSource - requesting URL: 'http://localhost:8080/strutslzx/dataHandler.do'
WARN data.XMLConverter - back-end mime-type is text/html, treating as text/xml
ERROR responders.Responder - Responding with error SWF: backend timeout for http://localhost:8080/strutslzx/dataHandler.do: null http response body

What does "null http response body" mean? Do you have any idea how to fix it?

Thanks.

mschipperheyn
04-24-2005, 06:42 AM
Should be similar to Laszlo. Didn't thoroughly read it yet.
http://www.macromedia.com/devnet/flex/articles/struts_05.html

Marc

srinivas
07-23-2006, 06:56 AM
Hi i'm unable to embed my lzx file in jsp.Here are the two files..pls check it..


getMenu.jsp::::::::::::::::::::::::

<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>


<root>
<%
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver"); //1
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/xyz","sree","mysql"); // 2
Statement stmt = connection.createStatement();
String username = request.getParameter("j_userrole");
String str = "select * from menu where username =" + "\'"+ username + "\'" ;
System.out.println("The entered user is " + str);
ResultSet rs = stmt.executeQuery(str);
while(rs.next()) {

%>

<menu role=" <%= rs.getString("role") %>"/>
<% System.out.println(" The Role from database is : " + rs.getString("role") );
} %>
<div>
<script type="text/javascript">
lzEmbed({url: 'http://inbaxpwsris:8080/lps-3.3.1/RDM-Development/adminmenu.lzx', bgcolor: '#ffffff', width: '400', height: '622'});
window.alert("ok");
</script>
</div>

<% }

catch (Exception e) {
e.printStackTrace();
}

%>
</root>


Here is my lzx file:::::::::::::

<canvas>
<dataset name="dset" src="getMenu.jsp" request="true" type="http"/>
<dataset name="menu" src="menu.xml"/>
<attribute name="mbar"/>

<class name="adminMenuBar" placement="menubar" datapath ="menu:/menubar/item" extends="menubar">
<menu name="File" datapath="@name" width="150">
<menuitem datapath="menu:/menubar/item[1]/subitem/@name" />
</menu>
<menu name="Document" datapath="@name" width="150">
<menuitem datapath="menu:/menubar/item[2]/subitem/@name" />
</menu>
</class>

<class name="userMenuBar" placement="menubar" datapath ="menu:/menubar/item" extends="menubar">
<menu name="Document" datapath="@name"
width="150">
<menuitem datapath="menu:/menubar/item[2]/subitem/@name" />
</menu>
</class>

<view datapath="dset:/root/menu" >

<text text="@role"></text>
</view>
</canvas>

I'm not getting any error but my lzx files is not getting displayed.


can any one help....

Thanks in advance

srinivas