I am currently in need of custom attributes which I can fetch anytime. Is there any way to create custom data attributes for nodes and then get those values in javafx?
Lets assume I have the the follwing Button.
<Button text="Im a button" fooBar="I hold some value" />
Similar to: https://developer.mozilla.org/de/docs/Web/Guide/HTML/Using_data_attributes
Now in HTML I could simply do the following:
<div id="example" data-foobar="I hold some value"></div>
Then I could easily get the data like this:
document.getElementById("example").dataset.foobar;
Edit: I need more than 1 data property for a node because a node can hold various information.
The data can be stored in the properties ObservableMap of a Node
Node node = ...
node.getProperties().put("foo", "bar");
...
Object foo = node.getProperties().get("foo");
Note however that some layout properties use this map too, so no property names similar to javafx properties / "static" properties should be used as key. To be sure you could create a custom key class that does not return true if an object of another type is passed as parameter to equals.
To solve your problem you should to use userData it can be any object that you need.
node.setUserData("Hello world");
node2.setUserData(123);
etc.
If you need to set multiple values you can save your values in an array, list, json etc.
ArrayList<String> vals = new ArrayList();
vals.add("Hello");
vals.add("World");
node3.setUserData(vals);
//some code
ArrayList<String> result = (ArrayList) node3.getUserData();
Related
I have created an ArrayList of media file paths and i want to get details of media file like title and album info in my JavaFX application. I want to add these details in ObservableList. So I created an iterator which gives path of all media files. Inside iterator loop, I have created a Media object. To get media information from Media object, I have created metadata event listener. I got media information in lambda function but i can't able to use them outside of lambda function. If i add info in ObservableList inside event listener lambda function than many null values inserting because of meta data iteration and only one useful information is inserting.
Here is my code:
ObservableList<PlayListModel> playListData = FXCollections.observableArrayList();
Iterator<JMPPlayListItem> it = playList.getIterator();
while(it.hasNext()) {
listMedia = new Media(it.next().getPath());
PlayListModel playListItem = new PlayListModel();
listMedia.getMetadata().addListener((MapChangeListener.Change<? extends String, ? extends Object> c)-> {
if (c.wasAdded()) {
if ("artist".equals(c.getKey())) {
playListItem.setArtist(c.getValueAdded().toString());
} else if ("title".equals(c.getKey())) {
// It prints title of song
System.out.println(c.getValueAdded().toString());
playListItem.setTitle(c.getValueAdded().toString());
} else if ("album".equals(c.getKey())) {
playListItem.setAlbum(c.getValueAdded().toString());
}
}
});
// It print null
System.out.println(playListItem.getTitle());
playListData.add(playListItem);
}
System.out.println(c.getValueAdded().toString()) is printing title of song but outside of lambda function System.out.println(playListItem.getTitle()) prints null. It means playListItem object's values isn't changing. I tried making playListItem final but wouldn't help. I also tried initializing playListItem object and playListData.add(playListItem) inside lambda function but it inserts title with many null title values because of event listener iteration.
I also tested with local variables but I'm not able to get values outside of listener lambda function.
I solved this problem. My solution is pass Media object in bean class's constructor and create another method in bean class that will retrieve media information and update bean object. This method is called through constructor. Now add this bean class's object in ObservableList. Observable list get updated automatically when media information event is fired. Now i can render tableview using ObservableList and using table.refresh() method, i can refresh table data when event is fired.
I'm pulling out information into a series of classes using the Firebase SDK in Android. My classes do indeed contain my data, but on trying to extract my data of something as the same class, I get:
java.lang.ClassCastException: java.util.HashMap cannot be cast to CustomItem
I have a class, called CustomItems, that has:
public Map<String, CustomItem> Items;
I'm loading this, by setting the following in the onDataChange event.
Items = (HashMap<String, CustomItem>) dataSnapshot.getValue();
Anyhow, on trying to read this information by using CustomItem item = Items.get('key'), shows me the correct object name of CustomItem in Android Studio and it's Intellisense, however always returns a Hashmap.
Having written this so far, Im wondering if I now need to actually iterate through the children to set a new CustomItem as
item = child.getValue(CustomItem.class);
And then add that item to a List in CustomItems.
I'm loading some data into a hidden Webix combo box via URL with two parameters. After loading, I want to store all values from the combo box into an array. But this doesn't work. If it is possible to load data from URL to an array without loading it first into a combo, how does this work? I use Spring ResourceMapping annotation in the controller.
You can use a webix DataCollection which work as any webix data component but without any graphical representation :
var store = new webix.DataCollection({ url:"data.php" });
Another solution is to manually do ajax request :
webix.ajax().get('data.php', function(txt, data) { console.log(data.json()); });
This code change all property of root bookmark to inheritzoom.
But i want to access Kids array of bookmarks and all bookmarks to inherit zoom.
how i access Kids array of bookmarks?
i want to change only property of bookmarks not destinations.
how i achieve? Can anyone help me out from this.
List<HashMap<String,Object>> list = SimpleBookmark.getBookmark(reader);
for(HashMap<String, Object> lis:list)
{
System.out.println(lis.size());
lis.put("Page",String.format("%d %s",page++,"XYZ"));
}
You want to access the Kids of a bookmark. This is done like this:
list.get("Kids");
I'm new to Struts 1 so may be its already a resolved question.
The situation is: I have a list of <html:multibox> tag, which are rendered into html-checkbox element when the page loads. I want the checkboxes to be checked by default (without using javascript/jquery).
You would set the fields in your Form if you want them selected. For multiple checkboxes with all the same name but different values, your Form should have a String[] property that holds all the selected values. Just populate that with the values you want selected by default. This could be something as simple as:
public void reset(ActionMapping mapping, HttpServletRequest request) {
if(multiboxField == null) {
multiboxField = new String[2];
multiboxField[0] = "optionOne";
multiboxField[1] = "optionTwo";
}
}
The best way to do this is with a *formname*SetupAction.java class.
Set your struts-config.xml to redirect people who click on your page to this SetupAction. Import your form class, populate your String[] with whatever values you want default-checked, and action-forward them back to your page. This also allows you to dynamically populate them, based on DB data or session variables or whatever you want.