B4J Tutorial [BANano] Why it is important to use unique names for your elements when not using AutoID?

Ola

I just spent some time nearly sweating as to why my app was not working properly. Turns out that my element names are not unique and as such a conflict arose.

1624993108777.png


Background

In one of my layouts i have a VFooter with a VFooter1 name. Then In another layout I put a footer with the same name ! Big mistake.

In the new layout, my VFooter1 component was empty however when I went to inspect elements on browser, it had content. Scratch head!!!

So the first layout with VFooter1 was loaded with all the elements inside, then the second layout with the second VFooter1 was also loaded. As much as this one was empty, but because these have the same names and identifier name VFooter1, they are treated as the same element. Children replicated across.

So if you are not using AutoID in your elements, be careful to name your controls properly.

After renaming the other footer to some unique name, my app works.

Ta!
 

alwaysbusy

Expert
Licensed User
Longtime User
Yes. HTML demands unique IDs. AutoID helps with non essential tags (like rows, cols, etc). It is always good practice to give your components a prefix in the name e.g. LAY1Label1 and LAY2Label1 where LAY1 and LAY2 are of course more sensible to the project. This could be solved it custom views in the Abstract Designer could have something else than "Main" for its parent (already reported to Erel).

If this would come available, I can start thinking of a system to prefix the IDs with its parent(s), just as ABM does. It would off course have the same drawbacks as in ABM: IDs can get complex: container1_container2_label3. The question is: is it worth to do so as this can be avoided just by using some discipline (and planning your layouts).
 
Top