I am designing an email client system using JSF Framework. The UI should be capable of taking multiple recipient address in the same inputText field each of which is separated by commas(,). How can i achieve this?
Asked
Active
Viewed 2,426 times
0
-
The most straightforward way is to simply parse the recipient address input string get what you want. – Mr.J4mes Dec 12 '11 at 18:22
-
can i assign the value attribute of *inputText* field to an array? – ThunderDragon Dec 12 '11 at 18:31
1 Answers
3
As per the comments:
can i assign the value attribute of inputText field to an array?
You could implement a Converter
for this.
@FacesConverter("commaSeparatedFieldConverter")
public class CommaSeparatedFieldConverter implements Converter {
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null) {
return null;
}
String[] strings = (String[]) value;
StringBuilder builder = new StringBuilder();
for (String string : strings) {
if (builder.length() > 0) {
builder.append(",");
}
builder.append(string);
}
return builder.toString();
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value == null) {
return null;
}
return value.split(",");
}
}
Use it as follows:
<h:inputText value="#{bean.addresses}" converter="commaSeparatedFieldConverter" />
with
private String[] addresses;

BalusC
- 1,082,665
- 372
- 3,610
- 3,555