Vaadin 23 open new browser tab with url on Button click - vaadin

I may open a browser new tab with Anchor component configured with target=_blank. How to do the same in Vaadin23 with the Button component inside the ClickListener code?

You can do it using UI.getCurrent().getPage().open(String url), which opens the URL in a new tab by default.
Button button = new Button("Click Me", e -> {
UI.getCurrent().getPage().open("https://stackoverflow.com");
});
add(button);

Related

How to get left click to work on column visibility example using the Vaadin Flow Grid example

On the Column Visibility example on https://vaadin.com/docs/latest/ds/components/grid/#column-visibility the code shows a class ColumnToggleContextMenu which isn't part of the Vaadin API however it seems to somehow adjust how the button is hooked so that it can be left clicked rather than the default right click for a context menu. With that in mind the code below will only show the context menu on a right click, I cannot get it to work like the example code. My code is:
Button showHideColumnsButton = new Button("Show/Hide Columns");
showHideColumnsButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
ContextMenu contextMenu = new ContextMenu(showHideColumnsButton);
for(Grid.Column column : grid.getColumns()) {
contextMenu.addItem(getColumnName(column), e -> showHideColumn(column));
}
I'm considering using a MenuBar instead to see if that will work but I'd prefer to figure out how to use a Button if possible as that seems more appropriate (mainly because it allows the checkbox to show if a column is visible or hidden).
In order to make the context menu to open on left click use setOpenOnClick(true):
Button showHideColumnsButton = new Button("Show/Hide Columns");
showHideColumnsButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
ContextMenu contextMenu = new ContextMenu(showHideColumnsButton);
contextMenu.setOpenOnClick(true)
for(Grid.Column column : grid.getColumns()) {
contextMenu.addItem(getColumnName(column), e -> showHideColumn(column));
}

TYPO3 Preview URL Configuration for all buttons

I need to add a query string to the preview URL on TYPO3.
There are 4 possible ways to view the page from TYPO3 BE
Edit the page and choose "Save and view page" from the "Save" button dropdown
Right click on page in page tree
Click "document with eye" icon "View webpage" button (under Columns/Languages dropdown)
Click "eye" icon "View webpage" under default when Languages is selected
Using this configuration:
https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Feature-66370-AddFlexiblePreviewUrlConfiguration.html
I am able to edit the "Save and view page" option to add a query string like so:
TCEMAIN.preview {
pages {
additionalGetParameters {
newQueryString = tx_languageversion2
}
}
}
Is there equivalent code to edit the other view page buttons listed above?
EDIT: Alternatively, is there a way to hide the View button next to the Edit button? That way the only way to preview is using the "Save and view page" option
Thanks

How do I preserve a hamburger menu when linking from a contentpage?

I've been using the MasterPageDetail approach in creating a hamburger menu for my Xamarin Forms app. The menu itself works fine as taken from the Xamarin documentation https://developer.xamarin.com/samples/xamarin-forms/Navigation/MasterDetailPage/. What I noticed was that if I create a simple link to a page in one of my views, the hamburger menu and it's icon are replaced with a back button.
What I would like to know is how to create a link in a content page that will preseve my hamburger menu instead of showing a back button. Any link you click from the MasterPage takes you to the corrosponding view but you can still see the hamburger menu, if you click a link within one of the pages however you are taken to the page but with a back button instead. It's causing a very confusing navigational experience for my users.
The following code demonstrates how the manu is created in the hamburger menu just now.
public partial class MasterPage : ContentPage
{
public ListView ListView { get { return listView; } }
public MasterPage()
{
InitializeComponent();
//var master = new MasterPage();
var masterPageItems = new List<MasterPageItem>();
masterPageItems.Add(new MasterPageItem
{
Title = "Dashboard",
IconSource = "dashboard-icon-24.png",
TargetType = typeof(Dashboard)
});
listView.ItemsSource = masterPageItems;
}
So that works perfectly, you can navigate around and the hamburger menu is there all the time.
Within my view called 'dashboard' I added some link to hope to those same pages that are in my hamburger menu, I did so int he following way:
<Button Text="Information" Clicked="informationClick" />
The code for this is as follows:
private void informationClick(object sender, EventArgs e)
{
Navigation.PushAsync(new Information());
}
When you click on this link however you lose the hambuger menu and it's repalced with the back button instead. I want to preserve the hamburger menu, does anyone know how I can do this from my content page?
You must replace the "Detail" property of your MasterDetail page with a new NavigationPage containing the page you are linking.
Something like that:
(App.Current.MainPage as MasterDetailPage).Detail = new NavigationPage(new ContactsPage());
This is not really clean but it makes the idea.

How to switch to a new tab

I currently have a TabSet of tabs.
List<Tab> tabList = new ArrayList<Tab>();
tabList.add(createTab("tab1", "Tab1", new TabPanel()));
tabList.add(createTab("tab2", "Tab2", new TabPanel()));
TabSet tabSet = new TabSet();
tabSet.setTabs(tabList.toArray(new Tab[tabList.size()]));
I want to be able to add a double click handler in a grid, by double clicking something, it will switch to one of the tabs Im not currently on. How do I achieve this?
In your click handler call selectTab() on the tabSet. Just pass in either the zero based index of the tab, the string id of the tab, or the particular Tab instance.

MVC page refresh on browser back button

I have a button that is visible only for certain item's page. Clicking the button leads to the item's detail page. On hitting the browser's back button, the item page is rendered without the button. And, if I hit refresh then the button appears. How do I render the button as well without refreshing.
Thanks!
just in case anyone is looking, for the button to be visible some other .cshtml page was handling it based on some event response, using a script that removed the "invisible" from its css. So, on hitting the browser back button the event would not be called and hence the button was still invisible. I needed to make the button visible. The only workaround I found was this -- a hidden check included in the target page after hitting the browser back button.
<script type="text/javascript">
onload = function () {
var e = document.getElementById("reloaded");
if (e.value == "no") e.value = "yes";
else { e.value = "no"; location.reload(); }
}
</script>

Resources