How to add a fragment to a page's content in SAPUI5 - view

I would like to add a dynamically created fragment to a page's content inside the view's controller.
I currently have the following code:
if(this.tableFragment) {
this.tableFragment.destroy(true);
}
this.tableFragment = sap.ui.xmlfragment("com.example.app.view.fragments.FragmentName");
this.getView().byId("pageID").addDependent(this.tableFragment);
and would like to insert it into a page:
<Page id="pageID" title="Page Title" class="sapUiStdPage">
<content>
</content>
</Page>
but I get an error that contains the following:
is not valid for aggregation "dependents" of Element
I also get the error:
this.tableFragment.destroy is not a function

Related

How can I create a DjRF API endpoint that returns a RML-generated PDF?

Django documentation has the following example for ReportLab.
from reportlab.pdfgen import canvas
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
# Create the PDF object, using the response object as its "file."
p = canvas.Canvas(response)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(100, 100, "Hello world.")
# Close the PDF object cleanly, and we're done.
p.showPage()
p.save()
return response
However. I want to use RML to generate my PDF. ReportLab Plus offers an rml2pdf function that can turn an RML document into a PDF using a similar markup to Django's templating. How can I provide Django the RML template and have Django return the PDF in the API response, similar to the example in the documentation?
Figured it out.
RML Template
Put this in your Django templates folder so Django can find it.
Call it templates/rml_template.rml
<!DOCTYPE document SYSTEM "rml.dtd">
<document filename="example_01.pdf">
<template>
<!--this section contains elements of the document -->
<!--which are FIXED into position. -->
<pageTemplate id="main">
<frame id="first" x1="100" y1="400" width="150" height="200"/>
</pageTemplate>
</template>
<stylesheet>
<!--this section contains the STYLE information for -->
<!--the document, but there isn't any yet. The tags still -->
<!--have to be present, however, or the document won't compile.-->
</stylesheet>
<story>
<!--this section contains the FLOWABLE elements of the -->
<!--document. These elements will fill up the frames -->
<!--defined in the <template> section above. -->
<para>
Welcome to RML!
</para>
<para>
This is the "story". This is the part of the RML document where
your text is placed.
</para>
<para>
It should be enclosed in "para" and "/para" tags to turn it into
paragraphs.
</para>
</story>
</document>
Django View
This view loads the template as a string and rml2pdf uses the response object as its "file" to write to, similar to the Django documentation example.
from django.template import loader
from rlextra.rml2pdf import rml2pdf
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
context = {} # You can add values to be inserted into the template here
rml = str(loader.render_to_string('rml_template.rml', context))
rml2pdf.go(rml, outputFileName=response)
return response

How to create content for child pages of a template?

I created a Zen page with a header. All is good. I then created a new Zen page and during the wizard specified that it was a "subclass of a template page". So now I have Class Custom.App.HomePage Extends Custom.App.TemplateMaster. If I visit HomePage.cls I see the header from the template. However, the HomePage class has no XData Contents section so I have no idea how to actually add content. I tried adding the section but once I do then I don't see the template content anymore.
So, how do I put content in a page that extends another page as a template?
The only documentation I found about templates doesn't really help and unfortunately I don't have access to the sample files mentioned.
You can do it using pane's. You can create differents XData with the identifier that you want, and add a pane object using the paneName. This is a simple example:
Class Custom.App.TemplateMaster
{
XData Contents
{
<page xmlns="http://www.intersystems.com/zen" >
...
<pane paneName="HomePageContent" width="100%" />
...
</page>
}
}
Class Custom.App.HomePage Extends Custom.App.TemplateMaster
{
XData HomePageContent
{
<!-- the specific content of your HomePage ->
}
}

Change page at XULRunner

