Last active
January 29, 2025 07:32
-
-
Save webfirmframework/0635e2cc28851a06704d1b986b1a72c0 to your computer and use it in GitHub Desktop.
Form submit sample code in wffweb-12.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.ServerMethod; | |
| 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.tag.htmlwff.TagContent; | |
| import com.webfirmframework.wffweb.wffbm.data.BMValueType; | |
| import com.webfirmframework.wffweb.wffbm.data.WffBMObject; | |
| import java.util.logging.Logger; | |
| public class FormSubmitExamplewffweb12 extends Div implements ServerMethod { | |
| private static final Logger LOGGER = Logger.getLogger(FormSubmitExamplewffweb12.class.getName()); | |
| public FormSubmitExamplewffweb12(AbstractHtml parent, AbstractAttribute... attributes) { | |
| super(parent, attributes); | |
| develop(); | |
| } | |
| private void develop() { | |
| final Type typeText = new Type(Type.TEXT); | |
| final Form form = new Form(this).give(fm -> { | |
| new NoTag(fm, "First name: "); | |
| new Input(fm, | |
| typeText, | |
| new Name("firstName")); | |
| new Br(fm); | |
| new NoTag(fm, "Last name: "); | |
| new Input(fm, | |
| typeText, | |
| new Name("lastName")); | |
| new Br(fm); | |
| new NoTag(fm, "Agree Conditions: "); | |
| new Input(fm, | |
| new Type(Type.CHECKBOX), | |
| new Name("agreeTC"), | |
| new Checked()); | |
| new Br(fm); | |
| new Button(fm, | |
| new Type(Type.SUBMIT)).give(TagContent::text, "Post"); | |
| }); | |
| final 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 invoke(Event event) { | |
| final WffBMObject data = event.data(); | |
| final String firstName = (String) data.getValue("firstName"); | |
| final String lastName = (String) data.getValue("lastName"); | |
| final boolean agreeTC = (boolean) data.getValue("agreeTC"); | |
| LOGGER.info("firstName: " + firstName); | |
| LOGGER.info("lastName: " + lastName); | |
| LOGGER.info("agreeTC checked: " + agreeTC); | |
| final WffBMObject result = new WffBMObject(); | |
| result.put("msg", BMValueType.STRING, "Successfully submitted!"); | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment