+ fieldValueId + "\");";
final String requiredStr = fieldValueId + ".setRequired("
+ required + ");";
if (field.getAnnotation(ROO_UPLOADED_FILE) != null) {
final AnnotationMetadata annotation = field
.getAnnotation(ROO_UPLOADED_FILE);
final String contentType = (String) annotation.getAttribute(
"contentType").getValue();
final String allowedType = UploadedFileContentType
.getFileExtension(contentType).name();
if (action == Action.VIEW) {
builder.getImportRegistrationResolver().addImports(
UI_COMPONENT,
PRIMEFACES_FILE_DOWNLOAD_ACTION_LISTENER,
PRIMEFACES_COMMAND_BUTTON,
PRIMEFACES_STREAMED_CONTENT);
// bodyBuilder.appendFormalLine("CommandButton " +
// fieldValueId + " = " +
// getComponentCreation("CommandButton"));
// bodyBuilder.appendFormalLine(fieldValueId +
// ".addActionListener(new FileDownloadActionListener(expressionFactory.createValueExpression(elContext, \"#{"
// + beanName + "." +
// fieldName +
// "StreamedContent}\", StreamedContent.class), null));");
// bodyBuilder.appendFormalLine(fieldValueId +
// ".setValue(\"Download\");");
// bodyBuilder.appendFormalLine(fieldValueId +
// ".setAjax(false);");
// TODO Make following code work as currently the view panel
// is not refreshed and the download field is always seen as
// null
bodyBuilder.appendFormalLine("UIComponent " + fieldValueId
+ ";");
bodyBuilder.appendFormalLine("if (" + entityName
+ " != null && " + entityName + ".get"
+ StringUtils.capitalize(fieldName)
+ "() != null && " + entityName + ".get"
+ StringUtils.capitalize(fieldName)
+ "().length > 0) {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine(fieldValueId + " = "
+ getComponentCreation("CommandButton"));
bodyBuilder
.appendFormalLine("((CommandButton) "
+ fieldValueId
+ ").addActionListener(new FileDownloadActionListener(expressionFactory.createValueExpression(elContext, \"#{"
+ beanName
+ "."
+ fieldName
+ "StreamedContent}\", StreamedContent.class), null));");
bodyBuilder.appendFormalLine("((CommandButton) "
+ fieldValueId + ").setValue(\"Download\");");
bodyBuilder.appendFormalLine("((CommandButton) "
+ fieldValueId + ").setAjax(false);");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("} else {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine(fieldValueId + " = "
+ getComponentCreation("HtmlOutputText"));
bodyBuilder.appendFormalLine("((HtmlOutputText) "
+ fieldValueId + ").setValue(\"\");");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
}
else {
builder.getImportRegistrationResolver().addImports(
PRIMEFACES_FILE_UPLOAD,
PRIMEFACES_FILE_UPLOAD_EVENT);
bodyBuilder.appendFormalLine("FileUpload " + fieldValueId
+ " = " + getComponentCreation("FileUpload"));
bodyBuilder.appendFormalLine(componentIdStr);
bodyBuilder
.appendFormalLine(fieldValueId
+ ".setFileUploadListener(expressionFactory.createMethodExpression(elContext, \"#{"
+ beanName
+ "."
+ getFileUploadMethodName(fieldName)
+ "}\", void.class, new Class[] { FileUploadEvent.class }));");
bodyBuilder.appendFormalLine(fieldValueId
+ ".setMode(\"advanced\");");
bodyBuilder.appendFormalLine(fieldValueId
+ ".setAllowTypes(\"/(\\\\.|\\\\/)("
+ getAllowTypeRegex(allowedType) + ")$/\");");
bodyBuilder.appendFormalLine(fieldValueId
+ ".setUpdate(\":growlForm:growl\");");
final AnnotationAttributeValue<?> autoUploadAttr = annotation
.getAttribute("autoUpload");
if (autoUploadAttr != null
&& (Boolean) autoUploadAttr.getValue()) {
bodyBuilder.appendFormalLine(fieldValueId
+ ".setAuto(true);");