At my current project we got a website which is shown of a microcontroller at a monitor. I found XULRunner for displaying the page. It is nice, so I can hide all user panels very easy.
The microcontroller got a controller application too. The controller application gets the url which should be displayed from a server. With firefox I can execute "firefox theUrl" and it opens the browser with that url. If the browser is already running, the page opens at the running firefox.
To get that behavior at XULRunner, my main.xul looks like this:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
id="display" windowtype="display" title="Display"
onload="init();" hidechrome="true" zlevel="6">
<script type="application/javascript" src="cmdline.js" />
<script><![CDATA[
function init() {
var cmdLine = window.arguments[0].QueryInterface(Components.interfaces.nsICommandLine);
var content = document.getElementById("content");
content.setAttribute("src", cmdLine.getArgument(0));
content.contentWindow.focus();
window.resizeTo(screen.width, screen.height);
}
]]></script>
<hbox flex="1">
<browser id="content" flex="1" disablehistory="false"
src="chrome://commandlineinit/content/default.html" />
</hbox>
</window>
My prefs.js got that content:
pref("toolkit.defaultChromeURI", "chrome://applicationname/content/main.xul");
pref("toolkit.defaultChromeFeatures", "dialog=no, chrome, centerscreen");
pref("toolkit.singletonWindowType", display
And the chrome.manifest:
content applicationname content/
So, now I can open with xulrunner application.ini http://www.myPage.de the page. But when I call it a second, it do nothing.
So I added the commandline handler from that tutorial: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/XULRunner/CommandLine
At the method "observe" at chrome/content/cmdline.js I added
var cmdLine = window.arguments[0].QueryInterface(Components.interfaces.nsICommandLine);
var content = document.getElementById("content");
content.setAttribute("src", cmdLine.getArgument(0));
content.contentWindow.focus();
Now I have 2 problems. At that method, it can't find the element with ID content. So I can't change the url.
The other problem: It calls the observe method only at the first call. I think, the component components/clh.js isn't registert.
What did I wrong?

HTML dynamic content is not shown in spark textarea

In a flex application, i want to display formatted tweets in a spark textarea but it is showing html elements (with tags) 'as it is' rather parsing it and converting into rich html text, i was following this example from flex official site
<s:TextArea width="400" height="100">
<s:content>This is <s:span color="#FF0000">HTML text</s:span>
in an <s:span fontWeight="bold">Spark TextArea control</s:span>.
Use the <s:span textDecoration="underline">content</s:span> property
of the <s:span color="#008800">Spark TextArea control</s:span>
to include basic HTML markup in your text, including
<s:a href="http://www.adobe.com" target="_blank">links</s:a>.
</s:content>
</s:TextArea>
but passing my data like this
<s:TextArea>
<s:content>{TwitterString.parseTweet(data.text)}</s:content>
</s:TextArea>
and the result to it for a tweet is,
<s:a href='http://t.co/a7bQnmLRGy' target='_blank'>http://t.co/a7bQnmLRGy</s:a> I'll be there
which means it has not been formatted as expected.
Any idea how to make <s:content> work for dynamic content pass to it?
Please no answers of TextConverter this would be my last resort, i would love to use <s:content> working
Check out the documentation for TextArea's content property. In particular, it states this about the content property:
This property is typed as Object because you can set it to to a String, a FlowElement, or an Array of Strings and FlowElements. In the example above, the content is a 2-element array. The first array element is the String "Hello". The second array element is a SpanElement object with the text "World" in boldface.
So the key here is that your TwitterString.parseTweet() function is returning a String. As such, the TextArea is displaying it as a String and not bothering to convert the elements found in the text.
Instead, if you wish to continue down this path, your TwitterString.parseTweet() function should return an Array. Each element in the array is either a String (represents normal text) or some sort of FlowElement object (a SpanElement, LinkElement, ParagraphElement, etc.). If you return an array that contains the structure you want, it will render your content properly. See below for a simple example, it will get very tedious for real content.
So you're really better off using TextConverter ... because by writing the code like you want, you are doing the exact same thing that TextConverter does.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">
<fx:Script>
<![CDATA[
import flashx.textLayout.elements.LinkElement;
import flashx.textLayout.elements.SpanElement;
[Bindable("contentChanged")]
private function getTheContent():Array
{
var temp:Array = [];
var link:LinkElement = new LinkElement();
link.href = "http://google.com";
var span:SpanElement = new SpanElement();
span.text = "Google";
link.addChild(span);
temp.push(link);
// continue building your structure...(so tedious)
return temp;
}
]]>
</fx:Script>
<s:TextArea width="400" height="100">
<s:content>{getTheContent()}</s:content>
</s:TextArea>
</s:Application>

how to assign value for id attribute of image tag in visualforce page?

Am not able to assign the id value dynamically for an image...am referring this image javascript to display the up/down arrows accordingly...here is the code snippet...
<apex:variable var="count" value="{!1}"/>
<apex:image id="msn{!count}" url="{!URLFOR($Resource.style_resources, 'images/up-arrow.gif')}" alt="Open-close" />
but i get the compilation error as "literal value is expected for id"...
can't we dynamically assign the value for id attribute ??
From Apex image,
<apex:image id="theImage" value="/img/myimage.gif" width="220" height="55"/>
The example above renders the following HTML:
<img id="theImage" src="/img/myimage.gif" width="220" height="55"/>
So change
<apex:image id="msn{!count}" url="{!URLFOR($Resource.style_resources, 'images/up-arrow.gif')}" alt="Open-close" />
to
<img id="msn{!count}" src="{!URLFOR($Resource.style_resources, 'images/up-arrow.gif')}" alt="Open-close" />
You are correct you can't assign an element id dynamically. it has to be a string literal. I have however used the class attribute to create custom ids that can be later used in javascript. I do this with jQuery and it's powerful selectors to select elements based on tag type and class.
The example below is just a sample but with jQuery you can get pretty creative.
<apex:variable var="count" value="{!1}"/>
<apex:image id="msn"
url="{!URLFOR($Resource.style_resources, 'images/up-arrow.gif')}"
alt="Open-close"
styleClass="msn{!count}" />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"/>
<script>
jQuery.noConflict();
function doSomethingWithImg() {
try {
var imgElement = jQuery('.msn1');
/*Do what you need to do with the element*/
} catch (e) { /*Ignore Error*/ }
}
</script>
Here is the link to jQuery selectors: jQuery Selector Documentation

Resources