问题
Would like to automatically compute the pageTitle property on the XPage to simply show the XPage name. I want to code this once on the Application Layout custom control so every page where I add the control gets the benefit of the property calculation. So far, I have some SSJS on my CC to calculate the page title and assign to a viewScope variable:
var path:String = context.getUrl().getPath();
var xpageName:String = @RightBack(path,"/");
viewScope.xpageName = xpageName;
return xpageName
On any XPage where I add the CC I can simply return the value of the viewScope variable to the pageTitle property like this:
viewScope.xpageName
However, was wondering how to automatically set it from the CC without the need for the line above. Can this be done?
回答1:
You can also set the pageTitle in a theme. This page from Julian Buss's site shows code for defaulting the value http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/Work_with_themes. Because override is set to false, you can override it on any custom control or XPage you choose. This is one of the theme properties I set in all applications.
回答2:
You can do this as Declan says in the All Properties property on the Custom Control. I prefer to put this in the Database Theme using a control block like this:
<control override="true">
<name>ViewRoot</name>
<property>
<name>pageTitle</name>
<value>#{javascript:
var path:String = context.getUrl().getPath();
var xpageName:String = @RightBack(path,"/");
viewScope.xpageName = xpageName;
return xpageName
}</value>
</property>
</control>
This then forces your code to use the ssjs code for all XPages delivered in the database. I actually prefer that the return value be:
return database.getTitle() + " : " + xpageName;
Enjoy
/Newbs
回答3:
In the 'All Properties' panel of the custom control there is a 'pageTitle' property that you can use. Once set it will be used for the title of the page as long as there is no pageTitle property set on the main XPage and as long as no other custom control on the same page have the property set.
来源:https://stackoverflow.com/questions/11796760/how-to-set-the-pagetitle-property-for-all-pages-that-use-a-custom-control