Not logged in. · Lost password · Register
Forum: agsXMPP RSS
null value returned from XDataList
Avatar
ThomWill #1
Member since Mar 2010 · 9 posts
Group memberships: Members
Show profile · Link to this post
Subject: "Too Many items in listbox error" in xdatalistsingle when rendering node config form
When asking for a node configuration OpenFire 3.6.4 returns options list as <value> elements with no <label> elements.

<field type="list-single" label="Publisher model" var="pubsub#publish_model"><option><value>publishers</value></option><option><value>subscribers</value></option><option><value>open</value></option><value>publishers</value></field>

This causes an error when loading the xdatacontrol because the underlying xdatalistitem class returns a null value for ToString() when loading values into the combo box of the Xdatalistsingle user control.   The MS combo box control has an issue when an item is added and the ToString() of that item is a null value.

public override string ToString()
{
      return m_Label;           
}

I have made two changes to protect against this:

1. Changes in the xdatalistitem object to handle this value only situation.

public override string ToString()
        {

            if (!string.IsNullOrEmpty(m_Label))
            {
                return m_Label;
            }
            else
            {
                if (!string.IsNullOrEmpty(m_Value))
                {
                    return m_Value;
                }
                else
                {
                    return string.Empty;
                }
            }

        }

2. Changes in the xdatalistsingle class

public void AddValue(string val, string label)
{           
    XDataListItem item = new XDataListItem(label, val);
        if (!string.IsNullOrEmpty(item.ToString()))
        {
              comboBox.Items.Add(item);
        }
         
}
Avatar
Alex #2
Member since Feb 2003 · 4311 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
thanks for posting and a patch. Can you please post the complete Xml stanza of the Openfire node configuration? Then I can debug this.

Thanks,
Alex
Avatar
ThomWill #3
Member since Mar 2010 · 9 posts
Group memberships: Members
Show profile · Link to this post
Alex,

Sure, here is the request my client sends and the complete Iq result returned from OpenFire.   I am working now on sending the modified response back to the server... we will see how that goes.  I have noted that the CreateResponse() method produces output with the order of the fields reversed from the initial Data object used to create the form.  Not sure it will cause any issues, but it does look confusing when compared to the examples in XEP-0060.

<iq type="get" to="pubsub.d194137" from="publisher" id="xmppClientIQ6"><pubsub xmlns="http://jabber.org/protocol/pubsub#owner"><configure xmlns="http://jabber.org/protocol/pubsub" node="Breast Cancer" /></pubsub></iq>

