Include Custom Control dynamically on XPage - custom-controls

I am trying to include custom control on XPage based on some conditions. These conditions are depends on certain user selection fields. So As user changes his selection, I am populating the custom control name, and trying to include it in XPage.
I read about , but it loads the give page during Page load, and I am not able to load it dynamically.
example code Snippet :
<xp:button id="button3" value="Change Page to Include CC 2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" disableValidators="true" refreshId="pnlRefresh">
<xp:this.action><![CDATA[#{javascript:sessionScope.ccPageName = "content_CC2"}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:panel id="pnlRefresh">
<xp:include>
<xp:this.pageName><![CDATA[${javascript:sessionScope.ccPageName + ".xsp";}]]> </xp:this.pageName>
</xp:include>
</xp:panel>
Is there any possibility to achieve this requirement? Or using JAVA how do we inject page dynamically in XPage code?
I don't want to use Dynamic Content Control or Switch Control from ExtLib, as I will need to include all the required custom controls (Hardcoded) then only I can display the specific CC based on criteria.
Please help me.

There are two ways to achieve what You want:
Use Dynamic Content Control - its not true that You have to include all controls in order to make it work - there is a hack that allows You to simply rebuild the content of this control (calling show method with null parameter), here is an example: http://pastebin.com/VEDAjdDJ
Build Your control from java using custom control builder. An example of this can be found in Extension Library source code (class com.ibm.xsp.extlib.builder.ControlBuilder). This is a bit harder than first way so I would advise You to use Dynamic Content Control!
Remember that after rebuilding content of control all data kept in controls that is not saved will be lost! The best way to handle this problem is to use managed beans to keep Your data away from UI controls.

Related

Add textfield for Classes in cq dialog

If we want to add an Id to an AEM Core component such as image, there is this field:
.content.xml
<id
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldDescription="HTML ID attribute to apply to the component."
fieldLabel="ID"
name="./id"/>
which gives this textfield in the dialog.
But what if we want to create the same textfield, but for CLASSES instead? The core components only seems to use the "./id" name, and nothing for classes.
As you can see I am an absolute beginner, so any pointer or help is much appreciated.
--- Edit (June 17, 2022):
Following Vlad's answer, I needed to narrow down where I am having issue:
I don't know how to "add a textfield for classes". For example, the id field has name="./id" in the xml, which can be accessed as "${image.id}" in the html. But the same doesn't exist for Classes.
How would the Textfield look like if I am adding it for Classes? Like this one obviously wouldn't work as "./class" is not connected to anywhere.
<class
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldDescription="HTML CLASS attribute to apply to the component."
fieldLabel="CLASS"
name="./class"/>
I guess that the name="./id" of the Textfield is tied to some Java logic so we can retrieve it via "${image.id}". I have looked at image's java code, but don't see how they tied together.
I would need to understand the Java code in order to override it. Or am I missing anything and there is an easier way? Again, absolute beginner here.
You can override the dialog and add a textfield for classes, then overlay the HTL script and inject the classes in the markup. However, I recommend you look first into the OOTB Style System. It allows you to define classes in the component’s policy and then use them in the editor (they will be added on the component wrapper element).

Organizing i18n source file for data binding

I have a SAPUI5 SplitApp application written in English. There is a need to add translation into another language.
I have already made changes to all my detail views using this documentation and I have used the first approach (jQuery.sap.resources). All translations are in WebContent>i18n>i18n.properties file and in another .properties file for another language. And it works.
The problematic part is my main menu that is situated on the master page. To build my main menu I use data binding approach. Here are the elements of the menu and how I bind them: JSBIN.
I still want to use data binding for the master page.
What is the best way to create/organize file with menu elements and file with translation of those elements?
I don't quite get your question.
You want to use Databinding for your controls and for your i18n - that's not a problem, just use two models and give one of them a name.
var oModel = [The model with the data]
var oModeli18n = [The i18n model]
sap.ui.getCore().setModel(oModel);
sap.ui.getCore().setModel(oModeli18n, "i18n");
Now you can bind your normal data using just the paths, e.g. in an XML-View:
<Text text="{title}" />
You can bind to the i18n model by just prefixing the path with the model name you set before:
<Text text="{i18n>SOME_TEXT}" />
You can use this approach with any type of model and choose any name you want to.
If I did not answer your question, please explain your problem in more detail.
Update:
I used your code to make a working simple example of the basic binding:
http://jsbin.com/wafecaqezu/1/edit?html,js,output
You just have to add the bundle...

Using variables in custom joomla module for tooltips

I'm new to joomla development, but I can't seem to figure out how to dynamically fetch descriptions to be displayed as tool tips for the form data of a module backend. I'm looking at an example module from joomlart and their code for a single field element in their xml file looks like this.
<field
name="mainWidth"
type="text"
default="auto"
size="5"
label="MAIN_WIDTH"
description="MAIN_WIDTH_DESC" />
MAIN_WIDTH and MAIN_WIDTH_DESC are obviously variables that are somehow being accessed and rendered later when the module is run in the backend but I can't find where the values to these variables are stored or how to replicate this behavior. Any help would be appreciated.
Label is the label that prints to screen, and description is rendered as the tooltip.
You can just replace these variable names with the actual text and it will work when the form is rendered.
However, in your example, I believe they are using language files to get the text to display.
Whilst you can set a language file within your module for that module's use, naming convention suggests to me that these are being pulled from somewhere like the template's language file.
( Such a file is likely to be found either under /language or /administrator/language or /templates/yourtemplate/language )
The benefit of such files is to allow for translations of the site to exist without having to write a new module / template each time.
Ultimately, if you don't want various language versions of your site, and you only intend to use the module on one site and not sell it as an extension, then there is no strong need to create a language file for your own bespoke modules (though best practise would probably be to do so).

Internationalising with multiple views

I have an action called index that returns a view and I've defined 3 views: index.cshtml, index.fr.cshtml and index.sv.cshtml, each of which contains my page in a different language. I expected my app would automatically find these views and serve them according to the browser language preference set, but it doesn't seem to.
is there some switch I have to turn on to make this work? I did add <globalization uiCulture="auto" culture="auto" /> to the <system.web> section of my web.config
TIA - e
If you go down this road, make a view per language you will end up with a lot a views and DUPLICATE code. something you want to avoid. A better approuch is the use of resources.
You can decide how far you go with globalisation : javascript / urls / tekst. The key is to make use of resources and put the key value pair there. Please look at http://channel9.msdn.com/Events/aspConf/aspConf/How-To-Achieve-World-Ready-Domination-In-ASP-NET-MVC-4
The index.mode.cshtml is for browser display mode of the ViewEngine.
You have to create a custom ViewEngine for localization. Here is one for WebForm. Just modify it to your needs and inherit from RazorViewEngine instead of WebFormViewEngine.

How can I prevent dojo javascript from being rendered from a custom control with rendered=false?

The title of this question may seem a bit confusing, but here is what is happening to me.
First off, I am using Notes/Domino 8.5.3 with UP1.
I have an Xpage with a edit mode custom control inside of it. Within the custom control are various elements using digit.forms. I have tried to set the custom control to be rendered only on edit mode, but even when it is in read mode certain dojo elements are STILL being rendered. To test this I even have set it to rendered=false for the control.
<xc:ccEditDocument rendered="false"></xc:ccEditDocument>
When I compare the source of the XPage with the custom control as rendered=false VS source of the XPage with NO custom control at all the following differences are encountered:
<script type=”text/javascript” src=”/xsp/.ibmxspres/dojoroot-1.6.1/ibm/xsp/widget/layout/layers/xspClientDojoUI.js”></script>
<script type=”text/javascript”>dojo.require(’dijit.form.Form’)</script>
and
enctype=”multipart/form-data” dojoType=”dijit.form.Form”
This is actually causing a problem for me with IE8 and iFRAME rendering of a PDF (it of course works in all other real browsers).
Is there a way to TRULY have the custom control NOT render the dojo form elements?
Thanks!
UPDATE
jjtbsomhorst had the fix! It was to add a conditional on the loaded property of the custom control.
<xc:ccEditDocument rendered="#{javascript:document1.isEditable()}"
loaded="${javascript:document1.isEditable()}">
</xc:ccEditDocument>
Thanks!!
Use the loaded property and toggle the loading of the element using a viewscope variable. This viewscope var is populated using a url parameter. Because you change the url, and do a full refresh, the loaded property is revaluated. I think this should cause the dojo not to render at unless the dojotype is loaded
You need to set the rendered property of the dojo module in the custom control itself. This will determine then at runtime whether or not the module will be added to the list of resources to be rendered.

Resources