Internal Error instead of showing the Default Image

Internal Error instead of showing the Default Image

  
I have three many to many related entities as students(Ogrenci), classes(Sinif) and seasons(Sezon). There is a many to many relationship that means every student may have many classes and seasons and vice versa. The relationship is defined in a forth entity called SinifOgrenci.

I have a list page (SinifOgrenci_List) for listing a particular season's students. I have inserted a picture column to the list and connected it to OgrenciPicture Entity. Backend TrueChange gives no error. But when I open the list from the browser I got an internal error for the first student without a picture, instead of showing the default image for it.

The Normal OgrenciList page with picture works without any problems.

The error in the log is:


Service Center Version: 6.0.0.6 (build 27043: tags/v6_0_0_6 @ 2011-06-21 22:19:25)


Module_Name: 

Message :"outsystems"."DBO"."OSUSR_8JS_OGRENCIPICTURE" with key 31 was not found

Stack:    at ssGBA.ExtendedActions.GetOgrenciPicture(HeContext heContext, Int32 inParamId, RCOgrenciPictureRecord& outParamRecord)
   at ssGBA.Functions.ssGetOgrenciPicture(HeContext heContext, Int32 inParamId)
   at ssGBA.Flows.FlowMainFlow.ScrnSinifOgrenci_List.img5_getFilename()
   at ASP.sinifogrenci_list_aspx.__DataBinding__control99(Object sender, EventArgs e)
   at System.Web.UI.Control.OnDataBinding(EventArgs e)
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBind()
   at OutSystems.HubEdition.WebWidgets.DynamicImage.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBind()
   at System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListIt....Control.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBind()
   at OutSystems.HubEdition.WebWidgets.OSPage.DataBind()
   at ssGBA.Flows.FlowMainFlow.ScrnSinifOgrenci_List.DataBind()
   at ssGBA.Flows.FlowMainFlow.ScrnSinifOgrenci_List.Page_Load(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
-Env-
eSpaceVer: 138 (Id=192, PubId=203, CompiledWith=6.0.0.6)
RequestUrl: http://212.175.206.151/GBA/SinifOgrenci_List.aspx
AppDomain: /LM/W3SVC/1/Root/GBA-4-129561187666875000
FilePath: C:\...\PS\running\GBA.01985253024\SinifOgrenci_List.aspx
Locale: en-US
DateFormat: dd/MM/yyyy
PID: 2528 ('w3wp', Started='7/26/2011 1:17:47 AM', Priv=191Mb, Virt=692Mb)
TID: 7
.NET: 2.0.50727.3623

eSpace Name: GBA

Tenant Name: GBA

InstallerId: 233FF278-4DE0-234B-B38E-8F08ABDBC382
License Edition: Community Edition
Windows Version: Microsoft Windows NT 5.2.3790 Service Pack 2

Thanks in advance.


Hi,

What is your question exactly?

the error suggest you have an image with key 31 which is not in the database.
so either 31 is wrong (perhaps removed already or... )


Thanks for your reply Joost.

The student with key 31 has never had a picture, i.e. never uploaded.

So, if no image exists in the database, Default Image is used at run time, isn't it?

Then why, in my case, it is giving an error instead of showing the image?

P.S.: If I upload a photo to the student with key 31, then the error repeats itself with the next key which has no photo.
Cannot see the oml, since I have only access to 5.1 :(

But I assume you are doing a Get<Entity> based on that id, which throws an exception if it cannot be found.
So, either use a normal query or catch the databaseexception.

Is my assumption correct?
Yes. I am using;
GetOgrenciPicture(SinifOgrenciTable.List.Current.SinifOgrenci.OgrenciId).OgrenciPicture.Filename
How can I catch the database exception?

I mean, I put a database exception handler to Preparation Action of the list. Is this the right place, or will I put it somewhere else? And how will I config it?
Hi Rifat,

It's better you don't let the error fire and only then catch it otherwise it's going to interrupt the page rendering altogether which is not what you want. It looks to me that what you really need to do here is NOT display the database picture at all in the case there isn't one associated to the current row being rendered.

I suggest that on the cell of the picture column, you push the current PICTURE widget into either the trueor false side of the IF widget and make the IF's condition only render that side (the one that fetches from the DB) if SinifOgrenciTable.List.Current.SinifOgrenci.OgrenciId does indeed have a corresponding picture.

The way I suggest to do this is to also add the OgrenciPicture Entity to the Preparation query (with join "Ogrenci with or without OgrenciPicture") and make the IF fall back to display the sillouete "default" image (by adding a "normal" non-DB image of DefaultOgrenciPicture) if GetSinifOgrencisBySezonId recorld list has, say, Filename <> "".

Let me know if this helped,


Miguel

[EDIT] - clarified one of the paragraphs after looking more at the eSpace.
Thanks for your reply Miguel.

I did your suggestions except the IF Fall back.

I put the picture widget in a IF container. And added the OgrenciPicture Entity to the Preparation query (with join "Ogrenci with or without OgrenciPicture").

Where wil I make the IF Fall back?

I am still getting the same error without it.

I attached the revised eSpace.

Armagan
I found something which would help.

When I test the preparation query GetSinifOgrencisBySezonId, OgrenciPicture.Id returns with a "0" value for each student that does not have a picture uploaded.

So PICTURE widget looks for a picture with an identifier of "0". Of course there is no such record.

Something to prevent this?

[EDIT] I attached the final version of the eSpace.
Hi Rifat,

I believe the problem you're getting is that, even though you correctly placed the images inside the IF, the IF condition is still unprotectedly trying to fetch the image with no previous knowledge if this row's image exists.

I have made a few changes to the 189 version of the eSpace that hopefully will fix it (I did not make it to the v217 you just sent because you seem to have reverted quite a lot of the work on this screen). In a nutshell, so you can double check, here's what I did:

1) I added the OgrenciPicture Entity as an outer join on the main query (GetSinifOgrencisBySezonId) that you had already feeding the Table Record (as you did later on v217);
2) I removed the new query GetOgrenciPictures that you had added (it is not needed, and you have removed it in v217 anyway);
3) I changed the IF condition (to SinifOgrenciTable.List.Current.OgrenciPicture.Filename <> "")  to check if this row does indeed have a picture by seeing if the join above returned anything (this assumes that ALL existing pictures have their filename set);
4) If the row has a corresponding picture, the IF will render the Database picture (btw, I changed the Filename prop of the IMAGE widget to feed off of that same SinifOgrenciTable.List.Current.OgrenciPicture.Filename value) otherwise the IF will render the static image you correctly added;

I also noted that on the S.No expression you were using GetSinifOgrencisBySezonId.List.CurrentRowNumber+1 - I'm pretty sure you meant SinifOgrenciTable.List.CurrentRowNumber+1 here so I also changed that.

I have not tested the eSpace in runtime but hopefully it will work. Let me know if it does and if you understood what I am trying to accomplish here.

Cheers,


Miguel
SOLVED! It works like a charm!!!

I think using GetOgrenciPicture(SinifOgrenciTable.List.Current.SinifOgrenci.OgrenciId).OgrenciPicture.Filename instead of SinifOgrenciTable.List.Current.OgrenciPicture.Filename was one of the main faults. Huh?

Thank you a lot Miguel.

Armagan