Search code examples
javaxpages

Working with aliases and xpages control, how to?


in my app I have radiogroups that have label|alias values.

in read mode I want to display them in an edit box control and set the readonly attribute. the control has a data-binding to java classes e.g. value="#{matterBean.matter.idType}"

how can I best convert the aliases into the values?

the keywords are now stored in Notes documents.

should I build some sort of converter-class and define a custom converter for the edit box control ?

sample code:

<xp:radioGroup 
                        id="rgRelStudy"
                        value="#{matterBean.matter.busStudy}"
                        disabled="#{!matterBean.matter.editable}"
                        styleClass="radio-spacing" readonly="true">
                        <xp:this.defaultValue><![CDATA[#{javascript:getKeywordDefault("intakeStudy")}]]></xp:this.defaultValue>

                        <xp:selectItems>
                            <xp:this.value><![CDATA[${javascript:return getKeywordValues("intakeStudy");}]]></xp:this.value>
                        </xp:selectItems>
                        <xp:eventHandler event="onclick" submit="true"
                            refreshMode="partial" refreshId="pnlUpdate">
                            <xp:this.script><![CDATA[var e = arguments[0] || window.event;
e = dojo.fixEvent(e);
if (e.target.type != "radio") {
    e.preventDefault();
    dojo.query("input",e.target).forEach(function(inputNode){
        dojo.attr(inputNode,"checked",!(dojo.attr(inputNode,"checked")));
    });
}
return true;]]></xp:this.script>
                            <xp:this.onComplete><![CDATA[XSP.partialRefreshGet('#{id:pnlCollegeContainer}', {
    onComplete: function () {
        XSP.partialRefreshGet('#{id:pnlResidenceContainer}');
    }
});]]></xp:this.onComplete>
                        </xp:eventHandler>
                    </xp:radioGroup>

Solution

  • A Computed Field component would work too. Rather than a custom converter (assuming this is the only place it's used), I'd set a rendered property and use a custom method in the Java class, e.g. getIdTypeValues() and map to that. Bearing in mind it's only used in read mode, you can boilerplate the method with UIViewRootEx2 view = (UIViewRootEx2) resolveVariable("view");if (view.isRenderingPhase()) {....}. That way it will only run once, during the RENDER RESPONSE phase.