return key.substring(key.indexOf(HtmlFormBuilderItem.DATA_UUID_PREFIX) + HtmlFormBuilderItem.DATA_UUID_PREFIX.length(), key.length());
}
@Override
public void decode(FacesContext ctx, UIComponent component) {
FormFillerInternal formFiller = (FormFillerInternal) component;
boolean fillError = false;
HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();
String formContentString = ctx.getExternalContext().getRequestParameterMap().get(FormBuilderInternalRenderer.getFormContentStringId(component));
String formActionString = ctx.getExternalContext().getRequestParameterMap().get(FormBuilderInternalRenderer.getFormActionStringId(component));
boolean formSubmit = true;
if (formActionString != null) {
switch (formActionString) {
case "download":
if (formFiller.getFormData().getData() != null) {
for (FormBuilderItemData data : formFiller.getFormData().getData()) {
if (data.getUuid().equals(formContentString)) {
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
prepareResponseFor(response, data.getFile());
try {
streamFileTo(response, data.getFile());
} catch (IOException ex) {
Logger.getLogger(FormFillerInternalRenderer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
formSubmit = false;
break;
}
}
if (formFiller.getFormData().getData() != null && formSubmit) {
MultipartRequest multiRequest = new MultipartRequest(request);
for (String key : multiRequest.getFiles().keySet()) {
if (key.contains(HtmlFormBuilderItem.DATA_UUID_PREFIX)) {
String dataUuid = extractDataUuid(key);
for (FormBuilderItemData data : formFiller.getFormData().getData()) {
if (data.getUuid().equals(dataUuid)) {
data.setFile(multiRequest.getFiles().get(key));
}
}
}
}
for (String key : multiRequest.getParameterMaps().keySet()) {
if (key.contains(HtmlFormBuilderItem.DATA_UUID_PREFIX)) {
String dataUuid = extractDataUuid(key);
for (FormBuilderItemData data : formFiller.getFormData().getData()) {
if (data.getUuid().equals(dataUuid)) {
List<String> result = multiRequest.getParameterMaps().get(key);
if (data.getFormBuilderItem() instanceof FormBuilderItemNumber) {
if (result.size() == 1) {
try {
if (!"".equals(result.get(0).trim())) {
data.setNumberValue(Float.parseFloat(result.get(0).replaceAll(",", ".")));
}
} catch (NumberFormatException ex) {
throw new NumberFormatException("Internal error with number component. Number not parseable.");
}
}
if (data.getFormBuilderItem().getProperties().getMandatory()
&& data.getNumberValue() == null) {
fillError = true;
data.getFormBuilderItem().getProperties().setMandatoryError(true);
}
} else {
if (result.size() == 1) {
data.setValue(result.get(0));
} else {
String tmp = "";
for (String str : result) {
tmp += str;
tmp += ";";
}
data.setValue(tmp.substring(0, tmp.length() - 1));
}
if (data.getFormBuilderItem().getProperties().getMandatory()
&& (data.getValue() == null
|| "".equals(data.getValue().trim()))) {
fillError = true;
data.getFormBuilderItem().getProperties().setMandatoryError(true);
}
}
}
}
}
}
//Check every field if it is filled
}
if (!fillError) {
formFiller.setInvokeCallback(true);
}
}