A simple use of the Custom Converter
Feb 11, 2014
http://www.bleedyellow.com/blogs/DominoHerald/entry/a_simple_use_of_the_custom_converter?lang=en_us


I love XPages work, but there are some bits that are fustrating to me. One is the lack of simple examples for things. For example, in the samples provided by IBM (like the Discussion library, or the OneUI samples) there are a lot of "moving parts" making it hard to see just the bit you are looking for. There are reasons for this, of course, but it makes it a bit harder when you want to understand one aspect, and there are a couple of callbacks, variables, locales, etc. in the mix. What I want is a sample where we do just one thing - forget formatting and everything else, I want to see just one part work. OK, rant off.
Since this is want I want, I figured something out today, so I'm sharing in hopes that is will assist someone else. I've wanted to make Custom Converters work for a while, but every time I went looking, I didn't seem to be able to grasp it. The need came up today, and I have a simple use of a Custom Converter. It is based on this post, but I made it a bit simpler so I could see the results.
<xp:inputText
id="inputText1"
value="#{viewScope.passVariable}">
<xp:this.converter>
    <xp:customConverter getAsObject="#{
javascript:value;}">
        <xp:this.getAsString><![CDATA[#{
javascript:try{
var dIn=value.toString();
dIn = "Prepend " + dIn + " Append";
return dIn
;
} catch(e){
print (e);

}}]]></xp:this.getAsString>
    </xp:customConverter>
</xp:this.converter>
</xp:inputText>

Pop this in an XPage, and create a button to do a full page refresh. When you preview, you can put something (like your name) into the field, click a the refresh button, and it will change the string. So you can go from:
<bleedyellow does not like inserting image directly into blogs>
Click here for the before picture
Click here for the after picture
You need to put a value in for getAsObject. Per is brilliant (follow him if you don't), but this makes it a bit simpler for me to look at.
Cheers,
Brian
 

 


Add a Comment 
More Actions 
Comments (1)


1 Steve Pridemore commented Feb 12 2014 Permalink Recommendations 0
That same post from Per inspired me to do this one 
http://openntf.org/XSnippets.nsf/snippet.xsp?id=converter-to-clean-up-font-tags-in-richtext-maintained-in-notes-client
It strips out unstyled font tags from richtext or changes the font tag to a span with the matching styles but is implemented as a java class instead of ssjs.
File TypeSizeFile NameCreated On
image/gif 2 KB ConvertAfter.gif 6/3/15 1:59 PM
image/gif 1 KB ConvertBefore.gif 6/3/15 1:59 PM
This is an archive of my previous blog http://www.bleedyellow.com/blogs/DominoHerald attachments are in the download control