You need to sign in to do that
Don't have an account?
Kevin Languedoc
Flex
Hi
Basically I have a flex application embedded in a visualforce page and I need to pass the session id and url like in a scontrol
i.e.:
<param name="flashvars" value="session_id={!API.Session_ID}&server_url={!API.Partner_Server_URL_90}" />
However when I try to save, I am getting errors that it is trying not finding API and wants to create a method in my controller class.
How can I get and pass the sessionid and url my my flex application from the VisualForce page.
Do I need to access it through a scontrol. If so how do I call a scontrol object in my visualforce or apex class?
code:
================================
<apex:page Controller="AccountInformationControl" tabstyle="Account">
<script src="/soap/ajax/11.1/connection.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<script>
function getAccountNo(){
var accountNo = "{!AccountNumber}";
function getAccountNo(){
var accountNo = "{!AccountNumber}";
return accountNo;
}
function getAccountName(){
var accountName = "{!AccountName}";
}
function getAccountName(){
var accountName = "{!AccountName}";
return accountName ;
}
function getOtherAccounts(){
}
function getSessionId(){
}
function getUrl(){
}
</script>
<h1>DRAXIMAGE Sales Information</h1><br/>
<apex:pageblock >
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="SFQueryBuilder" width="100%" height="303"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="{!$Resource.SFQueryBuilder}" />
<param name="flashvars" value="session_id={!API.Session_ID}&server_url={!API.Partner_Server_URL_90}" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="{!$Resource.SFQueryBuilder}" quality="high" bgcolor="#869ca7"
width="100%" height="421" name="SFQueryBuilder" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</apex:pageblock>
}
function getOtherAccounts(){
}
function getSessionId(){
}
function getUrl(){
}
</script>
<h1>DRAXIMAGE Sales Information</h1><br/>
<apex:pageblock >
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="SFQueryBuilder" width="100%" height="303"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="{!$Resource.SFQueryBuilder}" />
<param name="flashvars" value="session_id={!API.Session_ID}&server_url={!API.Partner_Server_URL_90}" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="{!$Resource.SFQueryBuilder}" quality="high" bgcolor="#869ca7"
width="100%" height="421" name="SFQueryBuilder" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</apex:pageblock>
<br/>
</apex:page>
</apex:page>
http://blog.jeffdouglas.com/2008/11/12/developing-salesforcecom-applications-with-flex-and-visualforce/
Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com
width="600" height="300"
flashvars="userId={!$User.Id}&session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_140}" />
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
xmlns:salesforce="com.salesforce.*"
applicationComplete="login();" height="302"
width="675" borderColor="#FBFBFB" backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#EBF2F3, #EBF2F3]"
name="SFQueryBuilder">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import com.salesforce.*;
import com.salesforce.results.QueryResult;
import com.salesforce.objects.LoginRequest;
import com.salesforce.objects.SObject;
import com.salesforce.AsyncResponder;
import flash.external.ExternalInterface;
import mx.utils.ObjectUtil;
import mx.controls.Alert;
import flash.events.Event;
[Bindable]
private var sfdc:Connection = new Connection();
private function login():void {
initVariables();
var lr:LoginRequest = new LoginRequest();
lr.server_url = Application.application.parameters.server_url;
lr.session_id = Application.application.parameters.session_id;
//test standalone
lr.username = 'klanguedoc@xxxxxxxxxxxxx';
lr.password = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
lr.callback = new AsyncResponder(loadData, handleFault);
apex.login(lr);
}
// initializes the building id variable
private function initVariables():void {
var modelId:String = Application.application.parameters.modelId;
sfdc.protocol = "https";
sfdc.serverUrl = "https://na6.salesforce.com/services/Soap/u/14.0";
}
private function handleFault(fault:Object):void {
Alert.show(ObjectUtil.toString(fault));
}
private function accountId():String {
var accountid:String = new String(ExternalInterface.call("getAccountNo"));
return accountid;
}
private function accountName():String{
var accountName:String = new String(ExternalInterface.call("getAccountName"));
return accountName;
}
[Bindable]
private var ar:ArrayCollection = new ArrayCollection;
// Display a selected item's label field and index for change events.
private function changeEvt(event:Event):void {
apex.query("Select Name from Account where AccountNumber='"+
event.currentTarget.selectedItem +"'",new AsyncResponder(
function(qr:QueryResult):void {
if (qr.size > 0) {
for (var j:int=0;j<qr.records.length;j++ ) {
txtCustName.text= qr.records[j].Name;
}
}
},
handleFault));
}
private function loadData(lr:Object):void {
apex.query("Select AccountNumber From Account where AccountNumber !=null ", new AsyncResponder(
function(qr:QueryResult):void {
if (qr.size > 0) {
for (var j:int=0;j<qr.records.length;j++ ) {
ar.addItem(qr.records[j].AccountNumber);
}
}
},
handleFault)
);
}
]]>
</mx:Script>
<salesforce:Connection id="apex" />
<mx:Canvas width="671" height="282" borderStyle="none" top="10" left="2" borderColor="#FBFBFB">
<mx:Label x="10" y="99" text="Customer No:" id="custNo" enabled="true"/>
<mx:ComboBox x="100" y="97" id="cbCustNo" enabled="true"
text="{accountId()}"
dataProvider="{ar}"
change="{changeEvt(event)}"
/>
<mx:Label x="268" y="99" text="Customer Name:" id="custName" enabled="true"/>
<mx:Text width="285" id="txtCustName" enabled="true" x="376" y="99" text="{accountName()}"/>
<mx:ComboBox x="100" y="127" id="cbProductNo"
editable="false"
enabled="true"></mx:ComboBox>
<mx:Label x="10" y="129" text="Product No:" id="prodNo" enabled="true"/>
<mx:DateField x="100" y="175" width="176" cornerRadius="0" showToday="true" enabled="true" id="dtStartDate"/>
<mx:Label x="10" y="177" text="Start Date:" id="startDate" enabled="true"/>
<mx:Label x="284" y="177" text="End Date:" id="endDate" enabled="true"/>
<mx:DateField x="376" y="175" width="176" id="dtEndDate" showToday="true"/>
<mx:Label x="268" y="129" text="Product Name:" id="prodName" enabled="true"/>
<mx:Text x="376" y="129" width="285" id="txtProdName" />
</mx:Canvas>
</mx:Application>
For data visualizations, another architecture to consider that would minimize trips to the server would be to load the data into Javascript variables and have the flash movie load the data from the store on the client rather than go back to the server. Doing this will also reintroduce controller binding and system integrity enforcement.
I am using Flex becauseI am used to it and I find Flex Builder a powerful tool for UI development. Since I am new to VF I sought to minimize my learning curve. Tat said I tried to oad the data from the Account object troughthe controller but could never get it to work. See incuded code:
public class AccountInformationControl {
private final Account account;
private String AccountNumber;
private String AccountName;
private List<Account> accountNos;
public AccountInformationControl() {
account = [select accountNumber, name from Account where id = :ApexPages.currentPage().getParameters().get('id')];
}
public String getAccounts() {
return null;
}
public String getAccountNo() {
return null;
}
public String getAccountName() {
AccountName = account.name;
return AccountName;
}
public String getAccountNumber() {
AccountNumber=account.accountNumber;
return AccountNumber;
}
public List<Account> accounts(){
accountNos = [Select AccountNumber from Account where AccountNumber !=null];
//List<Account> accountNo = new List<String>{'value1', 'value2', 'value3', 'value4' };
return accountNos ;
}
}
The Javascript/Apex code that I tried to used to load the data into a javascript array:
<script>var accounts = [];</script>
<apex:repeat value="{!accountNos}" var="accno">
<script>accounts.push("{!accno}")</script>
</apex:repeat>
also tried:
<apex:repeat value="{!accountNos}" var="accno">
<script>accounts.push("{!accno.AccounNmber}")</script>
</apex:repeat>
Any suggestions would be greatly appreciated since, as you said, I am leveraging the controller and have tigh data binding
Cheers,
I have a small BlazeDS tutorial you can that you may find interesting:
http://blog.jeffdouglas.com/2008/12/05/blazeds-referenceerror/
You also might want to take a look at the Mate dependency injection framework for Flex. It makes large application development MUCH easier!
Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com
Thanks for the info.
I used Blazeds in the past. However my employer was recently bought out and the new owners are big Microsoft fans, so we had to switch to .NET. That being said, I recently setup weborb on a dev server. I tried a couple of the samples that came with weborb and they worked fine. However when I tried to re-create some test apps from Flex Developer Portal in Flex Builder I am getting a lot of access denied and policy file permission problems. I tried a crossdomain.xml file at the root without any luck. And I don't have time right now to try and figure out what I am doing wrong.
I will get back to that issue after my current project.
I will check out your tutorial and Mate
Thanks
Kevin
I am using the flex toolkit. The posts form the different guys offered invaluable information on getting everything running smoothly
Kevin