Behold, my first GWT app's EntryPoint impl:
public class MyModule implements EntryPoint {
private SimplePanel mainPanel = new SimplePanel();
#Override
public void onModuleLoad() {
// Extract all root-level dependencies from the injector.
// Using Gin here.
EventBus eventBus = injector.getEventBus();
PlaceController placeController = injector.getPlaceController();
SignInEventListener signInEventListener = injector.getSignInEventListener();
PlaceHistoryMapper placeHistoryMapper = injector.getPlaceHistoryMapper();
// Start the activity manager.
activityManager = new ActivityManager(signInEventListener, eventBus);
activityManager.setDisplay(mainPanel);
// Start the place history mapper.
placeHistoryHandler = new PlaceHistoryHandler(placeHistoryMapper);
placeHistoryHandler.register(placeController, eventBus, startingPlace);
// Add the main panel to the RootPanel.
RootPanel.get().add(mainPanel);
// Navigate to the place represented by the current URL, otherwise the startingPlace.
placeHistoryHandler.handleCurrentHistory();
}
}
Several questions:
My call to the placeHistoryHandler's register(...) method is showing up as being deprecated. Why is it deprecated and what should it be (as of GWT 2.5.1)?
Is there one RootPanel per module/EntryPoint or is there only one RootPanel per GWT app (regardless of how many modules you have)?
What is the connection/relation between the mainPanel (above) that itself has been added to the RootPanel, and the AcceptsOneWidget that gets passed into each AbstractActivity#start method?
Look here: GWT deprecated: PlaceHistoryHandler.register?
The RootPanel is most likely the <body> element. So there is exactly one.
In most cases you will add one AcceptsOneWidget to the RootPanel. Your Activity has to create its view and set it into the AcceptsOneWidget passed to the start()
Take a look at the Activity and Places section of gwtproject.org
1) See Christian Kuetbach answer
2) In your GWT app you should have a MyModule.html file. This file has been define as the welcome file in your web.xml file. Inside this file you will see that is included the javascript version of your application MyModule.nocache.js (after gwt compilation). The RootPanel as said by Christian is the of your html page. Be careful you can use RootLayoutPanel or RootPanel depending if you want to use Layout Panels or not.
3) When using Activities and Places, the Activity Manager is given a widget container. Inside this widget container the framework will put the view of the new activity when changing place. That is the meaning of
activityManager.setDisplay(mainPanel);
Your are saying that when you go from one place to another, the activity view that corresponds to that place should be put inside mainPanel.
Related
The ZK setLabel() function of Button widget does not work; when the code runs to the line like foobutton.setLabel(mystring), the button disappears from the browser.
In the eclipse IDE, if I hover on the setLabel() function, the IDE shows this message:
If label is changed, the whole component is invalidate.Thus, you want to smart-update, you have to override this method.
Using ZK 8.5.0
Inside the controller class, I declare:
#Wire
Button delSelectedMonitor;
Inside the controller, I implement a class which implements EventListener:
public class onClickHolderEditMode implements EventListener{
public void onEvent(Event event) throws Exception {
clickedDivEditMode = (Div) event.getTarget();
clickedDivIdEditMode = clickedDivEditMode.getId().split(myUtil.monitorholderString)[1];
String curName = getCamNameById(clickedDivIdEditMode);
delSelectedMonitor.setLabel("DELETE:"+clickedDivIdEditMode+","+curName);
}
}
event binding:
tmpdiv.addEventListener("onClick", new onClickHolderEditMode());
My expectation is that when someone clicks the tmpdiv, the button delSelectedMonitor will change its label according to the property of tmpdiv. However as I say previously, the button is just disappearing.
https://www.zkoss.org/wiki/ZK_Client-side_Reference/General_Control/Widget_Customization
I have tried the section "Specify Your Own Widget Class" at the above website link, but the browser will be pending.
Please help, thank you.
I would prefer a different approach.
Why not use a
<button label="#load(vm.xyz)" ... />
(I wrote using MVVM pattern) and modify variable xyz in clicking action?
Check out http://books.zkoss.org/zk-mvvm-book/8.0/syntax/load.html for implementing guide.
I am a little confused about tags. I know from wicket 1.5 there was a change of head render strategy from parent->child to child->parent.
Now I use wicket 6.9 and I have simple menu panel which I want to use some jquery effects.
I want to use the same jquery (for example for google) file for whole application.
I cannot use jquery link only in main page, because in while rendering menu panel there is " $(document).ready" and it is not recognized. Reading some forum i found opinion that panel should contain jquery itselft - it is reasonable, because it can be reusable independently.
So now my page consist:
<head>
...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
...
</head>
And my menu panel consist the same. As a result in rendered html I load jquery.js twice.
How should I resolve it? I want to load it only once. I know i can back to old strategy and do application.getResourcesSettings().setHeaderItemComparator() but as i read it is not the best solution.
I can found such class like PriorityHeaderItem in wicket, but documentation is very poor for wicket and did not found any example of use it.
Best regards
Since wicket 1.6 jQuery is now the javascript library used by the framework. So you may see jQuery twice because of the one you included and the wicket version? If you want to override the jQuery version you can create a Resource Reference and then set it in your init method of the Application class.
First you need the resource reference file and put the js file in same package structure.
public final class JQueryResourceReference extends JavaScriptResourceReference {
private static final JQueryResourceReference INSTANCE = new JQueryResourceReference();
private JQueryResourceReference() {
super(JQueryResourceReference.class, "jquery.js");
}
public static JQueryResourceReference get() {
return INSTANCE;
}
}
Then in the application init method do this:
public MyApplication extends AuthenticatedWebApplication {
#Override
protected void init() {
super.init();
getJavaScriptLibrarySettings().setJQueryReference(JQueryResourceReference.get());
....
}
....
}
I have implemented a simple GWT app that uses 1 Place and 1 Activity (which I have implemented as a Presenter which extends an AbstractActivity and which contains a Composite "view" subclass). The 1 and only UI object in the view is a GWT-Bootstrap NavBar that I want presented at the very top of my "home page".
I'm running the app locally from inside Eclipse and am not getting any compiler or runtime errors. When I go to the URL that the Development Mode console points me to, I get a slight pause in the browser (I assume this is the browser "downloading" the JavaScript) and then I see a blank white screen (instead of my NavBar). The window title is correct (I set this in the module's HTML page) and when I view source I see the same HTML source, so I know that the app's JavaScript is getting to the browser properly. It's just not rendering the NavBar.
I have sprinkled System.out.println() statements throughout onModuleLoad(), my default ActivityManager, ActivityMapper, PlaceHistoryMapper, presenter and view Composite, and all these sysout statements print in the dev console; telling me that I have wired everything together correctly, and that at runtime when the PlaceHistoryHandler#handleCurrentHistory method is called (from inside onModuleLoad), I should be seeing my NavBar.
The only possibilities I can think of are:
I have configured gwt-bootstrap incorrectly; or
I'm not using UiBinder correctly
Something else is wrong with how I am using Activities and Places, or perhaps how I am attaching the UI to RootLayoutPanel inside onModuleLoad().
As for gwt-bootstrap:
I placed the JAR on my project's classpath (I know this because when I include a new UiField of type NavBar inside my widget/view, I don't get any compiler errors)
I added <inherits name="com.github.gwtbootstrap.Bootstrap"/> to my GWT module XML
So if there's anything else I have to configure, please let me know!
As for the UiBinder stuff, here's my widget/view:
public class WebRootDisplay extends BaseDisplay {
private static WebRootDisplayUiBinder uiBinder = GWT
.create(WebRootDisplayUiBinder.class);
interface WebRootDisplayUiBinder extends UiBinder<Widget, WebRootDisplay> {
}
#UiField
Navbar navBar;
public WebRootDisplay(EventBus eventBus) {
super(eventBus);
System.out.println("I get this printing to the console at runtime.");
initWidget(uiBinder.createAndBindUi(this));
System.out.println("...and this too!");
}
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<b:Navbar ui:field="navBar">
<b:Nav>
<b:NavLink href="http://www.google.com">
Home
</b:NavLink>
</b:Nav>
</b:Navbar>
</g:HTMLPanel>
</ui:UiBinder>
One thing I noticed is that I've got my NavBar inside an HTMLPanel in the UiBinder XML. I did this because I used the Google-Eclipse plugin to generate a new UiBinder for me (which autogenerated both the Composite (which I then modified to extend BaseDisplay, which itself extends Composite) as well as the UiBinder snippet. I figured GWT wants me to put all the UI fields inside this HTMLPanel...(?)
If I'm missing anything here please let me know. I'm not instantiating the NavBar field because I believe that's what createAndBindUi does for me.
If both my gwt-bootstrap config and my use of UiBinder looks correct, then something else is obviously wrong and I will have to post more code. I just wanted to hold off on that initially before these first two items were ruled out. Thanks in advance!
Update
Here is onModuleLoad:
public void onModuleLoad() {
// Some homegrown DI stuff. I have verified that the injector works properly.
ApplicationScope appScope = new ApplicationScope();
setInjector(new ApplicationInjector(appScope,
InjectorProvider.newMasterProvider()));
// Add the sole composite child to the RootLayoutPanel.
// I have verified that injectWebRootDisplay returns a fully configured
// WebRootDisplay instance.
RootLayoutPanel.get().add(injector.injectWebRootDisplay());
historyHandler.register(placeController, eventBus, defaultPlace);
historyHandler.handleCurrentHistory();
}
Could you paste the onModuleLoad() part of your code please?
If you don't got any Exception and error message, I think you should check that you add the view properly to the RootPanel, or when you run the app you should check that the view is there in a div in the HTML and just unvisible or something similar.
The UiBinder part looks fine in a first look.
EDIT:
This onModuleLoad() doesn't said too much to me, but you could try something.
I always use the RootLayoutPanel.get() method in the following way:
RootLayoutPanel.get("someDivId").add(injector.injectWebRootDisplay());
So I always add a div or table to the placeholder HTML with a id, so you can refer to that div when you get the RootPanel. I'm not confident about this is necessary, but I saw this at the first time, and it's working properly.
If you have question or problem, please let me know. :)
Well, I've tried a local example looking exactly like yours code, and I think that problem is not in UI binder. The code you provided so far, is correct, so it most likely that the error is somewhere else.
The biggest suspect is the BaseDisplay class. As far as I can see, this class is not from GWT or gwt-bootstrap. You can really quickly check it, by changing WebRootDisplay class, so it extends classic GWT Composite class instead of BaseDisplay (and disabling all mvp stuff for while). If it works, you have a proof that the problem is caused by 'BaseDisplay'
Since I don't have the full code, I can only assume that WebRootDisplay is used also for displaying the views, and most likely the error is that when view is added to that class, previously added widget (in your case it is a NavBar which you add in constructor of WebRootDisplay) is removed. Most likely the problem should be in methods setWidget and initWidget
In my experience with GWT Activities and Places, a common culprit of a blank white page is failing to register the Place's Tokenizer with the PlaceHistoryMapper as so:
/**
* PlaceHistoryMapper interface is used to attach all places which the
* PlaceHistoryHandler should be aware of. This is done via the #WithTokenizers
* annotation or by extending PlaceHistoryMapperWithFactory and creating a
* separate TokenizerFactory.
*/
#WithTokenizers({
MyPlace.Tokenizer.class,
SomeOtherPlace.Tokenizer.class})
public interface AppPlaceHistoryMapper extends PlaceHistoryMapper {}
See https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces#PlaceHistoryMapper
Another cause for a white page (particularly when using RootLayoutPanel.get() with a single place is failing to map the place correctly in the ActivityMapper:
/**
* AppActivityMapper associates each Place with its corresponding
* {#link Activity}
*
* #param clientFactory
* Factory to be passed to activities
*/
public class AppActivityMapper implements ActivityMapper {
private ClientFactory clientFactory;
public AppActivityMapper(ClientFactory clientFactory) {
super();
this.clientFactory = clientFactory;
}
#Override
public Activity getActivity(Place place) {
if (place instanceof MyPlace)
return new MyActivity((MyPlace) place, clientFactory);
else if (place instanceof SomeOtherPlace)
return new SomeOtherActivity((SomeOtherPlace) place, clientFactory);
return null; // If your return null with single place bound to RootLayoutPanel
// you may get a blank white page
}
}
See https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces#ActivityMapper
Without a more complete code sample it is impossible to determine exactly what is happening, but the two causes outlined above are common oversights which may help anyone who comes across this thread.
Instead of System.println use GWT.log messages. Then open the Javascript console (of Firebug or Chrome) and see where your code ends up. GWT.log will print out in the browser console, so you can see what the compiled JS code does.
Also, if you compile with the Pretty mode, you'll see the generated Javascript code in the browser and be able to step through and see what is being called (or not).
I put a toolbar on the top of my TrimmedWindow in my application. I have a handler which has to check whether a check button is pressed on this menu bar or not.
I tried putting EMenuService in my execute() method of the handler but it has no useful methods. If I debug into my application I can see my menu in the EMenuService object however.
How can I get my menu from the Eclipse context?
Without code it's hard to help you.
But the basic idea for your handler is the following :
public class BrokerHandler {
#Inject
// the services you need
#Execute
public void execute(IEclipseContext context, #Named(IServiceConstants.ACTIVE_SHELL) Shell shell)
throws InvocationTargetException, InterruptedException {
// do some stuff
}
}
Then, in your application.e4xmi you need to create a Window>Trimmed Window>Trim Bars>Window Trim>Toolbar>Handled Tool Item wich points to your Commands>Command that is binded to your Handlers>Handler pointing to your java class with a method annotated #Execute as described above.
Then each execution of the #Execute method means the user has pressed the toolbar button.
You can pass messages to other parts of your app with the event broker service, or store some of your own stuff in the IEclipseContext.
You can have a look here: http://xseignard.github.com/demoCamp2012/prez/#1
Hope this helps, but your question is too blurry.
I have this piece of code :
public class Profile extends Container{
public Profile(String value) {
Container profilo_1 =new Container();
Container profilo_2 =new Container();
// (1) THIS ADD A BUTTON TO THE MAIN CLASS
this.createButton().setLabel("Modifica Profilo");
// (2) NOW I NEED TO ADD A BUTTON INTO THE INSTANCE OF profilo_2 BUT IT FAILS
profilo_2.add(this.createButton());
this.add(profilo_1);
this.add(profilo_2);
}
}
the point (2) fails, because it said that im about to adding a child to this container, but it is owner already by a container...
In fact, if i do this :
ILabel label=new ILabel();
profilo_2.add(label);
it said to me that ILabel() is abract and cannot be instantiated!
How can I fix it? Cheers to everybody :)
Guessing wildly, since this depends on your code... Try this (moreless what Piotr said)
profilo_2.add(profilo_2.createButton());
Try changing to
Button button2 = this.createButton();
button2.setLabel("EDIT");
profilo_2.add(button2);
By the way this has nothing to do with abstract classes, from what I see
EDIT: Though you say that #1 "adds a button to the main class", so does that mean that createButton() does this.add(button) ? If so then you should probably change that function so that isn't done every time you create a button.
The problem is probably that when you create a button with "this.createButton", that button has its parent set to "this" (in this context), and when you try to add it to profilo_2, it throws an error. Instead you should createButton on profilo_2 directly, then the parent will be the correct one (and perhaps you won´t have to add() it either?)
Probably, setLabel() returns something which cannot be passed to Container::add(..). Please provide your code for Container