form validation ready

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/invite-friends-vre@114562 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2015-04-29 13:20:35 +00:00
parent cc12dd1ffd
commit d7eecbf6e3
14 changed files with 96 additions and 53 deletions

View File

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/invite-friends-vre-0.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/invite-friends-vre-0.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/invite-friends-vre-0.0.1-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<classpathentry kind="src" output="target/invite-friends-vre-0.1.0-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/invite-friends-vre-0.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/invite-friends-vre-0.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -39,5 +39,5 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/invite-friends-vre-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/invite-friends-vre-0.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -25,11 +25,6 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
<arguments>
@ -40,6 +35,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>

View File

@ -0,0 +1,3 @@
eclipse.preferences.version=1
validateFragments=false
validation.use-project-settings=true

View File

@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="invite-friends-vre">
<wb-module deploy-name="invite-friends-vre-portlet">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="session-checker-0.3.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="invite-friends-vre"/>
<property name="java-output-path" value="/invite-friends-vre/target/invite-friends-vre-0.0.1-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -4,4 +4,5 @@
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="liferay.portlet" version="6.0"/>
</faceted-project>

1
.tern-project Normal file
View File

@ -0,0 +1 @@
{"ide":{"scriptPaths":[]},"plugins":{"aui":{},"liferay":{},"yui":{}},"libs":["ecma5","browser"]}

View File

@ -6,7 +6,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>invite-friends-vre</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<version>0.1.0-SNAPSHOT</version>
<name>Invite Friends to VRE</name>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</connection>
@ -55,11 +55,13 @@
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -39,20 +39,41 @@ public class FormErrorsValidation extends AbstractActivity implements FormView.D
@Override
public boolean onSendClick() {
EditorDriver<UserDetails> editorDriver = view.getEditorDriver();
UserDetails login = editorDriver.flush();
Set<ConstraintViolation<UserDetails>> violations = validate(login);
UserDetails details = editorDriver.flush();
Set<ConstraintViolation<UserDetails>> violations = validateEmailTextBox(details);
//decorate widgets implementing HasEditorErrors with validation messages
return editorDriver.setConstraintViolations( (Set) violations);
}
private Set<ConstraintViolation<UserDetails>> validate(UserDetails user2InviteBean){
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public boolean onEmailSendInviteClick() {
EditorDriver<UserDetails> editorDriver = view.getEditorDriver();
UserDetails details = editorDriver.flush();
Set<ConstraintViolation<UserDetails>> violations = validateName(details);
return !violations.isEmpty();
}
private Set<ConstraintViolation<UserDetails>> validateName(UserDetails user2InviteBean) {
Set<ConstraintViolation<UserDetails>> violations = new HashSet<ConstraintViolation<UserDetails>>();
if(user2InviteBean.getName() == null || "".equals(user2InviteBean.getName().trim())) {
violations.add(buildNotNullConstraintViolation(user2InviteBean, "name"));
}
if(user2InviteBean.getLastName() == null || "".equals(user2InviteBean.getLastName().trim())) {
violations.add(buildNotNullConstraintViolation(user2InviteBean, "lastname"));
}
return violations;
}
private Set<ConstraintViolation<UserDetails>> validateEmailTextBox(UserDetails user2InviteBean){
Set<ConstraintViolation<UserDetails>> violations = new HashSet<ConstraintViolation<UserDetails>>();
if(user2InviteBean.getEmail() == null || "".equals(user2InviteBean.getEmail().trim())) {
violations.add(buildNotNullConstraintViolation(user2InviteBean, "email"));
violations.add(buildNotNullConstraintViolation(user2InviteBean, "email"));
}
else if (!isValidEmailAddress(user2InviteBean.getEmail())) {
violations.add(buildInvalidEmailAddressConstraintViolation(user2InviteBean, "email"));
}
return violations;
}
@ -155,4 +176,5 @@ public class FormErrorsValidation extends AbstractActivity implements FormView.D
return valid;
}
}

View File

@ -47,7 +47,11 @@ public interface FormView extends IsWidget {
public interface Delegate {
boolean onSendClick();
boolean onEmailSendInviteClick();
}
EditorDriver<UserDetails> getEditorDriver();
}

View File

