Zend Navigation: current page - zend-framework

There is a method isActive() in Zend_Navigation. But it returns true for all the elements in the current path
(parent li is active and all the children too, even when the current is parent li).
Is there any method like isCurrent(), to determine whether the current menu item is the current page?
I just like to add custom class attribute to just one, current element in the whole nested tree of ul's and li's.

easier with:
$activeElement = $view->navigation()->findOneBy('active', 1);
if you're inside your view script you can use:
$activeElement = $this->navigation()->findOneBy('active', 1);

You will need to use your own navigation view script, but that's fairly simple. Then try:
$this->navigation()->findActive($this->yourNavContainer);
That will return an object, var dump it and you will see the data you need. I think the variable is simply called 'page'. Do this before you build your menu, pre/post dispatch, then in your viewscript, do an if statement to check this var against the current looped item (i guess your loop it in a foreach).

Related

How to re-insert element with same id into sap.m.Page?

I want to remove all content of a page and insert different content into it with a click of a button.
Unfortunately some of the content is the same and therefore has the same id.
I expected it to not be a problem because I never try to insert the same element twice. I want to remove it before reinserting it again.
But apparently the methods I found: oPage.removeAllContent(); and oPage.destroyContent(); don't actually remove the old content completely because I'm still getting the error that I'm trying to add an element with a duplicate id:
Error: adding element with duplicate id 'text'
How can I remove the old content so that the old ids are actually forgotten and I can reinsert them?
Here's a minimal example (click the Reload button twice and on the second time the error will appear in the console):
https://jsfiddle.net/1Lqc36uh/
Here's the most relevant (I think) part:
let oPage = this.byId(this.detailId);
oPage.removeAllContent();
oPage.destroyContent();
if (bSetText) {
oPage.insertContent(new sap.m.Text(this.textId, {
text: "SetText"
}));
} else {
oPage.insertContent(new sap.m.Text(this.textId, {
text: "Test"
}));
}
Delete the line oPage.removeAllContent();.
The issue is that you're removing the content and then trying to destroy it:
oPage.removeAllContent(); // removes the existing content (without destroying it).
oPage.destroyContent(); // tries to destroy but there is no content!
The ManagedObject method destroyXYZ() relies on the fact that the child controls exist as part of the aggregation in the first place.
Removing the controls by removeAllXYZ() does remove them from the UI and makes them no longer related to the parent, but they're not destroyed and still in the control registry. Hence, the "duplicate ID" error.
The method destroyContent() is sufficient to remove the content from the UI and from the control registry.
Do you really need to give each element an ID? Most things can be done without an ID in UI5. Usually a JSONModel is the better approach to control UI elements.
For example you can make the first element visible and the second invisible (even using the same property in the JSONModel so both elements are automatically toggled).
That being said you can destroy the removed elements themself.
oPage
.removeAllContent()
.forEach(oControl => { oControl.destroy(); });
Edit: You can unaccept this answer, seems like #Boghyon gave a better one.

How to select a treeItem in a treeView, after checking a Condition on that treeItem, in Javafx

I have downloaded familyTree project and it doesn't have the ability to search for an specific family member!
I have added a search button to it, and in the handler method section, I need the code that searches for a member that has the specified socialID , and select it (scroll it to the sight, and make it blue (selected)). But I don't know how to programmatically select a treeItem, and make it visible and selected?
My code:
#FXML
private void btnSearch_click(ActionEvent event){
for(TreeItem<FamilyMember> treeItem:root.getChildren()){
if(treeItem.getValue().getNationality().toString()=="22"){
// treeView.setSelectionModel(item);
treeView.getSelectionModel().select(treeItem);
//it still doesnt select the item with nationality=="22"
break;
}
}
}
You can select the item with
treeView.getSelectionModel().select(item);
and if you still need to scroll (I think selecting it might automatically scroll to it), do
treeView.scrollTo(treeView.getRow(item));
A couple of notes:
I do not understand the for loop. Why are you doing
TreeItem<FamilyMember> item = root.getChildren().get(i);
and why are you creating the index i? What is wrong with the treeItem variable you already defined in the loop syntax? Isn't this necessarily exactly the same thing as item?
You need to read How do I compare strings in Java?

Wrap a list of WebElements and present as a single WebElement

I am automating testing of a response web app and have an issue with multiple elements on the page with the same #FindBy selector where only one is visible at a particular screen resolution (in this case a logout button that 'moves' around the screen).
I could just get a list of webelements and click on the first visible, but I was wondering if I could do something smarter using html elements:
Given the following annotation
#FindBy(css = ".logoutButton")
MultiWebElement logoutButton;
When I call this method
logoutButton.click();
Then the MultiWebElement class will iterate over all elements that match the find by and call the click method on the first one that isDisplayed().
Unfortunately the decorator seems to want logoutButton to be of type List which defeats the purpose of creating the new class.
Can I do something like this, or is this outside the current scope?

MvvmCross DataBinding To Modify Individual Item in Android ListView

I am trying to dynamically modify the items in a List (ObservableCollection) of a ViewModel and have those changes get updated in the View via MvvmCross bindings. My eventual goal is that when a user clicks on a list item, I will pop up a dialog asking them to edit that item. When the dialog is dimissed, the viewmodel will get updated (through an ICommand I assume) and that modified value will be now be in the list.
I haven't looked into dialogs yet, so for now I am just trying to toggle a boolean value each time a list item is clicked and have that value changed in the MvxListView. I have the MxvListView in my View bound to an ObservableCollection in my ViewModel and have an MvxCommand that is getting called when an item is selected. All this is working and I can see the value getting changed in the debugger, however, the new values are not being displayed in the MvxListView. So my question is: How do I get modified data in individual items in an ObservableCollection to bind to an MvxListView?
All of the examples I have seen online use ObservableCollection for dynamic binding but they only ever Add or Delete items. I haven't found any examples of modifying the items. If I change the code in my MvxCommand from modifying the data to adding or deleting an item, the list will get updated. So that tells me I'm close I think.
Rather than copy paste the code in here, I created a sample project on github here to look at:
https://github.com/smulrich/breaktimer
I appreciate the help.
You can simply replace
Breaks[index] = b;
with
Breaks[index] = new DailyBreak() { Reason = b.Reason, TimeOfDay = b.TimeOfDay, Enabled = b.Enabled };
or more reasonable, you should realize INotifyPropertyChanged for class DailyBreak
Diffrent among List, ObservationCollection and INotifyPropertyChanged, please refer to enter link description here

How to retrieve view from controller of another view?

I am just wondering how can I get one of the UI5 views in an application.
I know there is a method:
sap.ui.jsview(); // in case the view is written in JavaScript
But the problem with this method is: if you assign ID for any of the controls and you have already inflated this view, you get an error.
So I want to know how to check if the view already exists and then if yes return that existing view, otherwise create the view with the corresponding API such as the above one.
I also know in the control for view I can go
this.getView();
But as I said, how to get this view from another view?
I am not quite understanding your question
With managed object id's are unique, so if you try and create the same view twice you will get an error.
when you create your view the easiest way to access it is via an Id
sap.ui.jsview("view1",'testapp.view.view1');
sap.ui.getCore().byId('view1');
NB. views should not talk to anyone other than their controller A terrific Model View Controller (MVC) diagram
sap.ui.getCore().byId(<id_of_the_view>)
Where <id_of_the_view> can be obtained in the following way:
suppose that the corresponding controller of <id_of_the_view> is "controllerA.js",
then you can console.log, inside controllerA.js,
console.log(this.getView())
This will print you an object which contains the id of such view. This will be <id_of_the_view>
I think here is one solution.
Make a global variable;
Use it to create element.
In First View:
var mytextField ;(use it as global)
mytextField = new sap.ui.commons.TextField('textfieldId');
In Second View:
var myValue = mytextField .getValue();
~Mansi Rao