Here is my problem: I need to create a (seemingly) simple front-end for a report. The user enters a bunch of numbers, seperated by whitespace or commas, which are the IDs that will be brought up in a report.
I use a converter to change this from a string to a List, and then from there back into a form where the numbers are delimited with a comma:
@FacesConverter(value="multiProdConverter")
public class MultiProdConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
StringTokenizer splitter = new StringTokenizer(value, " \t\n\r\f,");
List<Integer> ret = new ArrayList<Integer>();
while (splitter.hasMoreTokens()) {
String token = splitter.nextToken();
ret.add(Integer.parseInt(token));
}
return ret;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return implode((List<Integer>)value);
}
private String implode(List<Integer> sdaList) {
StringBuilder sb = new StringBuilder();
if (!sdaList.isEmpty()) {
sb.append(sdaList.get(0));
for (int i = 1; i < sdaList.size(); i++) {
sb.append(",");
sb.append(sdaList.get(i));
}
}
return sb.toString();
}
}
However, what's the best way to actually get this formatted version of the numbers into a request parameter for an external page?
I want the user to just hit submit after giving the numbers, and then the page goes to this report. This would be pretty easy using just javascript, but what's the "JSF" way to do this?
Thanks, Zack