i done as follows
i have a method with brings data of particular table, as given my parameter to that method,
now i want to fetch data from corresponding table and it too list, and send back flex and form dynamically Grid & add dataprovider dynamically as for its corresponded table colomns in flex side ?
Remote objec(java class)
public List<List<String>> getMasterTableData(String name)
{
String designMaster = "tbl_design_master"+name;
String masterTableName = "tbl_master"+name;
String[][] res ;
List<List<String>> list = new ArrayList<List<String>>();
try
{
st = connection.createStatement();
ResultSet rs1 = st.executeQuery("select * from "+designMaster);
int len = 0;
while(rs1.next())
{ len++; }
ResultSet rs2 = st.executeQuery("select * from "+masterTableName);
while(rs2.next())
{
List<String> ll = new ArrayList<String>();
for(int i=1;i<=len; i++)
{
ll.add(rs2.getString(i));
}
list.add(ll);
}
}
catch (SQLException e) {
e.printStackTrace();
}
return list;
}
flex code :
<mx:RemoteObject id="RO" destination="adminServiceImpl">
<mx:method name="getMasterDesign" result="getMasterDesignRH(event)" fault="FH(event)" />
<mx:method name="getMasterTableData" result="getMasterTableDataRH(event)" fault="FH(event)"/>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
[Bindable] private var ac:ArrayCollection = new ArrayCollection();
public function init(Str:String):void
{
RO.getMasterDesign(Str);
Application.application.selectedgridItem = Str;
RO.getMasterTableData(Str);
}
private function getMasterDesignRH(event:ResultEvent):void
{
Application.application.designList = event .result as ArrayCollection;
var aColumns:Array = new开发者_如何学Python Array();
for(var i:int=0; i< Application.application.designList.length; i++)
{
var dgc:DataGridColumn = new DataGridColumn();
dgc.headerText = Application.application.designList.getItemAt(i).colName;
//dgc.dataField = Application.application.designList.getItemAt(i).colName;
aColumns.push(dgc);
}
mainGrid.columns = aColumns;
}
private function getMasterTableDataRH(event:ResultEvent):void
{
ac = event.result as ArrayCollection;
mainGrid.dataProvider = ac;
}
private function FH(event:FaultEvent):void{
Alert.show(event.fault.faultString);
}
]]>
</mx:Script>
<mx:HBox width="100%" height="80%">
<mx:DataGrid id="mainGrid" width="100%" height="100%" />
</mx:HBox>
getMasterDesign is an ArrayCollection, which is filled with the column names and components to be displayed
Ex : getMasterDesign(emp) empMasterDesign table looks like as follows
colName component
--------------------
EmpName textBox
empSal textBox
empDesi ComboBox
empMasterData:
empName | EmpSal | EmpDesi
abc 1000 Cler## Heading ##ck
xyz 2000 Manager
Now i want this create a Datagrid in flex dynamically by using its design & master data table in action script i done everyting , my dataGrid had formed as for his master design,but data is not showing ?
You must set the dataField
to the appropriate value. From the given data, it looks like colName
field in the metadata and its corresponding name in the table are not the same. For example it is EmpName
in the design and empName
in the original table; none of the fields match - empSal
vs EmpSal
, empDesi
vs EmpDesi
. Fix that, assign colName to the dataField, and you should be good to go.
精彩评论