This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jun 7, 2013, 1:46 PM
25 Posts

Hide when

  • Category: Other
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags: Combo box hide when
  • Replies: 9

I guess this is easy. I have searched the web and read for hours. But I just don't get it.

I have a field or should I say control, that I want to hide based on a selection of a combo box.

I have a tabbed table control.

I have two controls - a combo box and a radio button on the first tab. If I select Short Term Disability, I want the radio button control to be displayed, if the value selected is not Short Term Disability, I would like it not displayed.

 

I put the following code in the onchange event of the combo box control

var combo:javax.faces.component.UIComponent = getComponent("leaveType");
var comboVal = combo.getValue();
var edit:javax.faces.component.UIComponent = getComponent("note");
var edit1:javax.faces.component.UIComponent = getComponent("drNoteLabel")
if (comboVal == "Short Term Disability")
edit.setRendered(true);
else
edit.setRendered(false);
if (comboVal == "Short Term Disability")
edit1.setRendered(true);
else
edit1.setRendered(false);

 

When I test, if I select short term disability, the radio button does not display. However, if I click on the second tab of the tab control and then come back to the first tab, the radio button control is displayed.

 

So I guess it is a refresh issue.

 

I'm just getting started and boy do I find this to be difficult.

Thanks in advance for any help.

Sincerely,

Betsy Thiede


Jun 7, 2013, 3:17 PM
54 Posts
refresh

You are right. In your combobox set the partial refresh.

Jun 7, 2013, 3:27 PM
586 Posts
thoughts

Betsy,

I'm usually a little slow and without pictures or a live example it's had for me to just look at code and know what's going on.  But here's my comments / thoughts...

This is likely due to the tab control.  If you're using the built in tab control keep in mind that only the currently displayed tab is rendered to the browser.  The other tabs basically don't exist and I'm pretty sure aren't even in the JSF component tree.  So each tab change requires a trip to the server.  I don't like this.  If you want to use the tab control I'd take a hard look at the Dojo version as then everything exists on the page it's just hidden appropriately via CSJS.

But you can probably make it work they way you want today.  I would suggest not basing the rendering on direct access to the components. I know I've never personally created a variable for a component yet like you do:

var edit:javax.faces.component.UIComponent = getComponent("note");

 

Of course this doesn't make me right.  It's just something I've never needed to do.

 

More often then not I control rendering via a scoped Variable.  So my suggesting is in your onChange event set a viewScope variable - true or false to what you want to do.

viewScope.put("vsShortTerm". true);  or false depending on your needs

 

Then in the rendered event of the radio button do:

viewScope.get("vsShortTerm");

That should be all you need really then I'd think.  If the control gets removed from the tree because you changed tabs no biggie.. but when it comes back it should read in the scoped variable and render accordingly.

 

Hope that helps!!

Good Luck!

 

Dave

 

 

 

Jun 7, 2013, 5:36 PM
25 Posts
Hmmm

Thanks you two.

 

I tried to do as you said, but I have no idea what it means. I feel so frustrated.

Perhaps this is too advanced for me.

Jun 7, 2013, 6:31 PM
1 Posts
Use the rendered property

I think it is easier to use the rendered property combined with a partial refresh of the combobox.

You have to wrap the radiobutton in a span or div with an id, e.g. radioContainer (or use an existing parent id in your code). Set this for the refresh id of an event to the onchange event of the combobox:

Set the rendered property of the radio button to:

rendered="#{javascript:getComponent( 'leaveType').getValue() == 'Short Term Disability'}"

Use an event like this on the combobox:

<xp:eventHandler
            event="onchange"
            submit="true"
            refreshMode="partial" refreshId="radioContainer">
</xp:eventHandler>

The container is necessary for the event to find the component when the radiobutton is not rendered.

 

