Copy link to clipboard
Copied
I have some sample code that I got off a blog and was hoping you guys could fill me in on why it's not working properly as there demonstrations state it would. I have poured over the code and can't find the issue:
The Flex code is as such:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" applicationComplete="employees.send()">
<mx:Script>
<![CDATA[
import mx.events.ValidationResultEvent;
import mx.controls.Alert;private function validateEmpName():void{
if (empNameValidator.validate().type == ValidationResultEvent.VALID)
{
submitForm();
}
else
{
Alert.show("Employee name can not be blank");
}
}
private function submitForm():void
{
employees.cancel();
employees.send(employeeModel);
}
private function onResult(event:Event):void
{
return;
}
]]>
</mx:Script>
<mx:Model id="employeeModel">
<root>
<empName>{empName.text}</empName>
<age>{age.text}</age>
<skills>{skills.text}</skills>
</root>
</mx:Model>
<mx:HTTPService id="employees" useProxy="false" method="POST" url="index.jsp"/>
<mx:DataGrid dataProvider="{employees.lastResult.people.person}" width="50%">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name" />
<mx:DataGridColumn dataField="age" headerText="Age"/>
<mx:DataGridColumn dataField="skills" headerText="Skills"/>
</mx:columns>
</mx:DataGrid>
<mx:StringValidator id="empNameValidator" source="{empName}" property="text" triggerEvent=""/>
<mx:Form width="100%" height="100%" x="50" y="400">
<mx:FormItem label="Enter name:" required="true">
<mx:TextInput id="empName" />
</mx:FormItem>
<mx:FormItem label="Enter age:">
<mx:TextInput id="age" />
</mx:FormItem>
<mx:FormItem label="Enter skills">
<mx:TextInput id="skills" />
</mx:FormItem>
<mx:Button label="Add Employee" click="validateEmpName()"/>
</mx:Form>
</mx:Application>
While the JSP page is much simpler:
<%--
Document : index
Created on : Feb 1, 2011, 10:34:13 AM
Author : Adam Balan
--%>
<%@page import="java.io.PrintWriter"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String employees = "<?xml version=\'1.0\' encoding=\'UTF-8\'?><people><person><name>Alex</name><age>22</age><skills>java, HTML, SQL</skills></person><person><name>Brandon Smith</name><age>21</age><skills>PowerScript, JavaScript, ActionScript</skills></person><person><name>Jeremy Plant</name><age>20</age><skills>SQL, C++, Java</skills></person>";
String name = request.getParameter("empName");
String age = request.getParameter("age");
String skills = request.getParameter("skills");
String newEmployee = "<person><name>" + name + "</name><age>" +
age + "</age><skills>" + skills + "</skills></person>";
if (name == null)
{
out.println(employees + "</people>");
}
else
{
out.println(employees + newEmployee + "</people>");
}
%>
</body>
</html>
So my question is this:
Why is this JSP page not populating the data grid of the flex application with the information provided? This all connecting through a glassfish server.
Also are there any solid example and or projects where you can connect Flex to JSP to send and recieve data?
Copy link to clipboard
Copied
Why do you post this in the Flash Builder forum?
Copy link to clipboard
Copied
The Flex general discussion is the right place to post this.
But that aside, why is your JSP outputting HTML tags and then XML tags? Take away the text from <!DOCTYPE to <body> and </body> to </html>. Also, I don't know if the forum ate your quotes in the flex code: Alert.show("Employee name can not be blank");