Redirect Vaadin App - redirect

I am currently hosting my vaadin app on openshift. My main website redirects to the vaadin app when the login button is clicked. The first thing the user sees is the login page
I have 2 buttons on my website, a free trial button and a login button, and I have 2 different classes in my vaadin app, a login class and a free trial class.
How can I make the login button redirect to the login class of my vaadin app and the free trial button redirect to the free trial class of my vaadin app?
This is what it currently looks like:
#Theme("mytheme")
#Widgetset("com.example.myapp.MyAppWidgetset")
#PreserveOnRefresh
public class MyUI extends UI {
#WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
#VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
#Override
protected void init(VaadinRequest vaadinRequest) {
login();
}

You can use the Navigator as Chris M said, or you can try to implement an event driven architecture. I implemented a project like that using Vaadin too with Google Guava.
Here you can find some examples of how to use Google Guava if you are interested.
http://codingjunkie.net/guava-eventbus/
Below you can find some code fragments of my implementation:
// Using guava
final Button signin = new Button(
Lang.getMessage("login.signin"),
eventClick -> {BarsEventBus.post(new UserLoginRequestedEvent(
username.getValue(), password.getValue()));});
//Using Navigator, I also used spring here, so the registration view is a Spring View
final Button register = new Button(
Lang.getMessage("login.registration"),
clickEvent -> {getUI().getNavigator().navigateTo(ViewToken.REGISTRO);}
);
#UIScope
#SpringView(name = ViewToken.REGISTRO)
public class RegistrationView extends VerticalLayout implements View {...}
Please verify the code for the vaadin demo application. That code is having an example on how to handle it too. Find it here:
https://github.com/vaadin/dashboard-demo

You could pass in a parameter to your request and use a UI provider to serve the UI depending on this parameter.
See here.
Example:
public class DifferentFeaturesForDifferentClients extends UIProvider {
#Override
public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
if ("trial".equalsIgnoreCase(event.getRequest().getParameter("app-type"))) {
return TrialUI.class;
} else {
return LognUI.class;
}
}
}
web.xml:
<servlet>
<servlet-name>My Vaadin App</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<description>Vaadin UI</description>
<param-name>UIProvider</param-name>
<param-value>com.example.myexampleproject.DifferentFeaturesForDifferentClients</param-value>
</init-param>
</servlet>
And then in your main websites html code:
<form>
<input type="submit" name="app-type" value="Trial" formaction="/your/vaadin/url" formmethod="post">
<input type="submit" name="app-type" value="Login" formaction="/your/vaadin/url" formmethod="post">
<!-- Alternative using button tag (better for customization, but no IE < 9) -->
<button name="app-type" value="trial" type="submit">Trial</button>
<button name="app-type" value="login" type="submit">Login</button>
</form>

I now understand what you were truing to do. You can do this quite easily. You need to cast the VaadinRequest into a VaadinServletRequest. The reason it passes a VaadinRequest rather than an VaadinServletRequest is so you can deploy your application as a portlet too. In that case you would need to cast it to VaadinPortletRequest instead. Then you can use the serverName provided by the user.
#Override
protected void init(VaadinRequest vaadinRequest) {
VaadinServletRequest req = (VaadinServletRequest) vaadinRequest;
String serverName = req.getServerName();
if (serverName.equals("www.login.mywebsite.com"))
{
login();
}
else
{
trial();
}
}

Related

Navigate to page on start in .NET Maui app

