Skip to content

Instantly share code, notes, and snippets.

@webfirmframework
Last active January 31, 2018 15:46
Show Gist options
  • Save webfirmframework/183e5db0983ba8bb1b7fd091ee1e7d10 to your computer and use it in GitHub Desktop.
Save webfirmframework/183e5db0983ba8bb1b7fd091ee1e7d10 to your computer and use it in GitHub Desktop.
Sample form submit java code, refer https://webfirmframework.github.io for developers guide
import java.util.logging.Logger;
import com.webfirmframework.wffweb.tag.html.AbstractHtml;
import com.webfirmframework.wffweb.tag.html.Br;
import com.webfirmframework.wffweb.tag.html.attribute.Checked;
import com.webfirmframework.wffweb.tag.html.attribute.Name;
import com.webfirmframework.wffweb.tag.html.attribute.Type;
import com.webfirmframework.wffweb.tag.html.attribute.core.AbstractAttribute;
import com.webfirmframework.wffweb.tag.html.attribute.event.ServerAsyncMethod;
import com.webfirmframework.wffweb.tag.html.attribute.event.form.OnSubmit;
import com.webfirmframework.wffweb.tag.html.formsandinputs.Button;
import com.webfirmframework.wffweb.tag.html.formsandinputs.Form;
import com.webfirmframework.wffweb.tag.html.formsandinputs.Input;
import com.webfirmframework.wffweb.tag.html.stylesandsemantics.Div;
import com.webfirmframework.wffweb.tag.htmlwff.NoTag;
import com.webfirmframework.wffweb.wffbm.data.BMValueType;
import com.webfirmframework.wffweb.wffbm.data.WffBMObject;
@SuppressWarnings("serial")
public class SampleFormTemplate extends Div implements ServerAsyncMethod {
private static final Logger LOGGER = Logger.getLogger(SampleFormTemplate.class.getName());
public SampleFormTemplate(AbstractHtml parent, AbstractAttribute... attributes) {
super(parent, attributes);
develop();
}
private void develop() {
final Type typeText = new Type(Type.TEXT);
Form form = new Form(this) {{
new NoTag(this, "First name: ");
new Input(this,
typeText,
new Name("firstName"));
new Br(this);
new NoTag(this, "Last name: ");
new Input(this,
typeText,
new Name("lastName"));
new Br(this);
new NoTag(this, "Agree Conditions: ");
new Input(this,
new Type(Type.CHECKBOX),
new Name("agreeTC"),
new Checked());
new Br(this);
new Button(this,
new Type(Type.SUBMIT)) {{
new NoTag(this, "Post");
}};
}};
OnSubmit onSubmit = new OnSubmit("console.log('start loading icon'); event.preventDefault(); return true;", this,
"return ".concat(form.getNameBasedJsObject()).concat(";"),
"console.log('stop loading icon'); alert(jsObject.msg);");
form.addAttributes(onSubmit);
}
@Override
public WffBMObject asyncMethod(WffBMObject wffBMObject, Event event) {
String firstName = (String) wffBMObject.getValue("firstName");
String lastName = (String) wffBMObject.getValue("lastName");
boolean agreeTC = (boolean) wffBMObject.getValue("agreeTC");
LOGGER.info("firstName: " + firstName);
LOGGER.info("lastName: " + lastName);
LOGGER.info("agreeTC checked: " + agreeTC);
WffBMObject result = new WffBMObject();
result.put("msg", BMValueType.STRING, "Successfully submitted!");
return result;
}
}
@webfirmframework
Copy link
Author

webfirmframework commented Jan 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment