Skip to content

Instantly share code, notes, and snippets.

@webfirmframework
Last active October 2, 2019 02:43
Show Gist options
  • Save webfirmframework/6608fa82ac1a8ebf1c81a336fc8dccba to your computer and use it in GitHub Desktop.
Save webfirmframework/6608fa82ac1a8ebf1c81a336fc8dccba to your computer and use it in GitHub Desktop.
Example of getSharedData and setSharedData methods on a tag
Hello World
Hello World
import com.webfirmframework.wffweb.tag.html.Body;
import com.webfirmframework.wffweb.tag.html.Html;
import com.webfirmframework.wffweb.tag.html.TitleTag;
import com.webfirmframework.wffweb.tag.html.attribute.global.Id;
import com.webfirmframework.wffweb.tag.html.metainfo.Head;
import com.webfirmframework.wffweb.tag.html.stylesandsemantics.Div;
import com.webfirmframework.wffweb.tag.htmlwff.NoTag;
import com.webfirmframework.wffweb.tag.repository.TagRepository;
public class SharedDataOnTagUsage {
public static void main(String[] args) {
//use latest version to use this coding style
Html rootTag = new Html(null).give(html -> {
new Head(html).give(head -> {
new TitleTag(head).give(title -> {
new NoTag(title, "some title");
});
});
new Body(html, new Id("one")).give(body -> {
new Div(body);
});
});
Body body = TagRepository.findOneTagAssignableToTag(Body.class, rootTag);
//setting a shared data on body object
Object sharedData = "Hello World";
body.setSharedData(sharedData);
//this shared data is accessible from html tag because they are common for the whole tag hierarchy.
Object sharedDataFromHtml = rootTag.getSharedData();
//both print "Hello World"
System.out.println(sharedData);
System.out.println(sharedDataFromHtml);
}
}
@webfirmframework
Copy link
Author

webfirmframework commented Jan 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment