How to set pattern for date/time converter in a theme? - xpages

I am trying to set a date/time converter using a theme but I can not get it to work.
I have tried the following and it doesn't work:
<control>
<name>InputField.EditBox</name>
<property mode="override">
<name>converter</name>
<complex type="xp_convertDateTime">
<property>
<name>pattern</name>
<value>DD-MM</value>
</property>
</complex>
</property>
</control>
If at all possible, how do I set a pattern for date/time converters in a theme?

I think the problem is timing. The theme settings are only applied during the render response phase.
The examples that work for complex properties are setting browser-related settings, like dojoAttributes. So the values are applied as the HTML is passed to the browser.
Converters work during the ProcessValidation phase (I've seen that with PhaseListeners). So the converter needs to be there much earlier in the lifecycle.
If I'm right, you won't be able to use a theme to apply a converter. You'd probably need to extend the Edit Box control and create your own component.

Related

XPages favicon with oneui theme

I want to set a favicon in XPages. I am using Domino 8.5.3 with the latest 8.5.x version of the extlib. As application theme oneuiv2.1 is used.
I tried setting the pageIcon attribute in the XPage without success. Adding a link attribute to the header using
<xp:this.resources>
<xp:headTag tagName="link" rendered="true" loaded="true">
<xp:this.attributes>
<xp:parameter name="rel" value="icon"></xp:parameter>
<xp:parameter name="href" value="favIcon.png">
</xp:parameter>
<xp:parameter name="type" value="image/png">
</xp:parameter>
</xp:this.attributes>
</xp:headTag>
</xp:this.resources>
did not change the favicon. I found in various blogs, that I have to add a control to the application theme, for example:
<control>
<property>
<name>pageIcon</name>
<value>favicon.ico</value>
</property>
</control>
However I use the provided oneUi theme and do not want to create a custom theme. Is there a way to either set the favicon directly or modify the theme without creating a complete new one?
I think you are missing the control name in your theme rule.
Here is the syntax of the theme rule that works for me. (Taken from Tim Tripcony's HowYaBean demo application referenced on NotesIn9 and downloadable from here). I use it a ton. It takes the icon from the NotesDatabase (remember the one from the old Notes workspace that has not yet been pried out of my cold dead fingers). It also works with image or file resources.
<control override="false">
<name>ViewRoot</name>
<property>
<name>pageIcon</name>
<value>/$icon</value>
</property>
<property>
<name>pageTitle</name>
<value>#{database.title}</value>
</property>
</control>
This works for me - icon shows in tab bar and shortcut created from application URL.
Image resource (PNG image) with name img_ApplicationIcon16. The name is generic for every application, but each NSF contains different image.
Every XPage has property pageIcon="/img_ApplicationIcon16"
It renders as <link rel="SHORTCUT ICON" href="/path/database.nsf/img_ApplicationIcon16">
In my case, I did not want to use theme, too.
Import the favicon.ico file as file resource instead of image resource
Add the following code to the selected theme:
<control>
<name>ViewRoot</name>
<property>
<name>pageIcon</name>
<value>/favicon.ico</value>
</property>
</control>
Set up the application to use the theme containing the reference for the favicon.
Create a new xpage for testing, or delete the browser cache.
This works for me properly. In the browser window you should see the folloving source:
<link rel="SHORTCUT ICON" href="/db.nsf/favicon.ico">
(db.nsf is your database.)
If still not work check the xpage: "All properties-styling-disableTheme" should not be enabled.

Theme setting properties for child of control

I know Button.command is the theme ID for normal buttons and I can set properties for it. And I know eventHandlers don't have a theme ID by default. So to set properties of an eventHandler centrally, I've historically added what I've had this in my theme:
<control>
<name>Button.EventHandler</name>
<property mode="override">
<name>onStart</name>
<value>loading();</value>
</property>
<property mode="override">
<name>onError</name>
<value>stoploading();</value>
</property>
<property mode="override">
<name>onComplete</name>
<value>stoploading();</value>
</property>
</control>
But I then need to add the themeId Button.EventHandler to each eventHandler.
Is there a way to set properties in a theme for children, so set properties on all eventHandlers that are children of Button.Command controls?
I cannot help You with solving Your theme problem, but perhaps I can give You solution to general problem.
I assume that what You try to achieve is to attach some nice loader to all partial refresh events. This can be done on a lower level by using dojo.subscribe API: http://dojotoolkit.org/reference-guide/1.6/dojo/subscribe.html
Example code:
// we need to activate io events
dojo.config.ioPublish = true
dojo.subscribe("/dojo/io/send", function(/*dojo.Deferred*/dfd){
loading();
});
dojo.subscribe("/dojo/io/stop", function(){
stoploading();
});
This code has to be run on application start (onClientLoad event will do just fine)

styleClass property always gets overwritten when adding style in theme

I am using a theme for my XPage application to set global look&feel settings so my configuration for the viewRoot looks like this:
<control dojoTheme="true">
<name>ViewRoot</name>
<property>
<name>pageIcon</name>
<value>/favicon.ico</value>
</property>
<property>
<name>style</name>
<value>#{javascript:
var response = facesContext.getExternalContext().getResponse();
response.setHeader("X-UA-Compatible", "IE=8");
}</value>
</property>
<property mode="concat">
<name>styleClass</name>
<value>claro</value>
</property>
</control>
Although I use the mode="concat", which I thought just adds (like array.concat) my properties to my viewRoot but it always overwrites it, so that my <body> looks like this:
<body class="claro"... instead of:
<body class="xsp lotusui claro"...
I experienced this problem with other <controls>/<properties> as well.
My current solution is that I set the property value to xsp lotusui claro not just only claro to prevent my body from loosing all oneui/xsp styles. Anyone got a idea why the mode="concat" is not working in my example? or is this mode for something else?
I could not find a good documentation of all theme properties so if someone got a good link, I would be glad if he could share it.
EDIT:
As I am also working on a XPages Theme at the moment I got more curious and played a little bit with this. As far as I can see your code works perfectly fine . In my Tests I experienced that you can concat a style definition to a pre-defined styleClass. So you can create an XPages and define a body style class like this with a body-styleClass predefined within the XPage:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" styleClass="mystyle">
<xp:button value="Label" id="button1" themeId="bt"
styleClass="oink">
</xp:button>
</xp:view>
Using a Theme you can now add another (or even multiple) styleClasses:
<control>
<name>ViewRoot</name>
<property mode="concat">
<name>styleClass</name>
<value>claro</value>
</property>
</control>
In your scenario, you want to concat the styleClass definition which is added as "default" styleClass - and this seems to be an issue or conflict.
So, for now this is my conclusion. If there is anybody else having more and deeper insights I would also be interested in deeper insights into Themes and inheritance in particular.
Old comment:
As far as I know, to only add the attribute, you should set the override-property of the control to false.
Example (your code changed):
<control dojoTheme="true" override="false">
<name>ViewRoot</name>
<property>
<name>pageIcon</name>
<value>/favicon.ico</value>
</property>
<property>
<name>style</name>
<value>#{javascript:
var response = facesContext.getExternalContext().getResponse();
response.setHeader("X-UA-Compatible", "IE=8");
}</value>
</property>
<property mode="concat">
<name>styleClass</name>
<value>claro</value>
</property>
Hope that works and helps,
Michael
I know it has been a while, but did you remember to "extend" the theme you want to include the original classes from? i.e.:
<theme extends="oneui">
<control….>…</control>…
</theme>

How to get space between icon and label on button?

I am working on one of my first xPages applications. I want to add a nice little icon (from the FamfamFam collection) to some of my buttons, e.g. "New","Save", "Cancel", etc.
I add the GIF images as image resource, and specify the image for the buttons I want the icons on.
It all works, but the label (text) on the button is right next to the icon. I would like them to be spaced out some, perhaps 4-6 pixels. I would prefer not to have to add spaces to the label, I am sure there is a better way, probably using CSS somehow.
Anyone know a good way to do this?
OneUI v2.1 is set as the theme for the application and I am using Domino Designer 8.5.3 and Domino Server 8.5.3.
You can use the following custom CSS to add some margin to the right of the icon:
.lotusBtn img {
margin-right: 10px;
}
To add a space I use an <xp:text themeId="Text.Blank"></xp:text>
Text.Blank is in my Theme resource with the following control block:
<control override="true">
<name>Text.Blank</name>
<property mode="override">
<name>escape</name>
<value>#{false}</value>
</property>
<property mode="override">
<name>value</name>
<value>&nbsp;</value>
</property>
</control>

JSF converter property

I am trying to register different converter instances in the faces-config, using a standard converter class to which different parameters are passed.
The code below registers two DateTimeConverters, the first one for dates including time and the second one for time only. But the pattern property never gets set. Can this be done?
<converter>
<converter-id>dateTimeConverter</converter-id>
<converter-class>javax.faces.convert.DateTimeConverter</converter-class>
<property>
<property-name>pattern</property-name>
<suggested-value>yyyy-MM-dd HH:mm:ss</suggested-value>
</property>
</converter>
<converter>
<converter-id>timeConverter</converter-id>
<converter-class>javax.faces.convert.DateTimeConverter</converter-class>
<property>
<property-name>pattern</property-name>
<suggested-value>HH:mm:ss</suggested-value>
</property>
</converter>
This is unfortunately not possible through faces-config.xml. The <property> declaration which you're trying is not used during runtime.
If all you want is to control the pattern at one place, then best what you can do is to create a custom converter. For this particular purpose it isn't that hard. Just extend DateTimeConverter and set the pattern during construction. Here's a basic example:
public MyDateTimeConverter extends DateTimeConverter() {
public MyDateTimeConverter() {
setPattern("yyyy-MM-dd HH:mm:ss");
}
}
You can of course get the pattern from somewhere else, e.g. a properties file or xml file in classpath.
Register this converter as follows:
<converter>
<converter-for-class>java.util.Date</converter-for-class>
<converter-class>com.example.MyDateTimeConverter</converter-class>
</converter>
That should be it. No need for f:converter or UIOutput#setConverterId().

Resources