<iq xmlns="jabber:client" from="pubsub.d194137" to="publisher@d194137/CDCPublisher" type="result" id="xmppClientIQ6"><pubsub xmlns="http://jabber.org/protocol/pubsub#owner"><configure xmlns="http://jabber.org/protocol/pubsub" node="Breast Cancer"><x xmlns="jabber:x:data" type="form"><title>Node configuration</title><instructions>Please provide the configuration for node "Breast Cancer".</instructions><field type="hidden" var="FORM_TYPE"><value>http://jabber.org/protocol/pubsub#node_config</value></field><field type="text-single" label="Short name for the node" var="pubsub#title"><value /></field><field type="text-single" label="Description of the node" var="pubsub#description"><value /></field><field type="boolean" label="Allow subscriptions to node" var="pubsub#subscribe"><value>1</value></field><field type="boolean" label="New subscriptions require configuration" var="pubsub#subscription_required"><value>0</value></field><field type="boolean" label="Deliver payloads with event notifications" var="pubsub#deliver_payloads"><value>1</value></field><field type="boolean" label="Notify subscribers when the node configuration changes" var="pubsub#notify_config"><value>1</value></field><field type="boolean" label="Notify subscribers when the node is deleted" var="pubsub#notify_delete"><value>1</value></field><field type="boolean" label="Notify subscribers when items are removed from the node" var="pubsub#notify_retract"><value>1</value></field><field type="boolean" label="Only deliver notifications to available users" var="pubsub#presence_based_delivery"><value>0</value></field><field type="text-single" label="Type of payload data to be provided at this node" var="pubsub#type"><value /></field><field type="text-single" label="Message body XSLT" var="pubsub#body_xslt"><value /></field><field type="text-single" label="Payload XSLT" var="pubsub#dataform_xslt"><value /></field><field type="list-single" label="Specify who may subscribe and retrieve items" var="pubsub#access_model"><option><value>authorize</value></option><option><value>open</value></option><option><value>presence</value></option><option><value>roster</value></option><option><value>whitelist</value></option><value>open</value></field><field type="list-single" label="Publisher model" var="pubsub#publish_model"><option><value>publishers</value></option><option><value>subscribers</value></option><option><value>open</value></option><value>publishers</value></field><field type="list-multi" label="Roster groups allowed to subscribe" var="pubsub#roster_groups_allowed" /><field type="jid-multi" label="People to contact with questions" var="pubsub#contact" /><field type="text-single" label="Default language" var="pubsub#language"><value>English</value></field><field type="jid-multi" label="Node owners" var="pubsub#owner"><value>publisher@d194137</value></field><field type="jid-multi" label="Node publishers" var="pubsub#publisher" /><field type="list-single" label="Select entity that should receive replies to items" var="pubsub#itemreply"><value>owner</value></field><field type="jid-multi" label="Multi-user chat room to which replies should be sent" var="pubsub#replyroom" /><field type="jid-multi" label="Users to which replies should be sent" var="pubsub#replyto" /><field type="boolean" label="Send items to new subscribers" var="pubsub#send_item_subscribe"><value>1</value></field><field type="boolean" label="Persist items to storage" var="pubsub#persist_items"><value>0</value></field><field type="text-single" label="Max number of items to persist" var="pubsub#max_items"><value>-1</value></field><field type="text-single" label="Max payload size in bytes" var="pubsub#max_payload_size"><value>5120</value></field></x></configure></pubsub></iq>
Avatar
Alex #4
Member since Feb 2003 · 4311 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
thanks, I will debug and update the code ASAP.
You can reverse the order easily by just reversing the loop through all fields.
Avatar
ThomWill #5
Member since Mar 2010 · 9 posts
Group memberships: Members
Show profile · Link to this post
Thanks!  I did that.  I have now discovered a bug on the OpenFire side of things... looking at the reply from the server I posted to you...

<field type="list-single" label="Select entity that should receive replies to items" var="pubsub#itemreply"><value>owner</value></field>

I get this "list-single" type with a value, but no option elements, and so the xdatacontrol renders (and rightly) and empty combobox.  Then when one sends back to the server, we get an error for not sending back a valid value from the list...   AAAARRGGHHH!

So now, I need to fix the OpenFire code, OR change the Xdatalistsingle control to handle this "I have no options, but I do have a value" scenario, probably should do both.

I am not daunted... much.

ThomWill
Avatar
ThomWill #6
Member since Mar 2010 · 9 posts
Group memberships: Members
Show profile · Link to this post
Alex,

Even though this last issue was not really an issue with agsXMPP I did make the following changes to protect from this happening when working with OpenFire.



In the XDataListSingle class I modified the getter and setter.   The getter to check for the existence of a selected item (just to be safe if we get no options AND no value)  and the setter to check first for the existence of the value and if not found, add it before setting the combobox list index.

        public string Value
        {
            get
            {
               
                    if (comboBox.SelectedItem != null)
                    {
                        XDataListItem li = (XDataListItem)comboBox.SelectedItem;
                        return li.Value;
                    }
                    else
                    {
                        return null;
                    }
               
             

            }
            set
            {
               
                XDataListItem chk = new XDataListItem(null, value);
                if (!comboBox.Items.Contains(chk))
                {
                    comboBox.Items.Add(chk);
                }

                for (int i=0; i < comboBox.Items.Count; i++)
                {
                    XDataListItem li = comboBox.Items[i] as XDataListItem;
                    if (li.Value == value)
                    {
                        comboBox.SelectedIndex = i;
                        break;
                    }
                }

             
            }
        }

Then, to support the comboBox.Items.Contains() function,  I overrode the Equals function of the XDataListItem so that it compares ONLY on the value element (due mainly to the issue that started this thread)

 public override bool Equals(object obj)
        {
            //Check for null and compare on value only
            if (obj == null || GetType() != obj.GetType()) return false;

            XDataListItem x = (XDataListItem)obj;
            return (Value == x.Value);           
        }

 public override int GetHashCode()
        {
            return Value.GetHashCode();
        }

Regards,

Thom
This post was edited on 2010-03-29, 21:26 by ThomWill.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS