go back to the first form in windows mobile application - forms

i am developing an application in which i have a logout option at all the forms. When i click that button I have to return to login form which is the first form to be displayed . So i am able to track back to the first from by making a new object of this from by the way this idea is bad to implement because the other froms are also in the stack. My question is how will i go to that first form while the other form objects are distroyed.
The whole idea is about login-logout functionality in winMo app. If somebody can help me with some part of code it will be very great.
Regards,
Madhup

The easiest way is to pass a reference to the Log-in form to all other forms. Avoid creating and destroying forms. Since you know you are going to reuse them, create them only once and then show or hide them.
In log-in form:
if (isLoginSuccessfull) {
newForm.SetParentForm(this);
newForm.Show();
// Do not call Close();
}
In secondary-forms:
public void SetParentForm(Form parent) {
this.parent = parent;
}
// When you need to close the form:
parent.Show();

Related

hyperlinks with gwt

I am new to GWT, I would like to use hyperlinks where I would like to redirect the user to another form.
My question is that , creating hyperlinks are easy, but how do I use them ?? addClickListener seems to be deprecated, is there any other way to go around this ?
Update 1
I have implemented the Hyper link code as follows :
Hyperlink link0 = new Hyperlink("Show Boxes","showbox");
History.addValueChangeHandler(this);
History.fireCurrentHistoryState();
public void onValueChange(ValueChangeEvent<String> event) {
String eventValue=event.getValue();
if(eventValue.equals("showbox")){
showBox();
}
}
With this I see that the form corresponding to one hyperlink is visible, but this form is not closed and another for is not being opened when I click one another hyperlink.
I am using DockPanel to display the form in the East direction. The forms for all the hyperlinks are just being displayed one below the other.
Any comments/suggestions for the same ?
Thanks,
Bhavya
Use the Anchor.addClickHandler() method!
Anchor a = new Anchor("text");
a.addClickHandler(new ClickHandler(){
// etc
});
If the another form is within your GWT application, then you should consider using Hyperlink. In constructor you provide a history token which is pushed to History object when link is clicked. You just need to handle event that a history token has changed. It decouples navigation events from your logic. This will also make your application aware of back-forward and allows users save bookmarks to specific state (form in your case). Anchor is intended more for external links.
See it described in Coding Basics - History .
First you need to create a HyperLink with a history token:
Hyperlink link = new Hyperlink("link to foo", "foo");
In above example, "foo" is the history token.
Then you should register your value change handler on History object, like
History.addValueChangeHandler(myValueChangeHandler);
In your value change handler, you will need to read in the current token using event.getValue().
class MyValueChangeHandler implements ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> event) {
//get the new value of history token
//clicking on above example link will return "foo" here
String historyToken = event.getValue();
}
}
What does the value of history token means is up to your application to decide. For example you can maintain a simple Map between history tokens and the view that should be rendered. In more sophisticated applications you can encode more details into the token -- like initial state of the form that should be displayed.

Nvigation within a GWT application

I intend to build a web application where users can enter their time every week and have been struggling to get my head around the concept of a single page in GWT that gets repainted with data depending on the user actions. After researching a lot on this site and google, I found one link that I would like to emulate but dont know how to go about doing it in GWT. Although their source code is available, I dont think it is full and complete. I got some idea from this link - Multiple pages tutorial in Google Web Toolkit (GWT) but again dont know how to implement it into a working version. One small working sample would be great to help me understand and get started.
Could anyone please guide me as to how to achieve the look and feel of the screen with the link below and how the content can be repainted with data from the server ? Would I need to put all the logic in one EntryPoint class ? I would like to have the hyperlinks in the left navigation panel and show the content in the right panel. I seem to be completely lost after a few hours of research.
http://gwt.google.com/samples/Showcase/Showcase.html#!CwHyperlink
Thanks a lot for your help.
Regards,
Sonu.
A single page application layout is actually quite easy to achieve.
The first thing you do is define the general layout, using GWTs layout panels. For your layout, I'd suggest using a DockLayoutPanel.
Content content = new Content();
Button switchContent = new Button(content);
Navigation navigation = new Navigation();
navigation.add(switchContent);
DockLayoutPanel pageLayout = new DockLayoutPanel(Unit.EM);
p.addWest(new HTML(navigation), 7.5);
p.add(new HTML(content));
Here, the width of the navigation panel will be fixed, whereas the content will take the remaining space. You have to pass a reference of the button (or some other widget) which does the switch of the content area, add the button to the navigation area, and so on.
Put this into a class, e.g. called MasterPageFactory:
public class MasterPageFactory {
private MasterPageFactory() {}
public static MasterPage newInstance() {
Content content = new Content();
Button switchContent = new Button(content);
Navigation navigation = new Navigation();
navigation.add(switchContent);
DockLayoutPanel masterPage = new DockLayoutPanel(Unit.EM);
masterPage.addWest(new HTML(navigation), 7.5);
masterPage.add(new HTML(content));
return masterPage;
}
}
Now, in your EntryPoint class, call the factory:
RootLayoutPanel.get().add(MasterPageFactory.newInstance());
This example should get you an idea. Other options would be using a DI framework like Guice or the Command pattern.
Your question is mixing up a couple of concepts. If you want the user to click something that looks like a link, and in reponse the application sends a request to the server and shows a page that looks different than the page they're on, and that page has fresh data that just came from the server, then you want a perfectly normal anchor or form submit button. You don't need anything special or weird from GWT.
The showcase example you referenced lets the user click something that looks like a link, and looks like it loads a new page, even to the point of letting the back button work as expected, but does not actually hit the server to get a new page or new data.

