-
-
Save meriouma/9377380d942df849ae50 to your computer and use it in GitHub Desktop.
The hard way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyViewImpl implements MyView, AttachEvent.Handler { | |
interface Binder extends UiBinder<Widget, MyViewImpl> {} | |
private final Widget widget; | |
@Inject | |
MyViewImpl(Binder binder) { | |
widget = binder.createAndBindUi(this); | |
widget.addAttachHandler(this); | |
} | |
@Override | |
public void onAttachOrDetach(AttachEvent event) { | |
if (event.isAttached()) { | |
Document.get().setTitle("This is the new title of the page"); | |
updateMetaTags(); | |
} | |
} | |
private void updateMetaTags() { | |
injectMetaProperty("description", "This is the description"); | |
injectMetaProperty("og:image", "http://placehold.it/350x150"); | |
// ... | |
} | |
private void injectMetaProperty(String property, String value) { | |
Document document = Document.get(); | |
MetaElement metaElement = document.createMetaElement(); | |
metaElement.setName(property); | |
metaElement.setContent(value); | |
document.getHead().insertFirst(metaElement); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment