Passing a POJO to a custom control property - xpages

I'm refactoring an XPages application which has five nested repeat controls repeating basically the same thing (an xp:panel). I thought, aha, here comes a custom control with properties!
I'm looping my repeat controls around properties of a managed bean, and I was hoping I could have set a property for the custom control to just accept the POJO I'm sending it (and then access it with EL within the custom control).
What should I do? Make the custom control receive only strings, numbers, etc and have the whole nested-control logic outside? Or is there a trick?

A custom control can easily accept a java object that's passed in via the custom properties. Just use the type: java.lang.Object

All the answers were correct, but only David put it as an answer - thanks to all!
I've noted my code here for anyone later: I defined node to be of Type java.lang.Object. Notice the syntax to get the object into the custom control:
<xp:repeat
id="repeatfirstlevelnode"
value="#{TableOfContents.root.children}"
var="firstlevelnode">
<xc:ccPanelNavigation
node="#{firstlevelnode}"
panelStyleWhenActive="panelLevel1 active bold"
panelStyleWhenInactive="panelLevel1"
NameNestedRepeatControl="repeatsecondlevelnodes">
</xc:ccPanelNavigation>
And once you're in the custom control, you access the property with CompositeData.YourObject.
<xp:image
id="imgDummy"
url="/dummyEC.png"
styleClass="imageDummy">
<xp:this.rendered><![CDATA[#{not compositeData.node.hasChildren}]]></xp:this.rendered>
</xp:image>

Related

Xpages - Custom control getting a custom property from another custom control

I've searched google and stack but can't seem to find a definitive answer. What I would like to do, is something like this:
Say I have custom control A, within which, is a radio button, when I click it, I want it to grab a custom property that is set on custom control B, lets say compositeData.Name as an example. Can I do this?
If I give custom control B an ID, lets say ccB, can the radio button in custom control A do something like, getComponent("ccB").getValue().compositeData.Name so I can get the value of the property I passed into custom control B using the custom property 'Name'?
If its a straight no, at least I know to stop playing around with the idea! Thanks
Reaching from one control into the inside of another control would break component isolation. You might want to take a different approach:
Option a - client side:
Your control emits a JavaScript event that bubbles up until it reaches a parent element that contains the control you want to change (presumably the parent Dom element). There you set the property of that element.
Option b - server side:
As Urs suggested: bind both to a bean and handle the updates inside the bean

Is there a way to use a javascript object as a custom control property?

I'm currently building a custom control to be used as an application's view navigator (classic OneUI style). First of all: this is a 8.5.3 based project, and unfortunately there's no way to use Extlib stuff or other extensions / plug-ins. So we have to build all the tricky stuff ourselves using only what came "out-of-the-box" with 8.5.3.
I'd llike to build my navigator using a repeat control containing <xp:link> controls. Datasource could be an array of javascript objects where each single object would look like this:
var navEntry = {"entryLabel" : "label-of-link",
"entryTarget" : "target-url-of-link",
"entryStyle" : "style-to-emphasize-selected-link"}
Each array element then would describe a single navigator entry.
Since the navigator will be used in all possible "DominoView" Xpages it yould make sense to build the array of JS objects at the Xpage level and then pass that info into the custom control.
I'm aware that there are multiple ways to do this, and one could be "Custom Control Properties". If there was a way to pass my JS object array.
(Hope I could make clear what I'm trying to do here...)
That object looks like a HashMap to me really. You should be able to pass that in to a custom control via custom property if you use the type java.util.HashMap I'd think. You'll need to type it in I'm sure. I've passed custom objects in by using java.lang.Object.
The custom control will get loaded during the Page Load event, and usually properties have to be available at that point. If they're loaded during the Render Response phase, that's too late. So your SSJS object will need to be Compute on Page Load.
To use contents of a repeat control, you would need to set repeatControls=true, otherwise the repeat is only built during render response. Until then it's just a single set of controls with no data in them. However, Im pretty sure repeatControls="true" means you only get the number of rows you define. You can't change it via a pager.
You can manually define the type of the custom property. For a standard SSJS Object you use "com.ibm.jscript.std.ObjectObject", for a SSJS Array you use "com.ibm.jscript.std.ArrayObject" etc. As editor for the custom property, I set the string editor ("String value").

How can I add InputScope property to PasswordBox in WinRT?

How can I add Input Scope property to my User Control's PasswordBox?
Could you explain it to me, please?
Thanks.
according to the information i have PasswordBox does not have Input Scope Property in winrt so you can't set it directly. if you want do it you have to make your separate custom control. For defining your own Custom control you have read it on Windows Development Center..or simply google it..hope it helps you..
you can use this link..

Is it possible to determine the facet content in a custom controls design definition?

I'm putting together the design definition for a custom control and would like to vary how it displays based on whether or not a different custom control has been placed in the one of the facet areas. Is this possibe with the design definition and if so, how?
I know I can reference properties of the custom control by using "this", but I couldn't guess as to how to get to the facet content information.
Any ideas? Thanks
In the design definition you can add a callback node where your facet should appear. This should expose the Editable Area when you add your control to another page.
The format for the callback node would look similar to
<xp:callback id="callbackID" facetName="facetname" />
Dan,
Can you get the Editable Area as a javax.faces.component.UIComponent and then do .getFacets()?
BTW, hope you're well!

XPages Rich Text Component

Is there any chance to get the html content (mime) from a rich text component without any datasource. I would like to grab the content from the field like this. getComponent("FieldName").value but this dosen't work.
thanks.
You can bind the control to a scoped variable; for example, #{viewScope.comments}. You can then retrieve the submitted value from the scope instead of from the component itself; for example, viewScope.get("comments").
Alternatively, you can set a dataContext variable to a JS expression, e.g. <dataContext var="richText" value="#{javascript:return {value:""};}" />. Then you can bind the control to #{richText.value} and retrieve it via the same expression.
And, of course, you could define a managed bean and bind the control to one of its properties. This option provides the most flexibility, but isn't quite as simple as the other two options above.
The solution for my problem is
getComponent("FieldName").getValue()
thanks for your help.

Resources