Silverlight error + Cannot perform runtime binding on null reference - silverlight-3.0

In my crm application , i have an old silverlight webresource in the form of a grid which sets data in a field on the form.
However when the record is created freshly, and if the user adds data into the silverlight grid, while setting value in the crm field, it throws the error as "Cannot perform runtime binding on Null reference"
Below is the line at which it throws the error .
dynamic att = Xrm.Page.data.entity.attributes.get("new_crmfield");
As per my understanding , it does not find the field at first, however how do i resolve this.
Please suggest.

Related

Breeze and empty string (server side)

Is there a way to make breeze api on server treat empty strings as null?
This is default behaviour for binding models in ASP. Now it's broken with the usage of BreezeController and EFContextProvider.
UPDATE:
I'm using breezejs with knokout. The error ocurred with email field: this field is not required, but empty string is validated by .NET EmailAddressAttribute.
The situation: user changes settings that has this email field. If field is not changed it remains null, but when it has been changed and cleared then on saving server throws validation error for this field.
ApiController would have binded entity and cleared empty strings for me, but BreezeController does not do this. Now I have to manually clear empty strings in EFContextProvider.BeforeSaveEntity.

How can I use a shared error message Dialog in PrimeFaces

In PrimeFaces, when you want to show an error Message you can:
create in View a command Component that calls an action
in 'update' attribute, you set the id of the p:message or p:growl component that will display the message
in The backing Bean, in the action function you throw a message
As a result, the error message will be displayed in the redirect page, in the message component with the matching id
But what if :
You want to display the message in another page, that doesn't contain the command component that called the action.
The action can redirect to lots of different pages, depending on some Backing bean Logic.
The action is not called from a command Component, at least not directly
I've thought of putting a p:message component with a specific id, and include it in every xhtml page. But this would not necessarily cover the 3rd scenario.
For example, there could be a function that checks the connection to another Web Service. A Connection error could be thrown from lots of different Actions.
Or a session expiration
Or a denial of permission
How would you manage this kind of generic error messages ?
You could put the common <p:dialog> or <h:message> in a template file which is being used for all pages and give it a unique id. That way, it will be rendered for all the pages using that template.
This, is assuming that you're using templates that is.
UPDATE: If you wish to programmatically update the component, you can do so using RequestContext#update()
For e.g.
if (someErrorCondition) {
RequestContext.getCurrentInstance().update("errorDialogId");
}
where errorDialogId is the ID of the common error dialog.
If you intend to use this approach, you need to remove the update atribute from your command component.
See Also
Calling Primefaces dialog box from Managed Bean function
Why not use the RequestContext#showMessageInDialog(FacesMessage)?
As per their User Guide:
Displaying FacesMessages in a Dialog is a common case where a
facesmessage needs to be added to the context first, dialog content
containing a message component needs to be updated and finally dialog
gets shown with client side api. DF (Dialog Framework) has a simple utility to bypass
this process by providing a shortcut;
Using this you don't need to have additional codes to put in every page you have. Just add it in your beans.

Infragistics grid's GET returning empty response

I'm trying to use Infragistics' grid to display a list of items from my Database. I'm using code-first method with Entity Framework in an MVC application with Razor engine. Every thing is working fine in the view except the Infragistics grid.
Here is my home view:
#using Infragistics.Web.Mvc
#model IEnumerable<BusinessModel.Models.TestPlan>
#{
ViewBag.Title = "Home";
}
#( Html.Infragistics().Grid<BusinessModel.Models.TestPlan>(Model)
.AutoGenerateColumns(true)
.DataSourceUrl(Url.Action("igListTestPlan"))
.DataBind()
.Render())
Here is my controller:
[GridDataSourceAction]
public ActionResult igListTestPlan()
{
return View(service.getListTestPlan());
}
Using firebug I can clearly see that the request is sent with a status code "200 OK", but the response tab is empty. It also causes an error in the console (in infragistics.js):
Uncaught TypeError: Cannot read property 'length' of undefined
I guess it's because of the empty response.
What I tried:
Debugging my controller showed me that return View(service.getListTestPlan()); doesn't return an empty list: I have 3 valid items in.
I also tried Html.Infragistics().Grid<BusinessModel.Models.TestPlan>(Model__.ToList()) but nothing changed. Also Html.Infragistics().Grid(Model) tells me I've got invalid parameters
Thanks in advance.
I think I have a pretty good idea why you are getting this, happened to me as well.
The MVC wrappers provide defaults for the way the grid model handles data on the server (serializing the data source to an object with 'Records' of your data and supportive 'Metadata'). However, if you do that yourself since you don't define a key of your own you are stuck with a default key 'Records' that is used to filter the response and since it's not there..well you get 'undefined' data fed to the grid :)
So solutions:
1) Wrap your response and define matching key using the "ResponseDataKey" property of the grid. I am suggesting this because as far as I recall it's a good practice to wrap responses in a single object - think there were some security implications.
2) If you don't feel like doing this and just want to get it working now then set the "ResponseDataKey" to empty string ("" will do) so your response will be properly filtered(or rather not).
On the second part of binding the grid directly to model data in the view - you are correctly getting the error as far as I see. The DataSource property explicitly states the source must implement IQueryable instead of IEnumerable. Slap a .AsQueryable() in there and that should work fine as well.
Let me know if this helps :)

Strange MVC problem in VB.NET application with EditorFor method

I have a VB.NET MVC application and there I have the next code:
<%=Html.EditorFor(Function(m) m.UserName, New With {.class = "someClassName"})%>
which works fine on my dev machine, but returns this error after publishing the application to a QA server:
Compiler Error Message: BC30311: Value
of type ' (line 91)'
cannot be converted to 'String'.
Also if I remove the second param in EditorFor method, it works, e.g.:
<%=Html.EditorFor(Function(m) m.UserName)%>
The error is same for Editor method.
Any ideas?
This is MVC 2 application on .NET 3.5
Update:
The problem not in name of the 'class' attribute in this case, as I checked other attributes as well without success.
The method EditorFor doesn't have the overload you are using.
The ones that have two arguments are:
EditorFor(Expression<Func<TModel, TValue>>, Object)
where the object is additional view data.
EditorFor(Expression<Func<TModel, TValue>>, String)
where the string is the template name.
The sad thing is that there isn't any overload that lets you add html attributes.

MVC Validation Error Messages not hardcoded in Attributes

I have a requirement that the validation error messages that are passed to my view come from the database.
I want to use data annotation on my model but the error message key in validation attributes can only be a string or a constant.
I'm open to other solutions for validation but I need to pull the error messages from the database.
Are there any other ellegent solutions for validation were the error message is not a string? Right now I am thinking about using T4 to generate a constants file...
My specific problem can be solved by using the ASP.NET MVC2 Metadata and Model Validation Providers.
Here are the articles that got me started:
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html
http://dotnetslackers.com/articles/aspnet/customizing-asp-net-mvc-2-metadata-and-validation.aspx
http://haacked.com/archive/2009/10/01/asp.net-mvc-preview-2-released.aspx
You could overload the validation runner to swap out error messages with ones from a database.

Resources