how can I get an array of all objects in w2ui - w2ui

I am trying to subsequently manipulate the menus and tabs of a w2ui application.
In order to implement a generic solution, I added an additional attribute (zndesktop) to the related elements. Now I am looking for a generic method which gives me an array of all objects having this attribute.
Of course, I can hardcode such a query. But I am asking if there is an generic approach (for example w2ui.objects) which would return an array of all UI objects created for the application (recursive search)

w2ui objects are actually stored directly in the global w2ui object using their name, until you destroy them.
Example: if you create a grid with
$('#grid').w2grid({
name: 'my_grid',
...
});
Then you can access it with w2ui.my_grid or w2ui['my_grid'].
Of course you can also iterate the w2ui object (or rather its properties) just like any other JS object.

Related

AEM - How to pass data to a component

Usually an AEM component is retrieving its data from a JCR node, but I was wondering whether it's possible to pass data to it in HTL. Sure, there's data-sly-resource, but as far as I know this way you can only pass a JCR node.
So in an actual case I've got data in a model that's retrieved from elsewhere. Yet I'd like to use existing components. I'm aware that the data must at least match the component-types' model.
But what if the component I'd like to use is using an model that got its data injected like
#Inject
#Optional
String[] itemList;
So in my stubborn thoughts it should be possible to somehow pass a string array like
<div data-sly-resource="${myModel.aStringArray # resourceType='my/component' }"></div>
But like mentioned above this seems to be meant for passing nodes only.
Is there any way to accomplish passing data directly to a component (other than creating a template)?
You can pass additional information in the form of request attributes or selectors
Selectors
Selectors are the most straight forward of passing simple information. This is an array of strings that can be passed. This is quite useful to data that can act as flags ex:
Variant/Mode of the component
index of the component in a list if it is being included in a loop.
ID of the parent when building things like accordion, tabs
This approach is an abuse of selectors, but IMHO as long as you know what you are doing this shouldn't be a major concern.
<article data-sly-resource="${'path/to/resource' # selectors=['s1', 's2']}"></article>
You can add, replace or remove selectors while including the component. Checkout the documentation for the syntax. https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#resource
Request Attributes
This option allows you to add custom request attributes to the component request. This can be used to pass objects as parameters to the component while including them.
These are standard http request attributes with convince of scoping them to a particular instance of script/resource inclusion. To use this you will end up needing a model class or use-js as there is little support to compose the data to be passed along in sightly.
<sly data-sly-use.settings="com.adobe.examples.htl.core.hashmap.Settings"
data-sly-include="${ 'productdetails.html' # requestAttributes=settings.settings}" />
https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#request-attributes
There is another way. You can pass additional parameters to the Sling Model on initialization using data-sly-use. For example:
<div data-sly-use.model="${'com.model.Teaser' # test='abc'}"
You can read then the variable "test" in model from request:
#PostConstruct
private void initModel() {
String value = request.getAttribute("test");
// value is 'abc'
}
In order this to work correctly you need to make sure your Sling Model is adaptable from request #Model(adaptables = SlingHttpServletRequest.class}

Why no "insertAssociation" function?

I am writing a custom control and have an association declared like this:
details: {type: "sap.m.IconTabFilter", multiple: true, singularName: "detail"}
In the debugger I can see that there is an addAssociation function available, but there is no insertAssociation function (I am extending from sap.m.ResponsivePopover if that makes a difference).
My use-case is that I have an sap.m.IconTabBar that is internal to my control which I populate internally. But I also need to allow consumers to pass in their own custom tabs.
I want consumers to be able to instantiate my control using XML view types for example, so I am trying to expose a "details" association so they can seamlessly add the custom tab without having to create their own IconTabBar.
Is my understanding of associations incorrect?
Declaring it multiple says to the framework to store the association as an array. You are getting a method called getDetails() for this association. And also an addDetail and a removeDetail() method. Not sure if I understood your question because if you have a addDetail to add content to the association why do you want the insert?
J.

CFWheels form without objectName for design purposes

Is it possible to create a form using form helpers without having an object to link the form to? I want to just design a form and have it render, but I don't have an object to point to yet. Or, is there a simple way to create a dummy object? For instance,
<p>#textField(objectName="dummy", property="name", label="Name")#</p>
objectName seems to be a required parameter. http://cfwheels.org/docs/1-3/function/textfield
In CfWheels, there are four types of form helper functions:
form object functions
form tag functions
Form Association functions
General form functions
The one you are using is form object function which requires object and there are other functions (form tag functions) like bellow that don't require object to bind to:
textFieldTag()
fileFieldTag()
checkBoxTag()
etc....
Check out all [form tag functions][1]
[1]: http://cfwheels.org/docs/1-0/function/category/view-helper category.
I hope this helps.

Select ObjectSet by entity type

I need a way to select objects given the name:string of the object and ObjectContext, but dont know how to do this.
I will use this to create a generic lookup dropdown editor template in ASP.MVC
So when view contains #Html.EditorFor (student=>student.School), it will show dropDown containing list of schools.
I get the target entity name from relation.ToMember, but don't know how to query data records with this input.
Currently I have added a custom method which gets string and returns innumerable and inside that I have a big switch case "School": return this.SchooleSet;
Is there a right way to do this.
I also want to add a generic method which allows me to query using syntax like ctx.Select<Teacher>().Where(...)
again here I have implemented with switch but there should be a better way to do this.
Try the CreateObjectSet method.
var q = ctx.CreateObjectSet<Teacher>().Where(...);

Spring List Binding in Form

I'm trying to bind a list/arraylist/hashmap/etc of custom objects to my form in JSP using Spring. Right now, the controller creates a Map of the two lists (Boolean list and custom object list) in referenceData(), and provides it to the form which uses those values to populate the fields. The values are initialized from a MySQL database using Hibernate, and all that works fine. The list is a known length before the form is initialized, so that part is easier. Now what I'd like to do is correctly bind those objects in the form, so that when there are changes made, I can detect that in onSubmit() (or wherever is appropriate), and update the database accordingly. I can't seem to bind them correctly in the form so that I can see changes made. I tried just using a list of the form fields as the model, but even that wasn't working correctly. Do I just need to inject the list in a particular way? Any ideas or examples here? Any help would be greatly appreciated.
UPDATE: At Ralph's request here is the solution I used:
In my data object class, I lazy loaded a map using MapUtils.lazyMap(), with a String key and other custom object value. The other custom object is just a class that contains List<String> and getters/setters. In the corresponding .jsp file, I just nest several loops to loop through the keys first using loop.current.key and then loop2.current.value.paramsList to loop through the values for that key. This was not really what I asked for in my original post, as I was looking for a more general solution, and the lazy loading pointed me in the right direction.
In Spring 2 you need a special List in your Command object, that is able to grow if one add the x-th element event if the list has not this size yet.
One way to do that is to use LayzList decorator from commons-collections.
#Override
protected Object formBackingObject(final HttpServletRequest request)
throws Exception {
List<PosterSelectionRow> posterSelectionRowList = LazyList.decorate(
new ArrayList<PosterSelectionRow>(),
new PosterSelectionRowListFactory());
return new PosterSelectionCommand(posterSelectionRowList);
//PosterSelectionCommand contains a list of selected poster rows
}
private static class PosterSelectionRowListFactory
implements org.apache.commons.collections.Factory {
/** Invoked if the list need a new element */
public Object create() {
return = new PosterSelectionRow();
}
}
When I remember right, there is a way without that Factory stuff, but I am not sure.