this.inputLength = inputLength;
}
@Override
public void renderHead(HtmlHeaderContainer container) {
IHeaderResponse response = container.getHeaderResponse();
// shouldn't be using MarkupAttributes as it's an internal method, but
// have to, no other way to
// find out if the user put an id attribute on the tag,
// getMarkupId(false) should tell us, but it doens't
// at this stage in rendering it seems
String tmpId = this.getMarkupAttributes().getString("id");
// if they haven't set the id on the component tag, we'll set one for
// them
if (Strings.isEmpty(tmpId)) {
this.setOutputMarkupId(true);
tmpId = this.getMarkupId(true);
}
final String id = tmpId;
// add prototype
response.renderJavascriptReference(PrototypeResourceReference.INSTANCE);
// add this components javascript
response.renderJavascriptReference(new ResourceReference(this.getClass(), "res/scripts/tag.js"));
// add component css
if (properties.isBrowserInternetExplorer()) {
response.renderCSSReference(new ResourceReference(this.getClass(), "res/stylesheets/tag-ie.css"));
} else if (properties.isBrowserSafari()) {
response.renderCSSReference(new ResourceReference(this.getClass(), "res/stylesheets/tag-webkit.css"));
} else {
response.renderCSSReference(new ResourceReference(this.getClass(), "res/stylesheets/tag-moz.css"));
}
// render the javascript to setup the component
IModel variablesModel = new AbstractReadOnlyModel() {
public Map getObject() {
Map<String, CharSequence> variables = new HashMap<String, CharSequence>(2);
variables.put("id", id);
StringBuffer arr = new StringBuffer();
// join our collection into a comma delimeted string
Collection<T> model = (Collection<T>) MultiTextInput.this.getInnermostModel().getObject();
if (model != null) {
Iterator<?> iter = model.iterator();
while (iter.hasNext()) {
arr.append('\'');
// looks like a weird substitution, but regexp in java
// ftl.
arr.append(iter.next().toString().replaceAll("'", "\\\\'").replaceAll("\"", "\\\\\""));
arr.append('\'');
if (iter.hasNext()) {
arr.append(',');
}
}
}
variables.put("model", arr.toString());
variables.put("length", String.valueOf(MultiTextInput.this.inputLength));
return variables;
}
};
// merge the javascript from the properties file with the properties we
// set above
String js = new StringBuffer().append(getString("javascript.tagEntry", variablesModel)).toString();
response.renderOnDomReadyJavascript(js.toString());
super.renderHead(container);
}