@ -4,9 +4,11 @@
package org.gcube.portlets.user.invitefriends.client.validation;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.HelpBlock;
import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.EditorDriver;
@ -41,8 +43,11 @@ public class FormViewImpl extends Composite implements FormView, Editor<FormView
@UiField Button cancelInvite;
@UiField Button sendInvite;
@UiField Modal modalWindow;
@UiField HelpBlock nameErrors;
@UiField HelpBlock helpBlock;
@UiField
ControlGroup nameGroup;
/**
*
*/
@ -62,6 +67,17 @@ public class FormViewImpl extends Composite implements FormView, Editor<FormView
}
}
@UiHandler("sendInvite")
void onSendInviteClick(ClickEvent event) {
if (delegate.onEmailSendInviteClick()) {
nameGroup.setType(ControlGroupType.ERROR);
nameErrors.setText("Please fill both name and last name");
} else {
nameGroup.setType(ControlGroupType.SUCCESS);
nameErrors.setText("");
}
}
@UiHandler("cancelInvite")
public void onCancelClick(ClickEvent e) {
modalWindow.hide();

View File

@ -2,37 +2,31 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<b:Form type="VERTICAL">
<b:Fieldset ui:field="controlFieldset">
<b:ControlGroup ui:field="emailGroup">
<b:TextBox placeholder="e-mail address" ui:field="email"
controlGroup="{emailGroup}" errorLabel="{emailErrors}" />
<b:HelpBlock ui:field="emailErrors"></b:HelpBlock>
</b:ControlGroup>
<b:Button ui:field="openModal">Send Invite</b:Button>
<b:Modal ui:field="modalWindow" title="Invite Friend"
backdrop="STATIC" keyboard="true" animation="true">
<b:Form type="VERTICAL">
<b:ControlGroup ui:field="nameGroup">
<b:HelpBlock styleName="helpFontSize">Please, enter Name and
Last name
of the friend you
wish to invite:</b:HelpBlock>
<b:ControlGroup ui:field="emailGroup">
<b:TextBox placeholder="e-mail address" ui:field="email"
controlGroup="{emailGroup}" errorLabel="{emailErrors}" />
<b:HelpBlock ui:field="emailErrors"></b:HelpBlock>
</b:ControlGroup>
<b:Button ui:field="openModal">Send Invite</b:Button>
<b:Modal ui:field="modalWindow" title="Invite Friend"
backdrop="STATIC" keyboard="true" animation="true">
<b:Form type="VERTICAL" ui:field="mainForm">
<b:Fieldset>
<b:ControlGroup>
<b:HelpBlock styleName="helpFontSize">Please, enter Name and
Last name
of the friend you
wish to invite:</b:HelpBlock>
<b:TextBox placeholder="name" ui:field="name"></b:TextBox>
<b:TextBox placeholder="last name" ui:field="lastName"></b:TextBox>
<b:HelpBlock ui:field="helpBlock" styleName="helpFontSize"></b:HelpBlock>
</b:ControlGroup>
</b:Fieldset>
</b:Form>
<b:ModalFooter>
<b:Button ui:field="cancelInvite">Cancel</b:Button>
<b:Button ui:field="sendInvite" type="PRIMARY">Send Invite</b:Button>
</b:ModalFooter>
</b:Modal>
</b:Fieldset>
<b:TextBox placeholder="name" ui:field="name"></b:TextBox>
<b:TextBox placeholder="last name" ui:field="lastName"></b:TextBox>
<b:HelpBlock ui:field="nameErrors"></b:HelpBlock>
<b:HelpBlock ui:field="helpBlock" styleName="helpFontSize"></b:HelpBlock>
</b:ControlGroup>
</b:Form>
<b:ModalFooter>
<b:Button ui:field="cancelInvite">Cancel</b:Button>
<b:Button ui:field="sendInvite" type="PRIMARY">Send Invite</b:Button>
</b:ModalFooter>
</b:Modal>
</b:Form>
</ui:UiBinder>

View File

@ -2,6 +2,10 @@
}
form {
margin-bottom: 10px !important;
}
.helpFontSize {
font-size: 14px;
}

View File

@ -14,8 +14,6 @@
<title>Web Application Starter Project</title>
<script type="text/javascript" src="invitefriends/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="invitefriends/js/bootstrap.min.js"></script>
<script type="text/javascript" language="javascript" src="invitefriends/invitefriends.nocache.js"></script>
</head>

View File

@ -9,11 +9,6 @@
--%>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript"
src="<%=request.getContextPath()%>/invitefriends/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/invitefriends/js/bootstrap.min.js"></script>
<script type="text/javascript"
src='<%=request.getContextPath()%>/invitefriends/invitefriends.nocache.js'></script>
<div id="invite-friends-DIV"></div>