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
Highlighted
Developer
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2
Accepted Solution

Open page with selected data to another page

Hi,

 

i think this might be a simple question but everything i have tried don't seem to work.

 

I am trying to open a second page from a List, with a selected value, to another list in another page. However, I have tried every single possible combination from the tutorial but nothing works I am not sure how to explain so I have attached a diagram.

 

the FilterDataContainer.qml and FilterAlphaContainer.qml are identical except for the data query.

 

I have tried:

- ControlDelegate with NavigationTab [AKA saving the green coloured layer, FilteredDataContainer.qml as  NavigationTab -> turns out blank. Is it because the List itself is inside a .qml file that is then inside another Container?

- ComponentDefinition (the documentation only talks about adding it to the Container but I would like to create a new page;

 

What would be the easier way for this to work?

 

thanks!

 

QMLQuestion.png

BlackBerry Development Advisor
Posts: 15,264
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Open page with selected data to another page

[ Edited ]

Here is how I've done it before.  I defined 2 pages in different QML files.  On the first page I have something like this:

 

 

First Page

onTriggered method of my ListView

 

onTriggered: {
	var chosenItem = dataModel.data(indexPath);
	
	var page = secondPage.createObject();
	page.boardId = chosenItem.id[".data"]
	page.requestContent();
	
	navigationPane.push(page);
}

 The first page also defines the second page in the attached Objects section.

 

attachedObjects: [
	ComponentDefinition {
		id: secondPage
		source: "SecondPage.qml"
	}
]

 

Second Page

 

The second page defines a property that gets populated from the first page:

 

property string boardId

 

The second page also has a requestContent method, which loads up the data for the ListView on that page based on the boardId property.

 

 

 

 

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Open page with selected data to another page

Thank you M Sohm,

 

I have managed to get the page to open to another page. However, my query is not able to process the data being passed over.

 

With regards to:

 

page.boardId = chosenItem.id[".data"]
	page.requestContent();


is .id referrering to a custom property? or does it directly refers to the List selected?

Also, how do requestContent() deals with the data? Convert it to a string? Basically, I would like to insert the selected ID/data into my sql data query but it is getting undefined. E.g. my dataquery is "SELECT *.... WHERE = '" + boardId + "'". But on my console log I am getting back an 'undefined' value for the boardId.

 

Thanks for your help!

BlackBerry Development Advisor
Posts: 15,264
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Open page with selected data to another page

My DataModel is based on an XML document, so chosenItem.id[".data"] is referring to a value in it (the value of the "id" element).  You'd have to replace that with the variable in your DataModel you want to populate on the second page.

 

My requestContent method uses the boardId property on the second page (populated in the onTriggered method from the first page) to create my query to populate the DataModel for the ListView on the second page.

 

When/where are you getting the undefined?  Verify the value you are passing from the onTriggered method is valid.

 

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Open page with selected data to another page

The value that I am trying to pass is actually an integer from an SQL table. If I just assign it to a property string choosenData; it works if I put it in a Label.text, AKA the value shows up as the number in the label. However, when I pass it through the query, it shows up as undefined.

 

My current code for the first page is as such:

onTriggered: {
            var selectedData = dataModeldoc.data(indexPath);
            var newpage = pagebydoc.createObject(); //.qml file added as attachedObject in this page
            newpage.choosenDoc = selectedData.doc_order;
            newpage.requestedOption();
            rootNavPane.push(newpage)
           
        }

 On my second page, trying to use the requestContent you suggested, I have tried:

property string choosenDoc
function requestedOption(choosenDoc){
   	    switch (choosenDoc){
   	        case "1": return 1;
   	        break;
case "2": return 2;
break;
   	    }
   	}

 And in my DataSource{} query:

query: "SELECT title FROM new_list WHERE doc_ID = '" + choosenDoc +"'"

 But I am still getting back nothing for my 'choosenDoc'

 

BlackBerry Development Advisor
Posts: 15,264
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Open page with selected data to another page

You have to specify the page ID before the property when accessing it.  So if you define the property as:

 

Page {
        id: myPage
        property string myProperty
...

 In requestedOption you'd do:

 

function requestedOption(){

var query = "SELECT title FROM new_list WHERE doc_ID = '" + myPage.myProperty +"'";
}

 

 

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Open page with selected data to another page

That was not working either.

 

I have found the solution: http://supportforums.blackberry.com/t5/Native-Development/How-to-change-a-variable-of-an-attached-ob...

 

Basically I left my original code intact, and in fact reloaded the data:

onQueryChanged {

datasource.load()

}

 Very weird roundabout and seems to have nothing to do with the IDs/types etc. as I thought it was about!