on 01-24-2007 1:31 PM
Hi folks,
I am trying to Upload an image to the binary type context Attribute using the File Upload UI element. On selecting the file using the Browse button and on clicking the button Upload which calls the method onActionUpload.
what is actually happening is this
after using the browse button to select a file to be uploaded, when I press the Upload button to invoke the uploadAction event Handler , <b>the view(page) reloads</b> no corresponding messages in the code are printed and <b>the message in wdInit() gets printed again</b>
the code piece for <b>onActionUpload</b> and <b>wdinit( )</b> from the view controller are as follows
public void wdDoInit()
{
//@@begin wdDoInit()
IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
msgMgr.reportSuccess("inWdInit");
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute(
IPrivateFileUploadView.IContextElement.FILE_RESOURCE);
attributeInfo.getModifiableSimpleType();
wdContext.currentContextElement().setDetailsVisibility(
WDVisibility.NONE);
//@@end
}
Method for action upload
public void onActiononUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActiononUpload(ServerEvent)
IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
msgMgr.reportSuccess("onClick of Upload");
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute(IPrivateFileUploadView.IContextElement.FILE_RESOURCE);
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attributeInfo.getModifiableSimpleType();
IPrivateFileUploadView.IContextElement element = wdContext.currentContextElement();
if (element.getFileResource() != null)
{
try {
String mimeType = binaryType.getMimeType().toString();
byte[] file = element.getFileResource();
msgMgr.reportSuccess("file value"+file.toString());
//get the size of the uploaded file
element.setFileSize(this.getFileSize(file));
//get the extension of the uploaded file
element.setFileExtension(binaryType.getMimeType().getFileExtension());
element.setDetailsVisibility(WDVisibility.VISIBLE);
wdComponentAPI.getMessageManager().reportMessage(
IMessageFileUploadComp.SF__UPLOAD,
new Object[] { binaryType.getFileName()},
false);
}
catch (Exception e)
{
throw new WDRuntimeException(e);
}
}
else
{
msgMgr.reportSuccess("Nothing in the context Attribute");
element.setDetailsVisibility(WDVisibility.NONE);
msgMgr.reportContextAttributeMessage(
element,
attributeInfo,
IMessageFileUploadComp.NO__FILE,
new Object[] { "" },
true);
}
msgMgr.reportSuccess("File in Context attribute");
element.setFileResource(null);
msgMgr.reportSuccess("File thrown out of Context attribute");
//@@end
}
Kindly suggest..................guide me trace the errors if any....or the correct way to do it
Thanks
Paras
Strange !!!
remove the statement "throw new WDRuntimeException(e)" in th code
catch (Exception e)
{
throw new WDRuntimeException(e);
}
Regards,Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I replaced the line of code pointed out with a message !! now the method looks like this .........................
public void onActiononUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActiononUpload(ServerEvent)
IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
msgMgr.reportSuccess("onClick of Upload");
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute(IPrivateFileUploadView.IContextElement.FILE_RESOURCE);
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attributeInfo.getModifiableSimpleType();
IPrivateFileUploadView.IContextElement element = wdContext.currentContextElement();
if (element.getFileResource() != null)
{
try {
String mimeType = binaryType.getMimeType().toString();
byte[] file = element.getFileResource();
msgMgr.reportSuccess("file value"+file.toString());
//get the size of the uploaded file
element.setFileSize(this.getFileSize(file));
//get the extension of the uploaded file
element.setFileExtension(binaryType.getMimeType().getFileExtension());
element.setDetailsVisibility(WDVisibility.VISIBLE);
wdComponentAPI.getMessageManager().reportMessage(
IMessageFileUploadComp.SF__UPLOAD,
new Object[] { binaryType.getFileName()},
false);
}
catch (Exception e)
{
//throw new WDRuntimeException(e);
msgMgr.reportSuccess("Caught error in if (element.getFileResource() != null)"+e.getLocalizedMessage());
}
}
else
{
msgMgr.reportSuccess("Nothing in the context Attribute");
element.setDetailsVisibility(WDVisibility.NONE);
msgMgr.reportContextAttributeMessage(
element,
attributeInfo,
IMessageFileUploadComp.NO__FILE,
new Object[] { "" },
true);
}
msgMgr.reportSuccess("File in Context attribute");
element.setFileResource(null);
msgMgr.reportSuccess("File thrown out of Context attribute");
//@@end
}
but the problem remains the same,,,,,,,,,,,,,,any more pointers ?
Thanks
Paras
Hi,
1. Are you using MessageArea UIElement to display the messages.
If so check the visbility property of the UIElement,
Ans: No
2. To which UIElement are you binding the attribute "DetailsVisibility" ??
Ans: "DetailsVisibility" is a context attribute of type
"com.sap.ide.webdynpro.uielementdefinitions.Visibility" which is being
to set to value "WDVisibility.NONE" in wdDoInit( ) n WDVisibility.VISIBLE in onActiononUpload( ) , i.e it isnt bound to a UI element
3. Do you any code in wdDoModifyview() method ?
Ans: No
Regards
Paras
Hi Paras,
I think, because of some pblms(I cant see any thing in ur code), the WDVisibility.VISIBLE is never getting called. So for test purpose, let's use message manager
So can u try this.It is working for me
1.Create a context variable(Say File) of type binary in context and bind it to <b>data</b> pty of upload UI. Dont bind any values to <b>resource</b> pty of the Upload UI
2.In wdDoini(), add the following code
IWDAttributeInfo at=wdContext.getNodeInfo().getAttribute(IPrivate<View>.IContextElement.FILE);
at.getModifiableSimpleType();
3. In upload action,add the following code
IWDAttributeInfo at=wdContext.getNodeInfo().getAttribute(IPrivate<View>.IContextElement.FILE);
IWDModifiableBinaryType bType=(IWDModifiableBinaryType)attrInfo.getModifiableSimpleType();
byte b[]=wdContext.currentContextElement().getFile();
wdComponentAPI.getMessageManager().reportWarning("File Size is "(b.length/1000)"KB");
wdComponentAPI.getMessageManager().reportWarning("File Name is "+bType.getFileName());
wdComponentAPI.getMessageManager().reportWarning("File EXTN is "+bType.getMimeType().getFileExtension());
When u deploy and run the above application, it will display the file name, size and extension which is the one u want
Regards
Fahad Hamsa
Hi,
I did the following :
1) Created a new view "ImageUpload" and inserted FileUpload1 UI element and a Button(Upload button) having the event handler "onActiononImageUpload" as a child of the RootUI element container, created the "File" binary attribute :
the codbase for ImageUpload view :
package com.accenture.fileupload;
import com.accenture.fileupload.wdp.IPrivateImageUpload;
import com.sap.tc.webdynpro.progmodel.api.IWDAttributeInfo;
import com.sap.tc.webdynpro.progmodel.api.IWDModifiableBinaryType;
public class ImageUpload
{
/**
Logging location.
*/
private static final com.sap.tc.logging.Location logger =
com.sap.tc.logging.Location.getLocation(ImageUpload.class);
static
{
//@@begin id
String id = "$Id$";
//@@end
com.sap.tc.logging.Location.getLocation("ID.com.sap.tc.webdynpro").infoT(id);
}
private final IPrivateImageUpload wdThis;
private final IPrivateImageUpload.IContextNode wdContext;
private final com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;
private final com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;
public ImageUpload(IPrivateImageUpload wdThis)
{
this.wdThis = wdThis;
this.wdContext = wdThis.wdGetContext();
this.wdControllerAPI = wdThis.wdGetAPI();
this.wdComponentAPI = wdThis.wdGetAPI().getComponent();
}
<b> public void wdDoInit()
{
//@@begin wdDoInit()
IWDAttributeInfo at=wdContext.getNodeInfo().getAttribute(IPrivateImageUpload.IContextElement.FILE);
at.getModifiableSimpleType();
wdComponentAPI.getMessageManager().reportWarning("In wdDoInit()");
//@@end
}</b>
public void wdDoExit()
{
//@@begin wdDoExit()
//@@end
}
public static void wdDoModifyView(IPrivateImageUpload wdThis, IPrivateImageUpload.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
//@@end
}
/** Declared non-validating event handler. */
//@@end
<b>public void onActiononImageUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActiononImageUpload(ServerEvent)
IWDAttributeInfo at=wdContext.getNodeInfo().getAttribute(IPrivateImageUpload.IContextElement.FILE);
IWDModifiableBinaryType bType=(IWDModifiableBinaryType)at.getModifiableSimpleType();
byte b[]=wdContext.currentContextElement().getFile();
wdComponentAPI.getMessageManager().reportWarning("File Size is "(b.length/1000)"KB");
wdComponentAPI.getMessageManager().reportWarning("File Name is "+bType.getFileName());
wdComponentAPI.getMessageManager().reportWarning("File EXTN is "+bType.getMimeType().getFileExtension());
//@@end
}</b>
}
this time, only the page doesnt reloads, I get the message that I am printing in wdDoInit( ) but no message that is being printed out in the action " public void onActiononImageUpload() " the result, still unable to put the image in the context attribute, ...............................help!!
Regards
Paras
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.