Element and Widgets as child elements
treblereel May 15, 2017 1:38 PMHi all, maybe someone has some ideas on how to fix my issue. In general, from my point of view, the problem is that initWidget isn't called, so (GWTMaterialDesign) MaterialButton and MaterialDropDown aren't initialised. In case of div.add(btn) and div.add(mdd) all worked as expected, but i need to work with Composite as a parent element for these widgets. Thanks for any help
ps: For solution, i'll buy you a beer at the next GWTCon
code>
MaterialButton btn = new MaterialButton();
btn.setActivates("qwerty");
btn.setText("MaterialDropDown");
btn.setIconType(IconType.MERGE_TYPE);
MaterialDropDown mdd = new MaterialDropDown();
mdd.setActivator("qwerty");
MaterialLabel l1 = new MaterialLabel();
l1.setText("L1");
mdd.add(l1);
// it doesn't work
div.getElement().appendChild(btn.getElement());
div.getElement().appendChild(mdd.getElement());
//it works
// div.add(btn);
// div.add(mdd);
ps: little update, i have found out that my example works if I am adding HomePage directly to RootPanel (it's commented) but i have difficulties when i use navigation. So what are the differences between creating HomePage instance with injection and a navigation-created HomePage ?
@EntryPoint
@Templated("#body")
public class HelloWorldClient {
@Inject
@DataField
private MaterialPanel content;
@Inject
Logger logger;
@Inject
private Navigation navigation;
@PostConstruct
private void init() {
content.add(navigation.getContentPanel());
RootPanel.get().add(content);
// RootPanel.get().add(homePage);
}
@ApplicationScoped
@Templated("#root")
@Page(path = "home", role = DefaultPage.class)
public class HomePage extends Composite{
@Inject
@DataField("container")
MaterialRow div;
@Inject
GWTMaterialInitializationContainer gWTMaterialInitializationContainer;
@PostConstruct
public void init() {
MaterialButton btn = new MaterialButton();
btn.setActivates("qwerty");
btn.setText("MaterialDropDown");
btn.setIconType(IconType.MERGE_TYPE);
MaterialDropDown mdd = new MaterialDropDown();
mdd.setActivator("qwerty");
MaterialLabel l1 = new MaterialLabel();
l1.setText("L1");
mdd.add(l1);
getElement().appendChild(btn.getElement());
getElement().appendChild(mdd.getElement());
}
}