0
votes

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>
2
What do you mean you want to display them in an edit box control? If it's readonly mode isn't the value just a string at that point? Why use another component? Do you need to place the info elsewhere on the page? Because, as long as you keep the selectItem tags on the page, the conversion from value to label is handled automatically. How have you defined the items? - shillem
the display in an edit box is just for make-up. I do not want to display the other options in the checkbox group that are not selected in read mode. At this moment the web form is the form that users also print-out and I want to keep layout therefor to a minimum. I also need to display the alias in several languages. And later I need to collect the "label" value when I add a library that is suitable to create PDF's. For display in read mode I could use a combobox instead of a radiogroup. or are you suggestion I should use a different control? - Patrick Kwinten
A radio group in readonly="true" mode outputs just the values and not the other unselected options. It's like any other control when in read mode. - shillem
Hi, I tried this but then I still get the other non-selected values returned. - Patrick Kwinten
May I see the code you're using to create the checkbox group? - shillem

2 Answers

0
votes

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.

0
votes

I tried to reproduce the problem you are having but either I'm misunderstanding it or there's something else going on on your end, because it works as expected for me. If you consider this scratch code you have 2 buttons that turn the radio group readonly mode or not. When in readonly only the label associated with checked values is shown, but not the other ones.

<xp:view xmlns:xp="http://www.ibm.com/xsp/core" style="padding: 20px"
    beforePageLoad="#{javascript:viewScope.readonly=false}">

    <xp:div id="theThing">
        <xp:button value="Make readonly" id="buttonReadOnly"
            rendered="#{not viewScope.readonly}">
            <xp:eventHandler event="onclick" submit="true"
                execMode="partial" refreshMode="partial" refreshId="theThing"
                action="#{javascript:viewScope.readonly=true}" />
        </xp:button>

        <xp:button value="Make editable" id="buttonEditable"
            rendered="#{viewScope.readonly}">
            <xp:eventHandler event="onclick" submit="true"
                execMode="partial" refreshMode="partial" refreshId="theThing"
                action="#{javascript:viewScope.readonly=false}" />
        </xp:button>

        <hr />

        <xp:radioGroup id="rgRelStudy" value="#{viewScope.relStudy}"
            styleClass="radio-spacing" readonly="#{viewScope.readonly}"
            defaultValue="o">
            <xp:selectItems value="${javascript:['apple|a', 'orange|o', 'banana|b']}" />

            <xp:eventHandler event="onclick" submit="true"
                execMode="partial" refreshMode="partial" refreshId="pnlUpdate" />
        </xp:radioGroup>
    </xp:div>

    <hr />

    <xp:div id="pnlUpdate">
        <h3>The radio value (not label)</h3>
        <xp:text value="#{viewScope.relStudy}" />
    </xp:div>

</xp:view>