How to use GWTP for a ListView (Widget)?
Asked Answered
S

1

0

I started to use GWTP for my project and I'm currently re-writing all my code to let it work with this library.

However, I struggle to understand how I use GWTP if I want e.g. a ListView with ListItemView items.

@Inject
public ToolsPresenter(PlaceManager placeManager, EventBus eventBus, MyView view, MyProxy proxy) {

    super(eventBus, view, proxy, AdminToolPresenter.SLOT_AdminToolMainContent);

    this.placeManager = placeManager;

    ToolListView toolListView = new ToolListView(...)
    ToolListPresenter toolListPresenter = new ToolListPresenter(....);

    this.setInSlot(SLOT_ToolList, toolListPresenter);
}

What I want is to place my ListView inside a slot. I am very certain that I can't do what is shown up there but I just don't get how I use just simple Widgets with GWTP.

Or am I doing this completely wrong and I should just extend a Composite for ListView and not use GWTP stuff here at all?

Sectionalism answered 1/3, 2016 at 17:34 Comment(0)
W
1

There is a lot of information missing from your question so this is a difficult one to answer.

Assumption 1 - Your GWTP artifacts (ToolListView, ToolListPresenter, ToolListView.ui.xml, and ToolListModule) are setup correctly and ToolListModule is installed in a parent module.

Assumption 2 - You are using GWTP version 1.5+ which has typed slots.

You should not be instantiating your ToolListView or ToolListPresenter.

Simply add:

@Inject ToolListPresenter toolListPresenter;

If you are trying to call the setInSlot method then

  1. Make sure ToolListPresenter is a PresenterWidget
  2. Make sure your slot is not a NestedSlot.

Finally try moving the call to setInSlot outside of your constructor and into the overridden onBind() method.

Wrung answered 2/3, 2016 at 20:4 Comment(14)
Okay, I think I understand! But what is with a ListViewItem e.g.? If I have many items that I want to add.. do I still use GWTP Presenter and View? I don't think each list item would have a slot, right? Unfortunately I can't any good examples or code where something like this is done. I only find code with navigation examples but nothing where I can see how "normal" widgets are treated :/Sectionalism
@displayname I haven't worked with ListView or ListViewItems before. I imagine that your ToolListView.ui.xml uses a ListView as its container widget. Are you not able to add ListViewItems within the container? This sounds like standard GWT UiBinder stuff here, if it's a normal widget you can just add them to your UiBinder.Wrung
Well no, I am writing my own sort of ListView Widget with GWT Material Design. My problem is that I don't understand why I use for widget which are not associated with a place ^^Sectionalism
Sounds like you might be looking to use a PresenterWidgetWrung
I am actually trying to do that but it's not working. :/ This is some different scenario but it should work the same way for this model as for my list view in the end I guess.Sectionalism
Depending on your slot type, you can add multiple items to the slot. This could be helpful with your ListViewItems. If ListView has a slot of type Slot, then you should be able to add multiple ListViewItems to this. Use addToSlot instead of setInSlot for this case.Wrung
Hi! Sorry for the late response, didn't had time to work on this project for the last few days.. I'm still having problems to understand how GWTP works essentially. I understand that a slot is a "placeholder" but does that mean that each list-item has its own slot? If so: why? If I just want to write a simple widget that represents a list-item which has some functionality like "edit" or "delete" why would I not just simply extend a Composite instead? I also don't understand how I can create new list items at runtime. GWTP/GIN injects one presenter and one view, but how can I have more?Sectionalism
I think my problem is mainly because each ListItem has a different model e.g. itemName etc. normally I'd just write prestenter = new MyPresenter(); and view = presenter.getView() but this is pointless since installing a module means I can get everything I need basically from the constructor with @Inject. But I can't get my head around the "multiple instances" problem I guess ..Sectionalism
@displayname - Re - why wouldn't you just extend composite... You can do that and that was my original expectation. Then at runtime you can call the appropriate method in the ListView api to add a new ListViewItem. For example you could have a click handler that adds ListViewItems. If you do not understand how to do that, then you need to review GWT and UiBinder, that really isn't a GWTP topic.Wrung
Hm, I am not so sure about this. But after thinking about this the past few hours I think the answer lies in "When do I need a GWTP lifecycle for my Presenter/View". Could that be a way to see it?Sectionalism
Re: does each list-item need to have its own slot? No. You can use a slot type that supports multiple, e.g. Slot or OrderedSlot, then call addToSlot. That's if you were going to do this the GWTP way, which as I explain in my last comment you do not have toWrung
Okay, I think I'm starting to understand :) It's really hard for me to get into this. I don't know. A lot of "magic" happening from my point of view here at the moment ^^ but I am using PresenterWidget already so I guess your suggestion is correct!Sectionalism
Here is a real world example for you. In an application that I am currently working on, I created a NestedPresenter for filling out an application (ApplicationPresenter). The ApplicationPresenter has a slot for application forms because there are several pages in this application. The application forms were created as presenter widgets and get added to the ApplicationPresenter's slot. Some of the simple form elements needed to be custom so those were created as custom widgets (not via GWTP) and added directly on the UiBinder. I hope this helps.Wrung
Alright, thanks for that additional info! Seem like I was overthinking a little but and trying to "over"-GWTP everything :DSectionalism

© 2022 - 2024 — McMap. All rights reserved.