How to use FormComponentPanel for FileUpload Field in Apache wicket 9.x? - file-upload

I am trying to create FileUploadPanel that can be used in the form.
But however at runtime I facing some conversion error, I did debug the code it is going to the ConverterLocater.class in the wicket-core jar there it fails on the typecasting.
So when I debug I found filename is passed a in the below method public C convertToObject(String value, Locale locale) and in the conversion it fails because the value is string and it trying to caste to fileUpload.class.
Error:
throw (new ConversionException("Could not convert value: " + value + " to type: " + theType.getName() + ". Could not find compatible converter.")).setSourceValue(value);
Here value is passed as file name and theType is FileUpload.
I referred some examples, there setType is mandatory so I tried to set with String.class
but again next time fileUpload class was failing.
Could not convert value: test.pdf to type: org.apache.wicket.markup.html.form.upload.FileUpload. Could not find compatible converter.

I found the solution
Model name parameter was the issue, after changing this to List it got fixed.
private List<FileUpload> fileUploads = new ArrayList<FileUpload>();
new MultiFileUploadField("fileField",new PropertyModel(this,"fileUploads"),maxFiles)

Related

How to fix 'The string was not recognized as a valid DateTime.' error in BizTalk Test map?

I'm working on a BizTalk orchestrations with a map which contains an XSLT script. When I launch the orchestration I got this error
Error encountered while executing the transform. Error: Unable to create the transform.
So I go back to the map
XSL transform error:
Unable to write output instance. Exception has been thrown by the target of an invocation. The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.
I already tried to do a ParseExact but got the same error
Here is my code to convert DateTime:
public string FormatDate(string inputDate)
{
System.DateTime date = System.DateTime.Parse(inputDate);
return date.ToString("yyyy-MM-dd");
}
...and the code I tried with ParseExact:
public string FormatDate(string inputDate)
{
System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.InvariantCulture;
System.DateTime date = System.DateTime.ParseExact(inputDate, "yyyyMMdd", culture);
return date.ToString("yyyy-MM-dd");
}
The expected result is to have the date with "yyyy-MM-dd" format.
The problem came from several scripting functoid with the same method name inside. Just gave each methods a different name and the errors has gone.
Thank you to all users for your time.

patching a collection to add a field

I'm wanting to patch a RavenDB to add a field to a collection but am just getting errors using the suggested syntax. (I'm probably not understanding what I'm supposed to use)
I've tried the following in the patch window but get error: ' "Message": "Deserializing Json object with empty string as property name is not supported."
'
store
.DatabaseCommands
.Patch(
new ScriptedPatchRequest
{
Script = "_.extend(this, { 'GroupPlayString': 'Group Play'});"
});
Use:
Script = "this.GroupPlayString = 'Group Play'"

SharePoint 2010: Error Mapping to Picture Hyperlink with SPMetal

Whenever I have a column of type hyperlink with the format set for pictures, I get an error whenever there is actually a value in that column.
The exception it throws is "Specified cast is not valid".
My thought is that the problem is either here (the FieldType being set to Url):
[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "FOO", Storage = "FOO_", FieldType = "Url")]
public string FOO
{
get
{
return this._FOO;
}
set
{
if ((value != this._FOO))
{
this.OnPropertyChanging("FOO", this._FOO);
this._FOO = value;
this.OnPropertyChanged("FOO");
}
}
}
Or here (it being cast to a string):
private string _FOO;
But I'd have no idea what the proper values for either of those fields should be.
Any help would be greatly appreciated.
It works whenever this field does not have data in it and I JUST used SPMetal to generate the class, so I'll get the two most obvious questions out of the way.
Link to the answer:
https://mgreasly.wordpress.com/2012/06/25/spmetal-and-workflow-associations/
Turns out it is a known bug when mapping lists that have associated workflows.
SPMetal assigns it as a nullable integer when it's supposed to be an Object, hence the cast error.
Workaround: manually edit the mappings to make the type it returns an object or ignore the column by using a parameter map.

Stop WCF Deserializing Empty ICollection into Zero Capacity Array

I'm having a problem using WCF and Entity Framework 4.1 POCO objects (generated using T4 templates). My basic problem is that when sending a POCO object from my client to the service, WCF is deserializing a member variable of type ICollection as a fixed size array.
On the client side I can tell visual studio to use IList instead of T[] - but I cant see any option like this on the server end.
This causes no end of problems with several things, such as persisting these objects back to the database.
Is there any way to tell WCF what object type to deserialize ICollection (or any array) as?
I'm surprised that more folks haven't run into this issue, as it hits you smack in the face when you try to use the EF T4-generated POCO objects over WCF. Specifically, the error I was getting said something like:
Exception: "Unable to set field/property Orders on entity type Datalayer.Customers. See InnerException for details."
InnerException: "An item cannot be added to a fixed size Array of type 'Datalayer.Order[]'."
At any rate, the only solution I've been able to come up with is the one that you mention, namely, modifying the T4 templates to use HashSet instead of ICollection. Doesn't strike me as the cleanest, but it seems to work.
I'm using Entity Framework 6, and I was able to solve this issue by making the following changes in my T4 template.
I changed the following line where it creates the navigation properties to use a List instead of a collection from
navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,
to
navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("List<" + endType + ">") : endType,
Then I changed the code that sets the navigation property in the constructor to convert the default hashset to a list by adding a call to .ToList(). This line
this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();
was changed to
this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>().ToList();
The HashSet<>.ToList() method is an extension, so in order to make that extension method available, I added a using System.Linq statement by modifying the UsingDirectives method:
public string UsingDirectives(bool inHeader, bool includeCollections = true)
{
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion())
? string.Format(
CultureInfo.InvariantCulture,
"{0}using System;{1}" + Environment.NewLine +
"{0}using System.Linq;" +
"{2}",
inHeader ? Environment.NewLine : "",
includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",
inHeader ? "" : Environment.NewLine,
Environment.NewLine)
: "";
}

Linqpad - Outputting into anchor to use title

I have a db that stores exception messages.
I would like to create a query that gets these exceptions but instead of dumping huge amounts of text i would prefer it to be "on demand".
I figured putting the exception into an anchor tag like so and then reading the message when needed by mousing over it would work... apparently not.
var logsForErrors = (from error in Logs
select new {
error = LINQPad.Util.RawHtml("<a title='"+ error.Exception+"'></a>"),
errorDate = error.Date,
errorMessage = error.Message
}).Take(10);
logsForErrors.Dump();
This is throwing an exception (lol) - "Cannot parse custom HTML: "
Encoding the exception message
...RawHtml("<a title='"+ Uri.EscapeDataString(error.Exception)+"'></a>")
Message Could not translate expression 'RawHtml((("h__TransparentIdentifier0.error.Exception)) +
"'>"))' into SQL and could not treat it as a local expression.
will generate a new error
Any ideas? - I am open to alternative solutions to this also.
I just want a container for the message instead of it just dumping right into the output as it it so huge!.
Thanks,
Kohan
Have you tried using the "Results to DataGrids" mode in the recent betas? It might do just what you need without having to write anything else.
Edit: your error was probably due to emitting HTML without escaping the text. The easiest solution is to call Util.RawHtml with an XElement instead of a string. You could write an extension method that does what you want like this:
public static class Extensions
{
public static object Tooltipize (this string data)
{
if (string.IsNullOrEmpty (data) || data.Length < 20) return data;
return Util.RawHtml (new XElement ("span", new XAttribute ("title", data), data.Substring (0, 20)));
}
}
Put this into My Extensions and you can use it from any query.