[jbossseam-issues] [JBoss JIRA] Created: (JBSEAM-2552) Restructure UIFileUpload.processUpdates code
Kenneth Christensen (JIRA)
jira-events at lists.jboss.org
Tue Jan 29 14:42:59 EST 2008
Restructure UIFileUpload.processUpdates code
--------------------------------------------
Key: JBSEAM-2552
URL: http://jira.jboss.com/jira/browse/JBSEAM-2552
Project: JBoss Seam
Issue Type: Feature Request
Components: JSF Controls
Affects Versions: 2.0.1.CR2
Environment: Seam 2.0.1.CR2
Reporter: Kenneth Christensen
Will it be possible to restructure code in the UIFileUpload.processUpdates (s:fileUpload)?
>From - Original:
{code}
public void processUpdates(FacesContext context)
{
ValueExpression dataBinding = getValueExpression("data");
if (dataBinding != null)
{
Class clazz = dataBinding.getType(context.getELContext());
if (clazz.isAssignableFrom(InputStream.class))
{
dataBinding.setValue(context.getELContext(), getLocalInputStream());
}
else if (clazz.isAssignableFrom(byte[].class))
{
byte[] bytes = null;
if (getLocalInputStream() != null)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try
{
byte[] buffer = new byte[512];
int read = getLocalInputStream().read(buffer);
while (read != -1)
{
bos.write(buffer, 0, read);
read = getLocalInputStream().read(buffer);
}
bytes = bos.toByteArray();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
dataBinding.setValue(context.getELContext(), bytes);
}
if (getLocalContentType() != null)
{
ValueExpression valueExpression = getValueExpression("contentType");
if (valueExpression != null)
{
valueExpression.setValue(context.getELContext(), getLocalContentType());
}
}
if (getLocalFileName() != null)
{
ValueExpression valueExpression = getValueExpression("fileName");
if (valueExpression != null)
{
valueExpression.setValue(context.getELContext(), getLocalFileName());
}
}
if (getLocalFileSize() != null)
{
ValueExpression valueExpression = getValueExpression("fileSize");
if (valueExpression != null)
{
valueExpression.setValue(context.getELContext(), getLocalFileSize());
}
}
}
}
{code}
To - Restructured:
{code}
public void processUpdates(FacesContext context)
{
ValueExpression dataBinding = getValueExpression("data");
if (dataBinding != null)
{
if (getLocalContentType() != null)
{
ValueExpression valueExpression = getValueExpression("contentType");
if (valueExpression != null)
{
valueExpression.setValue(context.getELContext(), getLocalContentType());
}
}
if (getLocalFileName() != null)
{
ValueExpression valueExpression = getValueExpression("fileName");
if (valueExpression != null)
{
valueExpression.setValue(context.getELContext(), getLocalFileName());
}
}
if (getLocalFileSize() != null)
{
ValueExpression valueExpression = getValueExpression("fileSize");
if (valueExpression != null)
{
valueExpression.setValue(context.getELContext(), getLocalFileSize());
}
}
Class clazz = dataBinding.getType(context.getELContext());
if (clazz.isAssignableFrom(InputStream.class))
{
dataBinding.setValue(context.getELContext(), getLocalInputStream());
}
else if (clazz.isAssignableFrom(byte[].class))
{
byte[] bytes = null;
if (getLocalInputStream() != null)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try
{
byte[] buffer = new byte[512];
int read = getLocalInputStream().read(buffer);
while (read != -1)
{
bos.write(buffer, 0, read);
read = getLocalInputStream().read(buffer);
}
bytes = bos.toByteArray();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
dataBinding.setValue(context.getELContext(), bytes);
}
}
}
{code}
and/or what about a fileupload event, when upload is finish?
I really need setFileName(), setFileSize() and setContentType() to be called first - before setData() !
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list