webfirmframework for Java Experts

TagRepository for tag manipulations

A tag repository is a high level repository for tags contained in the browserPage instance for tags manipulations. The TagRepository may be used to find tags with different criteria. The TagRepository is available since wffweb-2.1.8 just for an introduction but a bug free and performance improved version will be available since wffweb-2.1.10. The TagRepository instance may be got from the instance of BrowserPage using browserPage.getTagRepository() method.

There is an important feature in TagRepository class, i.e. to attach JavaScript objects to a tag's wffObjects property from server. As we know the Java object for JavaScript object is WffBMObject and Java array for JavaScript array is WffBMArray, using TagRepository.upsert/delete methods we can set objects/arrays from server to a client html tag/element so that we can use these values by client JavaScript code. Find more details in its example.


The following are some of the methods in TagRepository

To get TagRepository instance

TagRepository tagRepository = browserPage.getTagRepository();

TagRepository.findAllTags

TagRepository tagRepository = browserPage.getTagRepository();
Collection<AbstractHtml> allTagsInTheBrowserPage = tagRepository.findAllTags();
				

TagRepository.findAllAttributes

TagRepository tagRepository = browserPage.getTagRepository();
Collection<AbstractAttribute> allAttributesInTheBrowserPage = tagRepository.findAllAttributes();
				

TagRepository.findOneTagAssignableToTag

TagRepository tagRepository = browserPage.getTagRepository();
				
//use it to find a particular type of tag, 
//if there are many matchings a random one will be returned.
//you can also find a custom tag (a new class which extends any tag)				
Body body = tagRepository.findOneTagAssignableToTag(Body.class);

TagRepository.findTagsAssignableToTag

TagRepository tagRepository = browserPage.getTagRepository();
//returns all matchings for the given tag class type.
Collection<Div> divs = tagRepository.findTagsAssignableToTag(Div.class);

TagRepository.exists

This is a fast and efficient way to find the existence of a tag or attribute in the UI.

TagRepository tagRepository = browserPage.getTagRepository();
//any tag instance to check its presence in the ui				
AbstractHtml tagInTheUi;				
boolean tagExists = tagRepository.exists(tagInTheUi);

//any attribute instance to check its presence in the ui				
AbstractAttribute attributeInTheUi;				
boolean attributeExists = tagRepository.exists(attributeInTheUi);
				

TagRepository.findTagById

TagRepository tagRepository = browserPage.getTagRepository();

//to find one tag by id attribute
AbstractHtml tagById = tagRepository.findTagById("alertDivId");

				

TagRepository.findOneTagByAttribute

TagRepository tagRepository = browserPage.getTagRepository();


//any attribute instance in the ui to find one tag consumed by this attribute			
AbstractAttribute attributeInTheUi;				
AbstractHtml tagByAttributeInstance = tagRepository.findOneTagByAttribute(attributeInTheUi);

//to find one tag by attribute name and value 
AbstractHtml tagByAttributeNameAndValue = tagRepository.findOneTagByAttribute("id", "alertDivId");

				

TagRepository.findOneTagByAttributeName

TagRepository tagRepository = browserPage.getTagRepository();

//to find one tag by attribute name
AbstractHtml tagByAttributeName = tagRepository.findOneTagByAttributeName("data-dialog");

				

TagRepository.findTagsByAttribute

TagRepository tagRepository = browserPage.getTagRepository();


//any attribute instance in the ui to find all tags consumed by this attribute instance			
AbstractAttribute attributeInTheUi;				
Collection<AbstractHtml> tagsByAttributeInstance = tagRepository.findOneTagByAttribute(attributeInTheUi);

//to find all tags consumed by attribute name and value 
Collection<AbstractHtml> tagsByAttributeNameAndValue = tagRepository.findTagsByAttribute("data-shape", "rectangle");

				

TagRepository.findTagsByAttributeName

TagRepository tagRepository = browserPage.getTagRepository();

//to find all tags by attribute name
AbstractHtml tagsByAttributeName = tagRepository.findTagsByAttributeName("data-shape");

				

To upsert/delete wffObjects on tags

These methods are valid only if the applicable tag is available in the ui so it's useful only for real time updates.

The main advantage of using this feature is the JavaScript object set on the tags will be in memory only in the life cycle of that particular tag. So when the relevant tag is removed from the browser page, the memory consumed by wffObjects property of the tag will also be released. Therefore, we don't have to manually care about the memory of JavaScript objects in the browser.

TagRepository.upsert

This method inserts (if not exists) or updates (if exists) the given WffBMObject or WffBMArray in the wffObjects property of a tag, eg:-

TagRepository tagRepository = browserPage.getTagRepository();

//any tag instance available in the ui
//suppose it has id as middleDivId
AbstractHtml tagInTheUi;

WffBMObject bmObject = new WffBMObject();
bmObject.put("bmkey1", BMValueType.STRING, "Success");
tagRepository.upsert(tagInTheUi, "key1object", bmObject);

WffBMArray bmArray = new WffBMArray(BMValueType.STRING);
bmArray.add("first value");
tagRepository.upsert(tagInTheUi, "key2array", bmArray);

				

To consume the JavaObjects/Arrays set from the server at client side. Suppose, The id of tagInTheUi in the UI is middleDivId then the following code may be used to get the values set from the server.


var middleDiv = document.getElementById('middleDivId');
var wffObjects = middleDiv.wffObjects;
var obj1 = wffObjects.key1object;
var ary2 = wffObjects.key2array;

//prints Success
console.log(obj1.bmkey1);

//prints first value
console.log(ary2[0]);

TagRepository.delete

To delete an entry from the wffObjects property of the tag

TagRepository tagRepository = browserPage.getTagRepository();
tagRepository.delete(tagInTheUi, "key1object");
				

These are some additional methods

TagRepository.findTagsByTagName

TagRepository.findOneTagByTagName

TagRepository.findAttributesByTagName

TagRepository.executeJs

Executes the given JavaScript in the client browser page.

TagRepository.execute(BrowserPageAction)

Performs some predefined JavaScript browser actions in the client browser page.

Some examples of static methods in TagRepository

It doesn't cover usages of all static methods.