Here is my Gwt Problem. Say, I got a form that has email, firstName,
username, password... Textboxes & a submit Button. When users click Submit,
the client will validate all fields, after all fields are ok, then they
will be sent to Server for another *EXACTLY* same validation.
Someone suggested me to make a Utility class & put that class into the *
shared* package.
Look at this code
In my.com.client package:
import my.com.shared.Utility;
public class CustPresenter extends
Presenter<CustPresenter.MyView, CustPresenter.MyProxy> {
@Inject DispatchAsync dispatchAsync;
public void postData(){
PostData postDataAction=new PostData();
String fName=fNameTextBox.getText();
String lName=lNameTextBox.getText();
//....... more field here ....//
if(!Utility.isOKString(fName)){
MyDialogBox myD=new MyDialogBox(fName, "Not OK");
}
else if (!Utility.isOKString(lName)){
MyDialogBox myD=new MyDialogBox(lName, "Not OK");
}
///.......more checking here//
postDataAction.setFName(fName);
postDataAction.setFName(lName);
//... more setting here...//
dispatchAsync.execute(postDataAction, postDataCallback);
}
private AsyncCallback<PostDataResult> postDataCallback=new
AsyncCallback<PostDataResult>(){
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(PostDataResult result) {
String resultStr=result.getResult();
if(resultStr.equals("fName is not OK")){
MyDialogBox myD=new MyDialogBox(fName, "Not OK");
}
else if (resultStr.equals("lName is not OK")){
MyDialogBox myD=new MyDialogBox(lName, "Not OK");
}
/// more displaying err message...
}
};
}
in my.com.server package
import my.com.shared.Utility;
public class PostDataActionHandler implements
ActionHandler<PostData, PostDataResult> {
@Override
public PostDataResult execute(PostData action, ExecutionContext context)
throws ActionException {
String fName=action.getFName();
String lName=action.getLName();
//more geting here....//
String resultInfo="";
if(!Utility.isOKString(fName)){
resultInfo="fName is not OK";
}
else if (!Utility.isOKString(lName)){
resultInfo="lName is not OK";
}
////... more checking here///
else{
postData();
}
return new PostDataResult(resultInfo);
}
}
As you can see in this structure, even I used Utility in shared package, i
still have to validate the same data 3 times. And there're a lot of
duplicates.
So my question is:
Can we create a certain Validation class (or design a certain Structure) &
put that class in shared package & so client & server can use it, so i just
need to validate 1 time rather than doing it 3 times like this?
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.