Show the user data of every response for the current Quick Poll in the campaign in a Flex Client, 3rd part
In this part, only we will focus in Flex client, also there are others parts, such as J2EE components, but here we don't consider here because they are out of scope of this blog. It includes to consider the following parts:
- Create J2EE Web Proyect, it will contain the flex client created with Flex Builder or Flash Develop IDE.
- Create EJB Project , it references to the java project created in the 2nd part of this blog. Here, you'll need to create a stateless session bean, and after to expose some method as Web Service. The NWDS has a wizard to do this taskes. Also, you could create a Web Services directly of the Java project by making use of the NWDS wizards.
- Create Flex Builder Project or FlashDevelop IDE, you create a flex client to consume the previuosly web services.
- Create Enterprise Project; finally we will add the web and ejb project modules, previously created, to this kind project for deployment our ear file on SAP Netweaver AS 7.0+.
Now, you will review the MXML file of our flex client (we will name FlexWebService.mxml). The main aspects of this file are the web services consumation, the treating of xml response from back end, and the datagrid flex component to show the data.
1. The web services part:
<mx:WebService id="myWebService"
wsdl="http://myserver:50200/SimpleSearchPollWS/sspollconfigws?wsdl">
<mx:operation name="getVotesPerCampaingXmlResponse"
resultFormat="object"
result="resultHandler(event)"
fault="faultHandler(event)">
</mx:operation>
</mx:WebService>
In the wsdl attribute of the mx:WebService tag, we will put the wsdl url of the previously deployed web service.Also, in the tag mx:operation we mention the name of the method to call.
Note: We could consider to make use of the mx:HTTPService component with Servletes, but I have problems with the login sesion. SAP Netweaver AS has using the JASS login (user/password) module by default, then the Flex Client doesn't save the jsession variable of the current logged user and therefore the HTTPService doesn't work. May be by making use of flashvars we could integrate the SSO session on flex client (here some link of possible useful resource ).
2. The treating of xml response from back end.
The response of the back-end need to be treat, then we write the actionscript method named
private function resultHandler(event:ResultEvent):void
This name is put on the "result" attribute of the mx:WebService attribute. Optionally, also we put on the "fault"attribute the name of the "faultHandler" function, in case of some error happen.
private function faultHandler(event:FaultEvent):void
3. The datagrid flex component to show the data.
We will create an ArrayColletion variable (it needs to be Bindable) for to be used in the datagrid component.
[Bindable]
private var myData:ArrayCollection=new ArrayCollection;
This collection will containt the DTO (data transfer object) objects. this kind of object store the information from xml response. This collection containing the dto objects willbe used as data provider of the mx:Datagrid flex component.
<mx:DataGrid id="campaignGrid"
dataProvider="{myData}"
width="100%">
<mx:columns>
<mx:DataGridColumn dataField="name"
headerText="Nombre del Usuario"
width="220"/>
<mx:DataGridColumn dataField="id"
headerText="Id de Usuario"/>
<mx:DataGridColumn dataField="email"
headerText="Email"
width="200"/>
<mx:DataGridColumn dataField="area"
headerText="Area/Departamento"
width="120"/>
<mx:DataGridColumn dataField="response"
headerText="Contesto"
width="120"/>
</mx:columns>
</mx:DataGrid>
Once compiled and released the flex client, it will be integrated on the previously web project module.
Next, a screenshot of the flex client.
You can download the Flex Builder project from here.
Comments