Last active
January 29, 2025 07:46
-
-
Save webfirmframework/37a7cb17dc735e936bccf04596d5fa1b to your computer and use it in GitHub Desktop.
Stateful Input 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.attribute.AttributeNameConstants; | |
| import com.webfirmframework.wffweb.tag.html.attribute.Value; | |
| import com.webfirmframework.wffweb.tag.html.attribute.core.AbstractAttribute; | |
| import com.webfirmframework.wffweb.tag.html.attribute.event.form.OnInput; | |
| import com.webfirmframework.wffweb.tag.html.formsandinputs.Input; | |
| import com.webfirmframework.wffweb.wffbm.data.WffBMObject; | |
| /** | |
| * Usage: | |
| * <pre> | |
| * <code>final StatefulInputwffweb12 statefulInputwffweb12 = new StatefulInputwffweb12(this); | |
| * final String inputValue = statefulInputwffweb12.getAttributeByName(AttributeNameConstants.VALUE) instanceof Value value ? value.getValue() : ""; | |
| * System.out.println("inputValue = " + inputValue);</code> | |
| * </pre> | |
| */ | |
| public class StatefulInputwffweb12 extends Input { | |
| public StatefulInputwffweb12(AbstractHtml base, AbstractAttribute... attributes) { | |
| super(base, attributes); | |
| develop(); | |
| } | |
| private void develop() { | |
| if (super.getAttributeByName(AttributeNameConstants.ONINPUT) != null) { | |
| throw new IllegalArgumentException("OnInput attribute should not be explicitly given to this tag."); | |
| } | |
| final OnInput onInput = new OnInput("return true;", | |
| event -> { | |
| final WffBMObject data = event.data(); | |
| final String attrValue = (String) data.getValue("attrValue"); | |
| // print just for testing | |
| // System.out.println("attrValue = " + attrValue); | |
| if (super.getAttributeByName(AttributeNameConstants.VALUE) instanceof final Value value) { | |
| //updateClient must be false to avoid syncing the changes to the client browser page | |
| value.setValue(false, attrValue); | |
| } else { | |
| //updateClient must be false to avoid syncing the changes to the client browser page | |
| super.addAttributes(false, new Value(attrValue)); | |
| } | |
| return null; | |
| }, | |
| "return {attrValue: source.value};", null); | |
| super.addAttributes(onInput); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: