Is there any way to check NodeIterator hasNext() condition in sightly.
For instance:
Resource resource = resolver.getResource("/etc/xyz");
Node node = resource .adaptTo(Node.class);
NodeIterator iterator = node .getNodes();
while (iterator.hasNext()) {
Node child = iterator.nextNode();
}
Here I am getting NodeIterator from sightly helper class.Now in html file I want to check hasNext() condition
As far as I think , hasNext() condition is used to check whether the next element exists or not (This condition is used to iterate all the elements).In sightly if you use data-sly-list tag , there is no need to check as it iterates only through the existing elements.Hope this helps.
Related
I am having scenario in which i want to fetch all the values of a property under a specific path in AEM using QueryBuilder api.
This property can have single or multivalued.
Any help will be appreciated!!
Example that can help you. is below as it is just for illustration written in simple JSP scriptlets
<%
Iterator<Resource> iter = resourceResolver.findResources("/jcr:root/content/geometrixx-outdoors//element(*, nt:unstructured)[(#imageRotate = '0' or #imageRotate = '1')]","xpath");
while (iter.hasNext()) {
Resource child = iter.next();
out.println("</br>"+child.getPath());
Node node = child.adaptTo(Node.class);
Property nProp = node.getProperty("imageRotate");
if(nProp.isMultiple()) // This condition checks for properties whose type is String[](String array)
{
Value[] values = nProp.getValues();
out.println(" :: This is a multi valued property ::");
for (Value v : values) {
out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+v.getString());
}
}
else if(!nProp.getDefinition().isMultiple()){
out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+nProp.getString());
}
}
%>
Here i have used the Iterator<Resource> iter = resourceResolver.findResources(query,"xpath"); which can give you the query results which matches the imageRotate property under /content/geometrixx-outdoors/ path which consists combination of single and multivalued as shown in below screenshot.
There is no direct way to fetch the properties using query builder api. I would suggest you to create a servlet resource, which requires a path and property name.
Fetch the jcr node using the given path via QueryBuilder. Then, you need to loop through the results to check the property of the nodes. You can access the multiple property values, once you have a node.
within an AnyLogic project, in the 'seize' block I need to make a custom choice of resources from resource sets.
Having in the properties tab of the 'seize' block the field "Resource sets" with the value { {ResourcePool_A, ResourcePool_B} } and the flag "customize resource choice" checked. In the "resource choice condition" code section, I need to make a choice like:
if (unit isfrom ResourcePool_A)
{
if (unit.param_a == value)
do something
....
}
else if (unit isfrom ResourcePool_B)
{
if (unit.param_b == value)
do something
....
}
How can I check if a resource unit is from a given pool or not and then discriminate resources accordingly with their features? Thank you. Best regards.
from your question it seems that you don't need to choose a specific resource, but rather do a specific set of actions on the resource once it has been seized.
which is why i've added two answers.
1.
If you just want to do a specific set of action. You should just copy your code to the "On seize unit" action in the seize object.
2.
If you want to select a specific resource. the easiest way to do that is to create an Anylogic function resource_selector()that returns a boolean.
if(unit isfrom ResourcePool_A && unit.param_foo == agent.param_bar)
...
your own code
...
return true;
else
return false;
and then in the Resource choice condition write:
resource_selector(unit, agent);
I solved the issue writing a an Anylogic function that returns a boolean and I used it in the resource choice condition. I implemented "isfrom" to discriminate from which pools the resource is picked up as shown in following code:
`
// cast pool object to the prorper type
ResourcePool t_pool = (ResourcePool)pool;
// resource selection condition
if ( (t_pool == ResourcePool_A && ((Resource_A)unit).param == agent.param_bar) ||
(t_pool == ResourcePool_B && ((Resource_B)unit).param == agent.param_bar) ) {
return true;
}
else {
return false;
}
`
In the Anylogic documentation is not explained that in the resource choice condition of the seize block you have access also to the pool object (this is bad...).
I want to create a tree of user with n level Hierarchy. I have a POJO object and within that I have id,parent_id.
The problem is user can belong in more than 1 group. So, when I am trying to do,
while (iterator.hasNext()) {
val user_pojo_obj = iterator.next()
val key = user_pojo_obj.id
val parent_key = user_pojo_obj.family_id
var child: Item = container.addItem(key)
child.getItemProperty("caption").asInstanceOf[Property[Any]].setValue(user_pojo_obj.name)
child.getItemProperty("POJOobj").asInstanceOf[Property[Any]].setValue(user_pojo_obj)
container.setParent(key, parent_key)
}
I got NullPointerException at the 2nd line, As per my knowledge it because of the addItem() duplication in container, which returns null.
Please suggest me the alternate if this can not be improve. (Using Scala)
Thanxx..
As far as I know, you can not have multiple parents or duplicate itemIds. The following pseudo-code is an alternate solution which builds the tree-like structure (node is your POJO):
counter = 0;
function process(nodes, parent) {
foreach (node in nodes) {
newId = counter++;
item = container.addItem(newId);
// set item caption etc.
if (parent not null)
container.setParent(newId, parent)
process(getNodesWithParent(node), newId);
}
}
process(getNodesWithParent(null), null);
The method getNodesWithParent needs to be defined by you. I guess you will take the iterator, iterate through your POJOs and return those with family_id equals the parameter's id. The overall performance depends on your implementation of getNodesWithParent, so if you have a large data set you should care to be efficient.
Given I have the elmFinder variable:
var elmFinder = element(by.css('.thing'));
What if i need to get back the webdriver.Locator, a.k.a locator strategy? i.e.
elmFinder.??? //=> by.css('.thing')
I'm looking after the function ??? if it exists.
UPDATE:
This feature has been merged and we can now do:
elmFinder.locator();
UPDATE:
This feature has been merged and we can now do:
elmFinder.locator();
Old answer:
You cannot. The element finder does not keep a reference to the locator:
https://github.com/angular/protractor/blob/master/lib/protractor.js#L103
What I typically do is store the selector in it's own var, and then place that string into the selector, so I can use both interchangably:
var cssThingSelector = '.thing';
var elem = $(cssThingSelector);
Something like that.
Edit:
I will also add that you can nest findElement calls from selenium webelement objects.
So, if there is another item in the inner html of the .thing web element (say, a span tag), you could just nest another findElement call:
var spanElem = elem.$('span');
You can do this as much as you'd like.
Using Ember.CollectionView I want to access and manipulate the DOM element which is being inserted by each child view. The issue I have is that I don’t know how to get a reference to the element from within didInsertElement. Here is the jsFiddle -- the summery of coffeescript is below:
window.App = Ember.Application.create()
window.App.initialize()
App.Item = Em.View.extend
didInsertElement: () ->
console.log ">>> element is: ", this.element
App.items = Em.ArrayController.create()
App.items.set('content',[
Em.Object.create({title:"AN", id:"item-one"}),
Em.Object.create({title:"Epic", id:"item-two"}),
Em.Object.create({title:"View", id:"item-three"})
])
App.EpicView = Ember.CollectionView.extend
classNames: ['epic-view']
contentBinding: 'App.items'
itemViewClass: 'App.Item'
this.element is undefined. I have also tried calling element and that is undefined as well. According to the docs, there is an element property available inside the view, but I don’t know how to access it, and I am not sure if it is available from within didInsertElement or not.
How can I get the id of the DOM element that was just inserted into the view? Ideally, I would like not having to search for it in the DOM since the view should already be aware of what it is inserting into the DOM.
ps: I am using Ember 1.0pre
Use get('element') or get('elementId') to access properties in Ember