Using design definition for computed properties - xpages

I cant find a solution for this problem. I am using design definitions for almost all my controls.
They are working fine the only problem i have is that if i am computing one of the properties i cant use the property anymore in the design definition. It will create a text in red and the xpages will prompt some error messages.
Is there a way to ask if the property is computed and show a standard text instead.
This is the design definition.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:inputText type="text" value="<%=this.field_name %>"></xp:inputText>
</xp:view>
Whenever the value of the property field_name is computed in the custom control it brings up that error.
Anybody any ideas?
When I insert the Field custom control with a static text value for field_name, the design definition will display the field_name properly.
<xc:Field field_type="text" field_name="myfield_1"></xc:Field>
If I insert the Field custom control with a computed text value for field_name, it doesn't:
<xc:Field field_type="text"><xc:this.field_name><![CDATA[# {javascript:"myfield_"+#Text(1)}]]></xc:this.field_name>
</xc:Field>

Make sure field_name is the exact name of the property passed in as CompositeData. For example, I was able to reference the string property 'create' to create the image of field this way:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:inputText value="<%=this.create%>">
</xp:inputText>
</xp:view>
So, I suspect it's a typo, a missing property, or not a string.

Related

how to generate the name of a custom control in it's design definition property

I would like to generate the name of the custom control in it's design definition property. how should i do that?
i tried:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:panel>
<%=this.pageName %>
</xp:panel>
</xp:view>
because this.getPageName() gives you the name of custom control name on custom control's main level.
but that does not work there.
After few tests it seems you can read only custom properties.
Because you write design definition to some specific custom control, you can use:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:panel>
My control name
</xp:panel>
</xp:view>
I am aware of harder maintainability with copypasta coding style.

Xpage: programmatically set custom control from session variable?

I am starting to get the dynamic nature of Xpages and am trying to make my coding more streamlined.
I am using the switchFacet cc in my xpages to control which custom control to load, depending on the value in a sessionScope variable.
To keep things simple I made the name of the cc match the sessionScope variable. So I ended up with the following code.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlnsstrong text:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xc:ccAppLayout>
<xp:this.facets>
<xc:ccAppNav xp:key="LeftColumn" />
<xe:switchFacet id="switchFacet1" xp:key="facet_1"
selectedFacet="#{javascript:return sessionScope.pageSelected}">
<xp:this.facets>
<xc:cpApp2Title1Page1 xp:key="cpApp2Title1Page1" />
<xc:cpApp2Title2Page1 xp:key="cpApp2Title2Page1" />
<xc:cpApp2Title2Page2 xp:key="cpApp2Title2Page2" />
<xc:cpApp2Title3Page1 xp:key="cpApp2Title3Page1" />
</xp:this.facets>
</xe:switchFacet>
</xp:this.facets>
</xc:ccAppLayout>
</xp:view>
Not to bad, but it seems to me things would be even cleaner if I could just directly set the cc to be the sessionScope variable. That way the code for this Xpage wouldn't have to change between different Xpages. I could get by with just one Xpage.
Is there a way to do this, and is it even a good idea?
Bryan
===============================================
What I am looking for is something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlnsstrong text:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xc:ccAppLayout>
<xp:this.facets>
<xc:ccAppNav xp:key="LeftColumn" />
<xc:#{javascript:return sessionScope.pageSelected} xp:key="facet_1"></xc:#{javascript:return sessionScope.pageSelected}>
</xp:this.facets>
</xc:ccAppLayout>
</xp:view>
==============================================================
Knut,
That is a good suggestion, but as you indicated it only loads on page creation.
Is there a different way to do what I want, or is it just easier to leave the code as I originally had it?
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xc:ccAppLayout>
<xp:this.facets>
<xc:ccAppNav xp:key="LeftColumn" />
<xp:include id="include1" xp:key="facet_1">
<xp:this.pageName><![CDATA[${javascript:sessionScope.pageSelected + ".xsp"}]]></xp:this.pageName>
</xp:include></xp:this.facets>
</xc:ccAppLayout>
</xp:view>
You can use <xp:include... and "calculate" custom control's name:
<xp:include pageName="${sessionScope.yourCC}" />
The sessionScope variable has to contain the name of your custom control like "cpApp2Title1Page1.xsp". Don't forget ".xsp" at the end.
Be aware that pageName gets calculated only once at first page load.
I know from your previous question that you'd like to keep the possible pages flexible in a sessionScope variable. Assuming you have a sessionScope variable pages which contains all custom control names as an array then you'd use a repeat and put the xp:include in it:
<xp:repeat
id="repeat1"
rows="30"
var="key"
repeatControls="true"
value="${sessionScope.pages}">
<xp:panel
rendered="#{javascript:sessionScope.pageSelected == key}">
<xp:include
pageName="${javascript:key + '.xsp'}" />
</xp:panel>
</xp:repeat>
It will include all pages defined in sessionScope variable pages but render only the one page with the name contained in sessionScope variable pageSelected.
You'd include the code above instead your switchFacet.
Could you create one custom control to rule them all? A CC that takes the name of the desired CC as a custom property, then renders only the one you want. So shove the switchFacet into a new custom control, e.g. ccAll.xsp:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:switchFacet id="switchFacet1" selectedFacet="#{javascript:return compositeData.ccName}">
<xp:this.facets>
<xc:cc1 xp:key="cc1" />
<xc:cc2 xp:key="cc2" />
<xc:cc3 xp:key="cc3" />
</xp:this.facets>
</xe:switchFacet>
</xp:view>
Add a custom property of ccName to the custom control using the "property definition" tab in the CC's properties.
Then add that to your XPage and pass in the sessionScope variable.
<xc:ccAll ccName="#{javascript:return sessionScope.pageSelected}"></xc:ccAll>
A while ago I have created a component to switch custom controls on-the-fly. The code is available at github:
https://github.com/hasselbach/domino-ccinjector
The component can inject custom components whenever you want: during a partial refresh or depending on a variable.

Custom Property in Repeat control stopped working

I have a strange bug that is reproducible but i cant find out whats causing it.
If i call this xpage i get the following error message:
Error while executing JavaScript computed expression
'fieldname' not found
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.data>
<xp:dominoDocument var="Request"></xp:dominoDocument>
</xp:this.data>
<xp:repeat rows="999" var="fieldname">
<xp:this.value><![CDATA[#{javascript:"myfieldname"}]]></xp:this.value>
<xc:Widgets_Field
field_datasource="#{javascript:currentDocument}"
field_name="#{javascript:fieldname}">
</xc:Widgets_Field>
</xp:repeat>
I have tried to empty the cc but without any success. The only thing thats working is when i am either hardcoding the property field_name or when i set the repeat control to "create controls at page creation"
I am absolutely sure that code was working before but i cant find out whats causing the error message. Can you please give it a try and let me know if you also have the same problem.
Attached please see stack trace
com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression
com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:132)
com.ibm.xsp.page.compiled.ExpressionEvaluatorImpl.getBindingValue(ExpressionEvaluatorImpl.java:151)
xsp.Widgets_005fField$Widgets_005fFieldPage.createInputText4(Widgets_005fField.java:776)
xsp.Widgets_005fField$Widgets_005fFieldPage.createComponent(Widgets_005fField.java:142)
com.ibm.xsp.page.compiled.AbstractCompiledPage.buildComponent(AbstractCompiledPage.java:265)
com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildChildren(CompiledComponentBuilder.java:115)
com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildAll(CompiledComponentBuilder.java:84)
Within the custom control, if you use wrong binding that should be known at the page load, it throws such an error. For instance if your custom control contains a "loaded" attribute like:
<xp:text
loaded="${compositeData.field_name}">
That will throw such an error. That's why it works with "create controls at page creation" setting.
Update: If you are going to use dynamic binding within the custom control, see my answer at this question:
Dynamic Data Binding?

How do I change the default XML generated for a blank XPage?

The default XML generated when a new XPage is created looks like thi
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
</xp:view>
but when you add new components from the extension library and other palette items the view xsmlns namespace changes. It also reformats code and screws up any JavaScript and or CSS on the page.
How can I change the default XML created to look more like this and therefore cover my bases when I add new components?
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom">
</xp:view>
One possible solution I could come up with would be to create a template in your Eclipse Designer (Preferences > XML > XML Files > Editor > Templates).
Just to test this I created this template:
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom"
Saved it under the name "myAddNamespace" with context "XML Attribute" and "Automatically insert" = ENABLED.
If then I create a new xpage, I can go into source view, place my cursor at the end of the default namespace before the closing '>', then type "my", hit - and then select my template to be inserted at the cursor position:
I'm aware that this is NOT what you really asked for, but it's at least something
Tested this on 9.0.1 and it automatically formats the way you mention. For example without touching anything I get this.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xe:dialog id="dialog1"></xe:dialog>
<xc:test></xc:test>
</xp:view>
You can force a reformat pressing CTRL-SHIFT-F (or right click, source->format). You can modify how the formatting works by selecting "File-Preferences" menu option, then select "XML->XML Files->Editor".
I think what you want is "Split Multiple Attributes each on a new line".

DataContext being executed multiple times

Has anyone noticed an issue with datacontexts in xpages. In certain scenario a single xpage with multiple custom controls would result in the datacontext being evaluated 12 times during a single page load?? Does this happen with other dataSources as well?
Here is a simple example, which gets executed 3 times!!
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.dataContexts>
<xp:dataContext var="doc1">
<xp:this.value><![CDATA[#{javascript:var doc:NotesDocument = database.createDocument();
doc.replaceItemValue("Form", "frmContact");
doc.replaceItemValue("fldFirstName", "test");
print("got here");
return doc;}]]></xp:this.value>
</xp:dataContext>
</xp:this.dataContexts>
<xp:inputText id="inputText1" value="#{doc1.fldFirstName}"></xp:inputText>
</xp:view>
Should I not be using dataContexts in my application?
And also watch out, if you are using partial refresh. Let's assume, you datacontext is in id B and you do a refresh on id A. The datacontext in id B will also be refreshed. Also happens to all other data sources.
I have described this behaviour here http://www-10.lotus.com/ldd/xpagesforum.nsf/topicThread.xsp?action=openDocument&documentId=56E9B8537DA50A90852579A6002EAC64#FA00DE3675A456C0852579AB005A1FF4
And there are also some hints about a PMR and a possible workaround for this.
Just like other controls on the page, the datacontext could be evaluated multiple times. See here for more information about the benefits of dataContexts. But in my opinion, from your code example, it could be faster to use a xp:data source but I'm not sure.
As with all other value bindings, if you change the # to a $, the value attribute of the dataContext may be requested multiple times, but the calculation to determine that value will only be executed once.

Resources