Dzięki takiemu rozwiązaniu można określić dodatkowe właściwości w wiążącej xml:
Rozwiązanie:
public class MorePropertiesTextArea extends TextArea {
private String moreProperties;
public MorePropertiesTextArea() {}
public void setMoreProperties(String moreProperties) {
for (Entry<String, String> entry : parse(moreProperties).entrySet()) {
getElement().setAttribute(entry.getKey(), entry.getValue());
}
this.moreProperties = moreProperties;
}
public String getMoreProperties() {
return moreProperties;
}
private Map<String, String> parse(String moreProperties) {
String[] pairStrings = moreProperties.split(";");
HashMap<String, String> map = new HashMap<>();
for (String pairString : pairStrings) {
String[] pair = pairString.split("=");
if(pair.length != 2)
throw new IllegalArgumentException("at " + pair + " while parsing " + moreProperties +
". Use format like: 'spellcheck=false; placeholder=Write something here...'");
map.put(pair[0].trim(), pair[1]);
}
return map;
}
}
UI Binder xml:
<p2:MultiLineTextArea ui:field="taMultiLine" styleName="form-control muliLine"
moreProperties="spellcheck=false; placeholder=Write something here... " />
Wynik html:
<textarea class="form-control muliLine" spellcheck="false" placeholder="Write something here..."></textarea>
Awesome. Działa świetnie. – supercobra