How to post partial view to another controller method

I have a one form tag inside my Index.aspx view. Index.aspx contains several partial views and using the same model to render them.
Now when any partial view is posting the form with submit button form is posted to OneActionMethod. But I want for some partial views to post form to OtherActionMethod.
How can I achieve this, without using action links, just with submit button in this particular patial view?
I`ve wrote the update in comments to this question. Answer is still not clear to me.
i believe a little javascript will get ur job done. u have to hook the submit event of the form and change the action attribute of the form. remember action is attribute of form not of a submit button. in jquery u can do something like
$("#myform").submit(function(){
if(isFirstSubmitButton){
$(this).attr(FirstAction);
}
else if(isSecondSubmitButton)
{
$(this).attr(SecondAction);
}
return true;
});
You sound like you are trying to program "WebForms" style in MVC.
Why do you have one big form enclosing all of your partials? Separate them into unique forms, and have each one post to it's appropriate action.
EDIT: With your further clarification, the only thing I can think of (aside from redesigning to use individual forms, which does lead to problems if they want to share data), is to post to a single action, and then route the request to a private member within the controller for ActionA or ActionB depending on a particular form element.

How to keep business logic seperate within GWT Composites?

I'm currently building a GWT login screen and I managed to get a basic version of the login structure working.
I created the following pieces:
An entry point class (actually it was given).
A main application screen composite.
A login-screen composite.
I have the following logic in my entry point method:
MyApplication mainWindow = null;
public void onModuleLoad() {
LoginScreen loginScreen = new LoginScreen() {
#Override
public String onLogin(String username, String password) {
boolean passwordWasOk = rpcCheckUsernamePassword(username,password); // mechanism not important for this question
if (passwordWasOk) {
RootPanel.get().remove(0);
mainWindow = new MyApplication();
// Using root layout panel as main window is a layout type composite
RootLayoutPanel.get().add(mainWindow);
return null;
} else {
return "password was incorrect";
}
}
};
RootPanel.get().add(loginScreen);
}
So, I created a method in the LoginScreen composite that is called when the user clicks the 'Sign-In' button. If the onLogin method fails its validation of the username and password, then a narrative can be returned to the login composite so that it can update the user. The login screen will stay on the screen until the user uses a correct username/password combination.
My question is, is this the correct way to use composites? Where should my login logic ideally reside. Is a better alternative to inject some sort of login handler object in the constructor of the composite or via a setter or is the method I used quite normal?
As I'm planning to write quite a lot of code, I want to get the coding style correct from the outset.
Any feedback is greatly appreciated.
Thanks,
For complex projects you'd want to use the Model-View-Presenter (MVP) design pattern. It allows you to separate the rendering logic (views) from the business logic. To get you started, the official documentation has two articles about it plus there's that presentation by Ray Ryan that started the whole GWT + MVP = <3 haze :) After that I'd recommend browsing through MVP related questions on SO and GWT's Google Group.

GWT need to know how to connect to.. or go from one page to another

im new to GWT ive been working on it since recently..
i want to know how can i go from "entry point page" ie,ImageViewer.java..
ive been suggested to create the memory by calling constructor on a perticular button
Button button = new Button("New button");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
new LookupMaster(); //this is a composite
}
});
but this is not working.. i guess v can only call or get alert messages using this type..
can some one help me.
I'm not sure how to answer, since I have the feeling you're not understanding the basic concepts totally, but that's just my interpretation.
GWT is one html page that via JavaScript methods changes the content of that one page. When you want to display 'another' page you need to do this via methods that update the html dynamically. Since you are just starting with GWT, you might want to read this page on Build User Interfaces to understand the concepts and look at some examples provided with GWT.