Is it possible link component to provide validation before opening the URL?
If so how can it be done?
example in a button in the button click even we can provide validation, in a link how could this be done before opening the page?
Is it possible link component to provide validation before opening the URL?
If so how can it be done?
example in a button in the button click even we can provide validation, in a link how could this be done before opening the page?
The easist way would be just use Button with button link style to mimic a link, then in the click listenr to open the url. something like
Button linkButton = new Button("Vaadin");
linkButton.setStyleName(BaseTheme.BUTTON_LINK);
linkButton.addClickListner(new ClickListener(){
public void buttonClick(ClickEvent event){
/*some validation here*/
Page.getCurrent().setLocation("https://vaadin.com/home");
}
})
However the URL is generated as new StreamResource(getSource((Document) response.getData()), document.getTitle())
So how will it work? I want it to be opened in a different broswer rather than the same one?
private StreamResource.StreamSource getSource(final Document document) {
return new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
return document.getInputStream();
}
};
}
maybe you can try this, though Page.open(resource, xx, xx) is deprecated
linkButton.addClickListener(new ClickListener()
{
@Override
public void buttonClick(ClickEvent event)
{
StreamResource resource =
new StreamResource(getSource(), “filename”);
Page.getCurrent().open(resource, “filename”, false);
}
});
Also have a look at the BrowserWindowOpener Extension for Button components. It uses a dynamically created Streamresource. There should be enough examples on the web.