WFF

wffweb - Java framework to develop web applications

View sample projects on GitHub

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.9. 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.exists
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 or updates (if not 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");
				

Next >>

Subscribe on youtube for technical videos