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
|