I have following facelet code for JSF 1.2 application xhtml file :
<h:selectOneRadio value="#{cdM.val}">
<f:selectItems value="#{userBean.myBooleanValues}" />
</h:selectOneRadio>
The userBean.myBooleanValues method returns select Item as : new SelectItem(Boolean.TRUE, "Yes") and similar for "NO"
cdM.val is having type as : Object val;
I am getting below exception when above radio component is rendered on UI .
java.lang.IllegalArgumentException:Value is no String (class=java.lang.Boolean, value=true) and component form0: with path: .......does not have a Converter.
The most strange part is that , above exception disappears when jsf facelet jar version is : jsf-facelets-1.1.14.jar. (and appears for jsf-facelets-1.1.11.jar).
Do I need to write any convertor to deel with the exception
After a lot of search I resolved below issue like this :
<h:selectOneRadio value="#{cdM.val} converter="javax.faces.Boolean">
<f:selectItems value="#{userBean.myBooleanValues}" />
</h:selectOneRadio>
where cdM.val contains values : "Yes" or "No".
The convertor is used to convert values between String (cdM.val) and Boolean (userBean.myBooleanValues).
The exception got resolved.
Related
I am trying to use the excellent DataGrid available in the Extended WPF Toolkit Community Edition made available by Xceed (http://wpftoolkit.codeplex.com/). I have an application that displays the results from reports in a simple DataGridControl object. The user can select the report from a list of reports and the data grid dynamically updates using a DataTable associated to the report. The columns in each Report's DataTable can vary both in name and quantity. With the default controls in WPF this works just fine using regular MVVM data binding. This also works fine with the DataGridControl from Xceed, except for when a column has been used to sort or group the data.
What happens is when a column is sorted or grouped, and the DataTable is updated to one that doesn't have the column in it, the DataGridControl throws an ArgumentException saying the column being sorted doesn't exist. Here's an example exception:
System.ArgumentException was unhandled
Message='' type does not have property named 'SAP_MATERIAL_NUMBER', so cannot sort data
collection.
Source=PresentationFramework StackTrace:
at System.Windows.Data.BindingListCollectionView.ConvertSortDescriptionCollection(SortDescriptionCollection
sorts)
at System.Windows.Data.BindingListCollectionView.RefreshOverride()
at System.Windows.Data.CollectionView.Refresh()
at System.Windows.Data.CollectionView.EndDefer()
at System.Windows.Data.CollectionView.DeferHelper.Dispose()
at System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView
view)
at System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable
value)
at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject
d, DependencyPropertyChangedEventArgs e)
...
Here's my current XAML that defines and binds the control:
<xcdg:DataGridControl
Grid.Row="2"
AutoCreateColumns="True"
AutoRemoveColumnsAndDetailConfigurations="True"
ReadOnly="True"
x:Name="xceedReportResult"
ItemsSource="{Binding SelectedReport.Report.Result}"
FontSize="11">
<xcdg:DataGridControl.View>
<xcdg:TableflowView
ShowRowSelectorPane="False"
IsAnimatedColumnReorderingEnabled="True"
HorizontalGridLineBrush="LightGray"
VerticalGridLineBrush="LightGray"
IsAlternatingRowStyleEnabled="True"
ShowScrollTip="False">
<xcdg:TableflowView.Theme>
<xcdg:ClassicSystemColorTheme />
</xcdg:TableflowView.Theme>
</xcdg:TableflowView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
...following some advice from the Xceed forums I've tried running the following code when a new report is selected in hopes of clearing out any SortDescriptions or GroupDescriptions, but this isn't working right:
ICollectionView source = xceedReportResult.ItemsSource as DataGridCollectionView;
if (source != null)
{
if (source.SortDescriptions != null)
{
source.SortDescriptions.Clear();
}
if (source.GroupDescriptions != null)
{
source.GroupDescriptions.Clear();
}
}
Has anyone used this data grid in this way, and found a way around this issue?
I think I found my issue, or at least a way to handle this without having exceptions be thrown. I modified by XAML code to use an explicit DataGridCollectionViewSource declaration for my grid:
<Control.Resources>
<xcdg:DataGridCollectionViewSource
x:Key="reportResultView"
x:Name="reportResultView"
Source="{Binding SelectedReport.Report.Result.DefaultView}"
AutoCreateItemProperties="True"/>
</Control.Resources>
and then update my DataGridControl to use this as the ItemsSource instead of binding directly to the DataTable:
<xcdg:DataGridControl
Grid.Row="2"
AutoCreateColumns="True"
AutoRemoveColumnsAndDetailConfigurations="True"
ReadOnly="True"
x:Name="xceedReportResult"
ItemsSource="{Binding Source={StaticResource reportResultView}}"
FontSize="11">
<xcdg:DataGridControl.View>
<xcdg:TableflowView
ShowRowSelectorPane="False"
IsAnimatedColumnReorderingEnabled="True"
HorizontalGridLineBrush="LightGray"
VerticalGridLineBrush="LightGray"
IsAlternatingRowStyleEnabled="True"
ShowScrollTip="False">
<xcdg:TableflowView.Theme>
<xcdg:ClassicSystemColorTheme />
</xcdg:TableflowView.Theme>
</xcdg:TableflowView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
Once I do that it no longer throws exceptions if the sorted or grouped column(s) don't exist, and the data grid updates as expected.
I am using Mvc 4 with Json.Net. I have an error message property with the follong content on the server:
"'Instalation Name' should not be empty."
On the client I am doing something like this:
'#Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(this.Model, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.Converters.StringEnumConverter()))';
and the output is the following:
"ErrorMessage":"'Instalation Name' should not be empty."
which is throwing error:
Expected ';'
I need a way to escape or remove the ' character. How can I do this? One way is to do custom JsonConverter ... Any other suggestions? Thanks!
I guess your #Html.Raw() is placed within <script></script>. So I suggest you just remove the ' characters around your JSON, so it looks like this:
<script type="text/javascript">
var v = #Html.Raw(...);
</script>
So the the variable v will receive the deserialized data directly.
i have an asp,net textbox like this
<asp:TextBox readonly="true" ID="txtLastService" runat="server"></asp:TextBox>
when i tried to get its value to a date variable LastService in code behind, i get this error
Conversion from string "" to type 'Date' is not valid.
Exception
Details: System.InvalidCastException: Conversion from string "" to
type 'Date' is not valid.
Source Error: Line 26: oItem.LastService = txtLastService.Text Source File: .\admin\vehicle\add.aspx.vb Line:
26
i have used this same code in other pages, and it works fine, except for this page
any help
EDIt
Please note that the value of the textbox is not empty when i click submit on the form. And also when i remove the readonly attributes, i don;t get the error. But i need this textbox to be readonly since am using javascript to select date and setting its value
Instead of Readonly="true", try using Enabled="false"
The error seems extremely self-explanatory to me. The string is "" and you are trying to convert it to a Date. So how the heck can an empty string be converted to a Date? What date would that be?
Why not use a HiddenField instead?
<asp:hiddenfield id="txtLastService" runat="server"/>
Try using Request.Form[txtLastService.UniqueID] if C# and
Request.Form(txtLastService.UniqueID) if vb.net
I've used EF4 EntityDataSources to do DataBinding with success, but here's a case where I'm stumped:
Table "CurrentComplaintsByUsers" has a foreign key over to a "Complaints" table. So in EF, I can access a CurrentComplaintByUser record, and navigate to its parent complaint like so:
var ccU = dataContext.CurrentComplaintsByUsers.First();
var parentComplaint = ccU.Complaint;
When I whip up an EntityDataSource based on CurrentComplaintsByUsers to bind a gridview, I want to get over from the "Complaint" object to an Assocation of Complaint called "Status". Here's a StatusID in my Complaint table, and so in code I can hit a complaint's status like so, including the Status properties:
string statusLabel = parentComplaint.Status.LabelText;
FAILURE: when I try to bake this all into an EntityDataSource, I can't get from my starting item "CurrentComplaintsByUsers" over to "Status". Here's my EDS:
<asp:EntityDataSource ID="edsCurrentCases" runat="server"
ConnectionString="name=EOCaseDataModel" DefaultContainerName="EOCaseDataModel"
EnableFlattening="False" EntitySetName="CurrentComplaintsByUsers"
Include="Complaint, Status">
</asp:EntityDataSource>
My error is this:
System.InvalidOperationException
"A specified Include path is not valid.
The EntityType 'EOCaseApp.CurrentComplaintsByUser' does not declare a navigation property with the name 'Status'."
I'm trying to get to the point where this works in my Gridview:
<%# ((CurrentComplaintsByUser)Container.DataItem).Complaint.Status.LabelText %>
So, using declaritive markup only, how do I get to a related objects associations from the EDS? (I can do it in code, just trying to use the EDS exclusively when I can)
Other notes: if I remove "Status" from the "Include" in the EDS, then I get a NULL ERROR when it hits ..Complaint.Status.LabelText in my Gridview, pretty much what you'd expect.
Try changing Include="Complaint, Status" to Include="Complaint, Complaint.Status" in your EntityDataSource
I'm working on Flex application and I need to open a Java Applet from Flex (e.g. clicking a button). In particular I'd like to open imageJ, a particular imaging program that could work as application, applet or be integrated in a web page. Is there a way to call it from Flex? I've seen a couple of tutorials that explain how to call a single function in another Java file from Flex, but I'm not so sure that it is what I'm looking for.
Thanks for your answers,
cheers,
David
I don't know if there's a better way, but if I was doing it, I'd write a JavaScript function that would load the Java applet (could be as simple as document.write("<object …>")), then use Flex's ExternalInterface to call that JavaScript.
Expose a public method in your applet, which the flex would call. You could load the applet the following way. It is a sample program, to call java methods and get a value from java, you can do changes as per your need
<object
id = "MyApplet"
name = "Some name"
classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height="0">
<PARAM NAME = "CODE" VALUE = "com.my.applet.MyApplet.class" >
<PARAM NAME = "CODEBASE" VALUE = "." >
<PARAM NAME = "ARCHIVE" VALUE = "applet-client.jar" >
<PARAM NAME = "cache_option" VALUE="No">
<PARAM NAME = "java_version" VALUE="1.6+">
<param name = "type" value = "application/x-java-applet;version=1.6">
<comment>
<embed
name = "MyApplet"
type = "application/x-java-applet;version=1.6" \
CODE = "com.my.applet.MyApplet.class" \
JAVA_CODEBASE = "." \
ARCHIVE = "applet-client.jar"
cache_option = "No"
scriptable = false
pluginspage = "http://java.sun.com/products/plugin/index.html#download"
width="0" height="0"
>
<noembed>
</noembed>
</embed>
</comment>
</object>
With the above in your html file( I am not explaining everything) , the applet will be downloaded and ready to use. Now on click of a button on your flex app, you should have something like below.
var returnedStringFrom java:String=ExternalInterface.call("document.MyApplet.functionInJava",stringParam);
Note : MyApplet is the name in the object declaration above, the functionInJava is a public function in the the java class com.my.applet.MyApplet. It takes a parameter and returns a string parameter. The Java program will look like below.
package com.my.applet;
public class MyApplet{
//other methods..
public String functionInJava(String stringpm){
// your implementation
return "SomeString";
}
}
Happy coding.