GWT Editor Set Path Programmatically - gwt

If you are defining an Editor in GWT using the UiBinder, then you can specify the path to a property value using the #Path annotation.
If you are defining an Editor without using the UiBinder (i.e programmatically), how can you specify the path to an editable attribute without using the annotation?

You can use the same #Path annotation on the declared fields.
It is not bound to UiBinder.
You can bind properties to fields in 2 ways -
1) Declare the field with the same name as the property.
2) #Path annotation, in case, if the field and the property are declared with different names.
If you don't want to bind any property to the field, declare that field with #Ignore annotation.
These annotations are all used by Editor Framework's Code generator to generate some supporting java classes.
So, At Runtime you can not change the Path of the editors programmatically.

If you define your UI programmatically, you can still use #Path (or just name the field to match the property) on a field in your widget class. Not using UiBinder doesn't mean you can't use the Editor Framework.
That said, paths cannot be defined programmatically, no matter how you build the ui. The Editor Driver generating code requires that it can see which properties will be used so it only generates the necessary code to wire properties into editors.
Editor and UiBinder are totally distinct features - it just so happens that both can wire into fields in your class. UiBinder doesn't care about #Path annotations any more than Editors care about #UiField

Related

How does Jackrabbit generate jcr:uuid (in AEM)?

I am trying to create an auto-generated GUID property on all cq:PageContent nodes. This will be similar to the jcr:uuid property, but will be persisted with content promotion/replication/package installs (whereas the jcr:uuid for a content item changes between different environments).
I am trying to determine how AEM/JCR generates the jcr:uuid property on node creation. The CND defining the property is:
[mix:referenceable]
mixin
- jcr:uuid (string) mandatory autocreated protected initialize
I've tried defining my GUID property in a similar manor, specifying the autocreated and initialize attributes, but this did not result in auto-generation of the property.
Could anybody point me to the source of the jcr:uuid's generation?
As an aside, I asked a related question on the Adobe Community Forum: http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.5_ciot.html/forum__bnxr-i_am_tryingtocreat.html
You don't mention which version of AEM (so whether you're dealing with Jackrabbit or Oak), but the mechanism turns out to be basically the same.
When assigning a default value, there are a few hard-coded system property names that get special treatment (jcr:uuid being one of them). If the name of the property being assigned a default value doesn't match any of the special cases, it falls back the static list of default values from the property definition (e.g. listed in the CND file).
In summary, it looks like you cannot piggy-back on this mechanism to assign your own dynamic default value for an arbitrary property. You would need to implement your own event listener or something.
Jackrabbit: See the implementation of setDefaultValues and computeSystemGeneratedPropertyValues
Oak: See the implementation of TreeUtil autoCreateProperty

CssResource #Source annotation when using #external

What happens when using multiple in the #Source annotation of a CssResource in a ClientBundle? Is this compatible with using #External/#CssResource.NotStrict?
To be more specific - in our codebase I encountered a ClientBundle that contains something like this:
#Source({"style1.css", style2.css"})
#CssResource.NotStrict
CustomCss css();
This suggests that definitions in style2 can override definitions in style1. Should this also work when using #CssResource.NotStrict, so without the accessors and obfuscation?
When #Source has multiple values, it's equivalent to concatenating the files (in order) into a big stylesheet. This is mostly useful to import constants (#def, #eval or #url) or #externals.
It doesn't change anything to the behavior or #external (note: that means one file can declare as #external a class name used in another file) or #NotStrict.

In GWT, How to use custom widget tag in an .ui.xml file with and without parameters for the tag in the same file

I am creating a custom widget, say "CustomWid" in UiBinder.
And in CustomWid.java file I am writing two constructors
one with zero args like
CustomWid(){....}
another with some args like
CustomWid(String a,String b){......}
So,Now I am using my custom widget in another .ui.xml file,in that .ui.xml file
it is working fine when we give
<my:CustomWid/> alone,
and also fine when we give like
<my:CustomWid a="srt1" b="str2"/> alone
But "MY PROBLEM" is whenever I am trying to give both the tags in the one .ui.xml as
<my:CustomWid/>
<my:CustomWid a="str1" b="str2"/>
Now it is throwing error when i am using both types of tags in a single .ui.xml
I mean How to use my custom widget tag like a prdefined tag?
I am using #uiConstructor, but it showing error
Please developers... I need answer as early as possible
UiBinder will only ever use a single constructor for a given widget: either its zero-arg constructor, or a #UiConstructor (I'm surprised that you say it works when using either one or the other call but not both: one should fail in every case, and one should succeed in every case; if you haven't annotated a constructor with #UiConstructor, then <my:CustomWid/> should always work and <my:CustomWid a="str1" b="str2"/> should always fail)
There are two solutions here:
use setters for the a and b attributes (void setA(String a) and void setB(String b))), and possibly check later (say, in onLoad or onAttach) that you have either none or both of A and B, but not one without the other (if that's your rule).
use #UiField(provided = true) when you need to use the other constructor (if you choose to have UiBinder use the zero-arg constructor –i.e. no #UiConstructor–, then that means you'll have to move the a="str1" b="str2" from the XML to the Java code: #UiField(provided = true) CustomWid myCustomWid = new CustomWid("str1", "str2")).
The first option has my preference.
It Will not show any errors...'
#UiConstructor
public Component(String displayText,String heading)
{
initWidget(uiBinder.createAndBindUi(this));
this.displayText.setText(displayText);
this.heading.setText(heading);
}`
now use another constructor with default parameters also it will work
public Component()
{
initWidget(uiBinder.createAndBindUi(this));
}
now if you add with xml parameters component and without parameters also works in the same page.

What does wicket:scope attribute do?

There's no documentation for it https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html#Wicket%2527sXHTMLtags-Attributewicket%253Ascope. Does it work only for components?
What does wicket:scope attribute do?
The HtmlHeaderContainer class documents the wicket:scope attribute:
wicket:head tags (components) must only be added once. To allow for a little bit more control, each wicket:head has an associated scope which by default is equal to the java class name directly associated with the markup which contains the wicket:head. It can be modified by means of the scope attribute.
It is further documented in the HeaderPartContainer class simply stating that it is "A kind of namespace."
Does it work only for components?
The wicket:scope attribute is used only for the tag. The tag should only be used in "Panels, Borders and inherited markup (of Panels, Borders and Pages)", as documented in the HtmlHeaderContainer class level javadoc.
In short, the answer to your question is no, the attribute can be used within tags inside of Pages that inherit markup from a parent. The implication here is that a tag only makes sense where you wouldn't just use a tag (meaning in the base page html file).

setting styleName attribute in ui.xml overwrites primaryStyleName set in constructor of widget

I've written a custom widget with its own set of styles. These styles are defined in a little resource interface contained in the widget, and applied in the constructor of the widget.
I'd like to use the widget in a uibinder xml file, and apply additional styles there. Unfortunately, setting the styleName attribute seems to remove the styles applied in the constructor, and indeed the setStyleName javadoc indicates that it clears other style names.
What's the best solution here? I could override setStyleName, but that takes away options later. Is there a way to call addStyleName instead of setStyleName from the ui.xml file?
Did you try addStyleNames in your ui binder file?