Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Dhanya
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device
My Carrier: Vodafone
Accepted Solution

ListView not loading xml using DataSource??

Hi,

 

When I am using DataSource for loading XML, the listview shows the data only if there is atleast 2 item in the XML.

 

import bb.cascades 1.0
import bb.data 1.0
NavigationPane {
    id: nav
    Page {
        
        id: emp
        titleBar: TitleBar {
            visibility: ChromeVisibility.Visible
        }
        onCreationCompleted: 
                                {
                                    dataSource1.load(); //load the xml when page is created
                                }
        actions: [
                      
            ActionItem {
                title: qsTr("Create List")
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered: {
                    dialog.open();
                }
            }
        ]
        Container {
            topPadding: 30.0
            leftPadding: 20.0
            rightPadding: 20.0
          
          
          ListView {
              id:list1
            dataModel:dataModel
             listItemComponents: [
                        ListItemComponent {
                           
                            StandardListItem {
                                
                                 title: {
                                qsTr(ListItemData.name)
                            }
                            }
                        }
                    ]
       
                  
            }

        }
        
            
             } //page

    attachedObjects: [
         GroupDataModel {
                    id:dataModel
                },
                 DataSource {
                      id: dataSource1
                      source: "models/employeelist.xml"
                     query: "/root/employee"
                    type: DataSourceType.Xml
                      onDataLoaded: {
                      dataModel.clear();
                       dataModel.insertList(data);
                      }
                    },
        Dialog {
            id: dialog
            Container {
                background: Color.Gray
                layout: StackLayout {
                }
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Center
                preferredWidth: 700.0
                leftPadding: 20.0
                rightPadding: 20.0
                topPadding: 20.0
                bottomPadding: 20.0
                Container {
                    background: Color.White
                    horizontalAlignment: HorizontalAlignment.Center
                    preferredWidth: 700.0
                    preferredHeight: 50.0
                    Label {
                        text: "Add Employee List"
                        textStyle.base: SystemDefaults.TextStyles.TitleText
                        textStyle.color: Color.DarkBlue
                        horizontalAlignment: HorizontalAlignment.Center
                        textStyle.fontSizeValue: 4.0
                    }
                }
                Container
                {
                    topPadding: 30.0
                    layout: StackLayout {
                        orientation: LayoutOrientation.LeftToRight
                    }
                    Label {
                    text: "Employee Name "
                }
                TextField {
                    id:nametxt
                }
            }
           Container {
               topPadding: 30.0
                    layout: StackLayout {
                        orientation: LayoutOrientation.LeftToRight
                    }
                    Button {
                       text: "OK"
               onClicked: 
                   {
               var name=nametxt.text;
               if(nametxt.text=="")
               {
                    _model.toastinQml("Please enter a name");
               }
               else
               {
             
	               _model.writeEmployeeName(name); //writing name to the employeelist.xml
	                
	               nametxt.text="";
	               dialog.close();
	             dataSource1.load(); //loading the xml
	             }
             
                   }
                        preferredWidth: 300.0
                    }
            Button {
                 text: "Cancel"
                 onClicked: 
                     {
                         dialog.close();
                     }
                        preferredWidth: 300.0
                    }
                         }
            }
        }
    ]
  
    
}//navigation

 

When I add a name first time to the xml, the list shows nothing.Then when I add a name again, it displays the list.

Why is it so? Is there any mistake I have done?

Please Help!!

 

Thanks in Advance

Dhanya

Please use plain text.
Developer
oniongarlic
Posts: 72
Registered: ‎10-19-2012
My Device: Playbook, BB10DevAlphaB
My Carrier: Sonera, Saunalahti

Re: ListView not loading xml using DataSource??

Having the same problem here too. Have you found a solution?
Please use plain text.
Developer
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: ListView not loading xml using DataSource??

I don't know the solution, but I can give you an hint: the problem comes from the query :

query: "/root/employee"

 

I had to parse an xml file manually and when the list has only one element, it is not longer recognise as a list by the XmlDataAccess.

Try with something like "/root/", but if it works, then it does not support multiple items anymore....

Please use plain text.
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: ListView not loading xml using DataSource??

[ Edited ]

Try setting the grouping property of the GroupDataModel to ItemGrouping::None. The GroupDataModel is mainly used for sorting data items by comparing the values of at least two items and accordingly sort them.

 

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: ListView not loading xml using DataSource??

Sorry for bumping old thread but how is it mark 'Solved'? ItemGrouping::None does not help me. If .xml has only one Item to show then this Item is not shown at all. Everything is ok when .xml has 2+ items.

Please use plain text.
Regular Visitor
andrescgf1
Posts: 1
Registered: ‎04-11-2013
My Device: Z10
My Carrier: AT&T

Re: ListView not loading xml using DataSource??

I'm also having this problem. Would anyone be so kind in providing a solution?

Please use plain text.
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: ListView not loading xml using DataSource??

[ Edited ]

It seems that this is a known issue reported on the DIT that has been escalated to BlackBerry's internal MKS defect tracking system. Until this issue is investigated by our internal teams, please use the workaround suggested by the reporter of the issue by introducing an "if" statement before inserting the data to the DataModel:

 

                if (data.name) {
                    empDataModel.insert(data);
                } else {
                    empDataModel.insertList(data);
                }

 

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Developer
oniongarlic
Posts: 72
Registered: ‎10-19-2012
My Device: Playbook, BB10DevAlphaB
My Carrier: Sonera, Saunalahti

Re: ListView not loading xml using DataSource??

Great! Thank you for the workaround, it fixes my issue.
Please use plain text.
Trusted Contributor
Mitch99
Posts: 102
Registered: ‎05-09-2013
My Device: BB10 Z10
My Carrier: Virgin

Re: ListView not loading xml using DataSource??

[ Edited ]

How do I accomplish the same in C?

 

As, in:

 

    if(???)
    	m_dataModel->insert(list.value<QVariantMap>());
    else
    	m_dataModel->insertList(list.value<QVariantList>());

 

Please use plain text.
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: ListView not loading xml using DataSource??

[ Edited ]

Hi Mitch99, are you seeing the same issue in C++? The DataSource class is specifically intended to be used in QML: https://developer.blackberry.com/cascades/reference/bb__data__datasource.html

 

P.S. Replace the ??? with the following line:

 

m_dataModel->data(indexPath).value<QVariantMap>().value("name").toString()

 

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.