Creating a hyperlink / HTML / "Please Suggest" in a loop in GWT?

So my question is this:

Let's say I show the data in flextable after retrieving from the database, doing it the usual way using loops.

Now, in the entire first column, the text should be accessible for clickability, that is, I should be able to add Click Handler to First Column values ​​(since I have to load another table after clicking on any of the first columns of the column text.)

Question . How can I generate such hyperlink tags in a loop? The problem arises when I try to do this, since I don’t know how to name them how the loop works and use the same concept, adding ClickHandlers.

Should I use something other than Hyperlink for this task. Please explain how?

I really appreciate the help with this since I am a very new GWT encoder.

- Chiraiu

+3
source share
3 answers

Using a hyperlink may not be the best way to do something like this, because you should not use a ClickHandler with a hyperlink. The hyperlink sets the HistoryToken, and you must respond to a change in History.
I would use a shortcut and possibly use it as a regular link if you want to have the same look. (I will use the shortcut in the following example, but you can change it to a hyperlink if you want.)

, Label. ID, . , FlexTable. ClickHandler, id , FlexTable.

public class FlexTableLabel extends Label implements ClickHandler {
    int id=0;  
    public FlexTableLabel(String text, int id) {
        this.id=id;
        this.setText=text;
        this.addCickHandler(this);
    }

    public void onClick(ClickEvent event) {
        //sends the id to the server, of course you need to replace it with your 
        //service
        yourService.getNewFlexTable(this.id);
    }     
 }

( , ArrayList . ArrayList id):

for(int i=0; i<result.size;i++) {
    FlexTable.setWidget(i,0, new FlexTableLabel(result.get(i).text, result.get(i).id);
}

, - , - , .

Chirayu:

- . Singleton Pattern, . :

public static YourPanel extends Panel {
    private static YourPanel instance=null;

    public static YourPanel getInstance() {
        if(instance==null) {
            instance=new YourPanel();
        }
        return instance;
    }
}

EntryPointClass - :

public class YourEntryClass extends EntryPoint {
    public void onModuleLoad() {
        RootPanel.get().add(YourPanel.getInstance());
    }
}

YourPanel.getInstance() onSuccess() , :

yourService.getNewFlexTable(this.id, new AsyncCallback<ArrayList<String>>() {
    public void onSuccess(ArrayList<String> result) {
    For(int i=0;i<result.size;i++) {
            YourPanel.getInstance().add(result.get(i);
        } 
    }
});

, . , .



+2

Anchor, , Anchor(java.lang.String text):

. anchor href javascript:;; , .

, ol '<a>, , ClickHandler :

Anchor anchor = new Anchor("Click me!"); // At this point clicking it won't do a thing
anchor.addClickHandler(new ClickHandler() {
    @Override
    public void onClick (ClickEvent event){
        // Do something cool here
    }
});

// Insert the anchor into the table

: , ClickHandler , Anchor , Anchor, (, ) - , .

+2

... , .

, @, , , ()... , , , , EntryPoint , " ", ...

then in another class FlexTablelabel, in the part where I add services, i.e. onClickpart ... how should I add material to my panel that are defined in the class EntryPoint?

AT,

public void onClick(ClickEvent event) {

        //sends the id to the server, of course you need to replace it with your 
        //service
        yourService.getNewFlexTable(this.id);
    }     
}

How to access panels, methods, etc. out of class EntryPoint. I know what I can do EntrypointClass EC = new EntrypointClass(), but it does not work as intended.

0
source

Source: https://habr.com/ru/post/1756972/


All Articles