Jun 7, 2013, 6:45 PM
25 Posts
Here is my code.. still not working

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xc="http://www.ibm.com/xsp/custom">
    <xp:this.data>
        <xp:dominoDocument formName="LeaveType" var="document1" />
    </xp:this.data>
    
    <xc:header></xc:header>
    <xp:tabbedPanel id="tabbedPanel1">
        <xp:tabPanel label="Main" id="tabPanel1" style="padding-left:5.0px;padding-right:5.0px;padding-top:2.0px;padding-bottom:2.0px">
            <xp:table style="width:100.0%">
                <xp:tr><xp:td style="width:150px"><xp:label value="Leave Type:" id="leavetype_Label1" for="leavetype1"></xp:label></xp:td><xp:td>
    <xp:comboBox id="leaveType" value="#{document1.leavetype}">


        <xp:this.onchange><![CDATA[#{javascript:refreshMode="partial" refreshId="note"}]]></xp:this.onchange>
        <xp:selectItem itemLabel="Bereavement"
            itemValue="Bereavement">
        </xp:selectItem>
        <xp:selectItem itemLabel="Family Medical Leave Act"
            itemValue="FMLA">
        </xp:selectItem>
        <xp:selectItem itemLabel="Floater Day"
            itemValue="Floater Day">
        </xp:selectItem>
        <xp:selectItem itemLabel="Jury Duty" itemValue="Jury Duty"></xp:selectItem>
        <xp:selectItem itemLabel="Leave of Absence"
            itemValue="Leave of Absence">
        </xp:selectItem>
        <xp:selectItem itemLabel="Flextime" itemValue="Flextime"></xp:selectItem>
        <xp:selectItem itemLabel="Reserve Duty"
            itemValue="Reserve Duty">
        </xp:selectItem>
        <xp:selectItem itemLabel="Scheduled Sick Leave"
            itemValue="Scheduled Sick Leave">
        </xp:selectItem>
        <xp:selectItem itemLabel="Short Term Disability"
            itemValue="Short Term Disability">
        </xp:selectItem>
        <xp:selectItem itemLabel="Unscheduled Sick Leave"
            itemValue="Unscheduled Sick Leave">
        </xp:selectItem>
        <xp:selectItem itemLabel="Vacation" itemValue="Vacation"></xp:selectItem>
    </xp:comboBox></xp:td></xp:tr><xp:tr>
                    <xp:td>
                        <xp:label value="Received Physician's Authorization Note?" id="drNoteLabel">

                        </xp:label></xp:td>
                    <xp:td>
                    
                        <xp:radioGroup id="note"
                            value="#{document1.note}" defaultValue="No">

                            <xp:this.rendered><![CDATA[#{javascript:rendered="#{javascript:getComponent( 'leaveType').getValue() == 'Short Term Disability'}"}]]></xp:this.rendered>
                            <xp:selectItem itemLabel="Yes"
                                itemValue="Yes">
                            </xp:selectItem>
                            <xp:selectItem itemLabel="No"
                                itemValue="No">
                            </xp:selectItem>
                        </xp:radioGroup></xp:td>

                    
                </xp:tr>
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td></xp:td>
                </xp:tr>
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td></xp:td>
                </xp:tr>
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td></xp:td>
                </xp:tr>
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td></xp:td>
                </xp:tr>
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td></xp:td>
                </xp:tr>
            </xp:table></xp:tabPanel>
        <xp:tabPanel label="Approval Section" id="tabPanel2"></xp:tabPanel>
    </xp:tabbedPanel></xp:view>

 

so here is the code it generated.

My radio control is being displayed if I select Short Term Disability, but only if I click on the Approval Tab and then come back to the Main tab.

Curious to me why my label value highlighted in the code is being displayed and hidden as well. As it isn't part of the Radio control with the id = "note"

Jun 7, 2013, 7:47 PM
366 Posts
The tabbed table is the culprit

As a rule tabbed tables in XPages are evil.  Try and avoid them at all costs especially if you are trying to something like this.

 

The problem is the contents of the unselected tab are not rendered and each tabs on click event is doing a full refresh.

 

Get this code working OUTSIDE of the tabbed table FIRST.  I will post some sample code based upon your code later ( I don't have my VM running right now)

Then If you just HAVE to have the tabbed table then look at the dojo or jquery tabbed table instead.

 

 

Jun 7, 2013, 8:00 PM
25 Posts
Thanks Paul

I'll see if I can getting working without the tabbed table. My confidence is shot.

 

Seems like a simple thing to do.

 

All of our Notes client rely so much on tabbed tables and so many hide when formulas. I'm like, goodness, if I can't get a cheesy radio button to hide when I select something from a combobox, then there must be something wrong with me.

Jun 7, 2013, 8:30 PM
54 Posts
partial refresh

Try this solution for the combobox and the radio button inside a DIV.

<xp:comboBox id="leaveType" value="#{document1.leavetype}">       
        <xp:selectItem itemLabel="Bereavement"
            itemValue="Bereavement">
        </xp:selectItem>
        <xp:selectItem itemLabel="Family Medical Leave Act"
            itemValue="FMLA">
        </xp:selectItem>
        <xp:selectItem itemLabel="Floater Day"
            itemValue="Floater Day">
        </xp:selectItem>
        <xp:selectItem itemLabel="Jury Duty" itemValue="Jury Duty"></xp:selectItem>
        <xp:selectItem itemLabel="Leave of Absence"
            itemValue="Leave of Absence">
        </xp:selectItem>
        <xp:selectItem itemLabel="Flextime" itemValue="Flextime"></xp:selectItem>
        <xp:selectItem itemLabel="Reserve Duty"
            itemValue="Reserve Duty">
        </xp:selectItem>
        <xp:selectItem itemLabel="Scheduled Sick Leave"
            itemValue="Scheduled Sick Leave">
        </xp:selectItem>
        <xp:selectItem itemLabel="Short Term Disability"
            itemValue="Short Term Disability">
        </xp:selectItem>
        <xp:selectItem itemLabel="Unscheduled Sick Leave"
            itemValue="Unscheduled Sick Leave">
        </xp:selectItem>
        <xp:selectItem itemLabel="Vacation" itemValue="Vacation"></xp:selectItem>
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="partial" refreshId="Div1">
        </xp:eventHandler></xp:comboBox>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:div id="Div1">
        <xp:radioGroup id="note" value="#{document1.note}"
            defaultValue="No"
            rendered="#{javascript:getComponent( 'leaveType').getValue() == 'Short Term Disability'}">
            <xp:selectItem itemLabel="Yes" itemValue="Yes">
            </xp:selectItem>
            <xp:selectItem itemLabel="No" itemValue="No">
            </xp:selectItem>
        </xp:radioGroup>

    </xp:div>


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal