Created
January 31, 2018 08:35
-
-
Save webfirmframework/e01427cc8acb8a2e48dee61f7d76d442 to your computer and use it in GitHub Desktop.
Example for Sateful input field which syncs the value state to the server on change value event.
This file contains 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.OnChange; | |
import com.webfirmframework.wffweb.tag.html.formsandinputs.Input; | |
public class StatefulInput extends Input { | |
public StatefulInput(AbstractHtml base, AbstractAttribute... attributes) { | |
super(base, attributes); | |
develop(); | |
} | |
private void develop() { | |
if (super.getAttributeByName(AttributeNameConstants.ONCHANGE) != null) { | |
throw new IllegalArgumentException("OnChange attribute should not be explicitly given in this tag."); | |
} | |
final Value valueAttr; | |
{ | |
Value value = (Value) super.getAttributeByName(AttributeNameConstants.VALUE); | |
valueAttr = value != null ? value : new Value(""); | |
} | |
OnChange onChange = new OnChange("return true;", | |
(bm, ev) -> { | |
String value = (String) bm.getValue("attrValue"); | |
//updateClient must be false to avoid synching the changes to the client browser page | |
valueAttr.setValue(false, value); | |
return null; | |
}, | |
"return {attrValue: source.value};", null); | |
super.addAttributes(valueAttr, onChange); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:-
new StatefulInput(this, new Type(Type.TEXT), new Name("First Name"));
Developers guide to get started
Convert HTML5 to webfirmframework Java/Kotlin Code