Seems like a simple question, but I haven't been able to find a simple answer. Essentially I want to choose which page in the app to start on based on some stored state. I added a GoToAsync call in the AppShell constructor, but this didn't work--which makes sense because the AppShell hasn't been fully constructed yet.
I found this answer, but it feels like it kind of skirts around the issue:
Maui AppShell - Navigate on Open
Where is the best place to inject some code that will run once on startup and can successfully navigate a .NET Maui app to a chosen page?
After playing around with overrides, it seems like overriding Application.OnStart works! Shell.Current is set at this point and navigation works.
Here's additional code that allows for asynchronous initialization and uses a Loading Page until the initialization is complete:
using MyApp.Services;
using MyApp.UI;
namespace MyApp;
public partial class App : Application
{
ConfigurationProviderService m_configProvider;
public App(ConfigurationProviderService configProvider)
{
m_configProvider = configProvider;
InitializeComponent();
MainPage = new LoadingPage();
}
protected override void OnStart()
{
var task = InitAsync();
task.ContinueWith((task) =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
MainPage = new AppShell();
// Choose navigation depending on init
Shell.Current.GoToAsync(...);
});
});
base.OnStart();
}
private async Task InitAsync()
{
await m_configProvider.InitAsync();
}
}

How to redirect User to website specific landing page

I wanted to redirect user to default landing page based on the website access user has in liferay. I am using liferay DXP. I know how it can be done in liferay 6.2, but i don't have a idea how to override/extend DefaultLandingPageAction class in liferay 7.
Let me know if anybody has done this before.
Thanks!!
I assume that you are trying to redirect the user after login.
Have a look at this. Should do the trick.
Place the class into a bundle and adjust the logic.
#Component(
immediate = true,
property = {
"key=login.events.post"
},
service = LifecycleAction.class
)
public class LandingPageRouter implements LifecycleAction {
private static Log LOG = LogFactoryUtil.getLog(LandingPageRouter.class);
#Reference
private UserLocalService userLocalService;
#Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
//Do some magic
//build the path.
LastPath lastPath = new LastPath(StringPool.BLANK, path);
lifecycleEvent.getRequest().getSession().setAttribute(WebKeys.LAST_PATH, lastPath);
}
}
LastPath works as in DefaultLandingPageAction.

Where is good place to register Messenger responsible for showing Windows to ensure MVVM pattern Separation of Concerns and Testability not violated?

Scenario:
MainWindow has a Menu About which relates to AboutWindow.
About Meny is triggered by command:
<MenuItem Header="_About" Command="{Binding OpenAbout}"/>
OpenAbout is property like that:
private RelayCommand _openAbout;
public RelayCommand OpenAbout
{
get
{
return _openAbout ?? (_openAbout = new RelayCommand(() => Messenger.Default.Send(new NotificationMessage("ShowAboutView"))));
}
}
Notification message is registered in App.cs class as follows:
static App()
{
DispatcherHelper.Initialize();
}
public App()
{
RegisterMessenger();
}
public void RegisterMessenger()
{
Messenger.Default.Register<NotificationMessage>(this, ProcessShowAboutView);
}
private void ProcessShowAboutView(NotificationMessage message)
{
AboutWindow view = new AboutWindow();
view.Show();
}
I analysed another questions like that:
How to open a new window using MVVM Light Toolkit
WPF MVVM - How to Show a view from MainWindowViewModel upon Clicking on button
I like Messenger functionality but however I am not sure If above solution is a good one.
I would be thankful for any advise!
As depicted above, Registering messages is done in App Config.
I consider it not be a good place therefore I need to know what place would be better.
Another place to consider would be Locator
I personaly would register the messages in App.xaml.cs in the OnStartup method (WPF) and in the set up method of the unit test (dont forget to unregister everything in the tear down method).

wicket download link clear feedback panel

I have couple of drop downdowns and a download link button. Based on the user selection, i get the file to be downloaded. if the user did not make a selection I show an error on the feedback panel. if the user then makes a selection and clicks on download link it works fine, but the previous feedback message is still visible. How do I clear it.
onclick of the download link, i tried the following, but no use
FeedbackMessages me = Session.get().getFeedbackMessages();
me.clear();
Probably it is
Session.get().cleanupFeedbackMessages()
even it has been changed in Wicket 6.x
I've found this post and I think it is time to share the way for Wicket 6.x and for Wicket 7.x, because Session.get().cleanupFeedbackMessages() was deprecated already.
To do it for Wicket 6.x you have to implement additional filter for the feedback panel. Where to do it, it is your decision to decide.
Create a new FeedbackPanel implementation by extending from the existing FeedBackPanel class
private class MessagesFeedbackPanel extends FeedbackPanel{
private MessageFilter filter = new MessageFilter();
public MessagesFeedbackPanel(String id){
super(id);
setFilter(filter);
}
#Override
protected void onBeforeRender(){
super.onBeforeRender();
// clear old messages
filter.clearMessages();
}
}
Provide a new Filter implementation, by implementing the existing IFeedbackMessageFilter interface
public class MessageFilter implements IFeedbackMessageFilter{
List<FeedbackMessage> messages = new ArrayList<FeedbackMessage>();
public void clearMessages(){
messages.clear();
}
#Override
public boolean accept(FeedbackMessage currentMessage){
for(FeedbackMessage message: messages){
if(message.getMessage().toString().equals(currentMessage.getMessage().toString()))
return false;
}
messages.add(currentMessage);
return true;
}
}
Following code works for me in Wicket 6:
public class MyComponent extends Panel {
...
FeedbackMessages feedback = getFeedbackMessages();
feedback.clear();

GWT TestCase: Simulating clicking a button on my page

I'm using GWT 2.4 with JUnit 4.8.1. When writing my class that extends GWTTestCase, I want to simulate clicking on a button on the page. Currently, in my onModuleLoad method, this button is only a local field ...
public void onModuleLoad() {
final Button submitButton = Button.wrap(Document.get().getElementById(SUBMIT_BUTTON_ID));
...
// Add a handler to send the name to the server
GetHtmlHandler handler = new GetHtmlHandler();
submitButton.addClickHandler(handler);
How do I simulate clicking on this button from the GWTTestCase? Do I have to expose this button as a public member accessor is there a more elegant way to access it? Here is what I have in my test case so far ...
public class GetHtmlTest extends GWTTestCase {
// Entry point class of the GWT application being tested.
private Productplus_gwt productPlusModule;
#Override
public String getModuleName() {
return "com.myco.clearing.productplus.Productplus_gwt";
}
#Before
public void prepareTests() {
productPlusModule = new Productplus_gwt();
productPlusModule.onModuleLoad();
} // setUp
#Test
public void testSuccessEvent() {
// TODO: Simulate clicking on button
} // testSuccessEvent
}
Thanks, - Dave
It can be as easy as buttonElement.click() (or ButtonElement.as(buttonWidget.getElement()).click(), or ButtonElement.as(Document.get().getElementById(SUBMIT_BUTTON_ID)).click())
But remember that a GWTTestCase doesn't run in your own HTML host page, but an empty one, so you'll first have to insert your button within the page before simulating your module's load.
gwt-test-utils seems to be the perfect framework to answer your need. Instead of inheriting from GWTTestCase, extend the gwt-test-utils GwtTest class and implement your click test with the Browser class, like shown in the getting starting guide :
#Test
public void checkClickOnSendMoreThan4chars() {
// Arrange
Browser.fillText(app.nameField, "World");
// Act
Browser.click(app.sendButton);
// Assert
assertTrue(app.dialogBox.isShowing());
assertEquals("", app.errorLabel.getText());
assertEquals("Hello, World!", app.serverResponseLabel.getHTML());
assertEquals("Remote Procedure Call", app.dialogBox.getText());
}
If you want to keep your button private, you'd be able to retrieve it by introspection. But my advice is to make you view's widgets package protected and to write your unit test in the same package so it could access them. It's more convinent and refactoring-friendly.
gwt-test-utils provide introspection convinence. For example, to retrieve the "dialogBox" field which could have been private, you could have do this :
DialogBox dialogBox = GwtReflectionUtils.getPrivateFieldValue(app, "dialogBox");
But note that using GwtReflectionUtils is not mandatory. gwt-test-utils allows you to use ANY java classes in GWT client side tests, without restriction :)
You can do it like this:
YourComposite view = new YourComposite();
RootPanel.get().add(view);
view.getSubmitButton.getElement().<ButtonElement>cast().click();