Hi,
If you develop portal applications, you probably find yourself sometimes searching for best way to pass parameters (configuration or others) from java code(server) into Javascript (client side) for easy to use later.
In this blog post you can find a code sample of how to pass parameters/properties from Portal Component and then easily read these in Javascript.
This works if you are using the ajax framework page or your custom framework page using the LSAPI mechanism
Java code for the portal component:
import com.sap.portal.navigation.afp.IAFPHelperService;
import com.sapportals.portal.prt.component.*;
import com.sapportals.portal.prt.resource.IResource;
import com.sapportals.portal.prt.runtime.PortalRuntime;
public class Test extends AbstractPortalComponent
{
private static String COMP_NAME = "MyTestComponent";
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
IPortalComponentContext componentContext = request.getComponentContext();
IPortalComponentProfile profile = componentContext.getProfile();
String myProfileProperty = profile.getProperty("myProperty");
IAFPHelperService afpHelperService = (IAFPHelperService) PortalRuntime.getRuntimeResources().getService(IAFPHelperService.KEY);
afpHelperService.addClientSideAttribute(COMP_NAME, "myProperty", myProfileProperty);
IResource myJS = request.getResource(IResource.SCRIPT,"scripts/myAppJS.js");
response.include(request, myJS);
}
}
<application-config>
<property name="PrivateSharingReference" value="com.sap.portal.navigation.afp.helperservice"/>
</application-config>
var SERVER_COMP = "MyTestComponent";
var topFrame = EPCM.getSAPTop();
var propFromServer = topFrame.LSAPI.AFPPlugin.configuration.getClientSideAttributeValue(SERVER_COMP, "myProperty");
alert("myProperty = " + propFromServer);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
40 | |
25 | |
17 | |
13 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 |