This is my code snippet:
final ListGrid subscriberGrid = new ListGrid();
subscriberGrid.setWidth(500);
subscriberGrid.setHeight(224);
subscriberGrid.setShowAllRecords(true);
subscriberGrid.setSelectionType(SelectionStyle.SIMPLE);
subscriberGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
ListGridField fnField = new ListGridField("fn", "First Name");
ListGridField lnField = new ListGridField("ln", "Last Name");
ListGridField emailField = new ListGridField("email", "E-mail");
subscriberGrid.setFields(fnField, lnField, emailField);
How do I enter values for it? I tried initiating a ListGridRecord[], but I was unable to fill any values properly. I also tried with a Javascript Object, but that also gave me an error. Googling also did not return satisfactory results.
TIA.
ahh Darn. I got the answer after asking it.
ListGridRecord temp = new ListGridRecord();
temp.setAttribute("fn", "foo");
temp.setAttribute("ln", "bar");
temp.setAttribute("email", "baz");
ListGridRecord[] record = { temp };
subscriberGrid.setData(record);
Sorry for the clutter ^-^
Related
I'm working on an application that needs to be able to insert messages into an O365 mailbox with particular dates (similar to a mail migration). I created a version using IMAP with MailKit, and that was a simple matter of setting the date property on the message object:
MimeMessage message = new MimeMessage();
message.From.Add(new MailboxAddress(NameGenerator.AnyName(), EmailAddressGenerator.AnyEmailAddress()));
message.To.Add(new MailboxAddress(m_O365UserID));
message.Subject = StringGenerator.AnyStringOfSizeAndCase(NumberGenerator.RandomNumberBetween(20, 100), CaseType.TitleCase);
BodyBuilder builder = new BodyBuilder
{
HtmlBody = LipsumGenerator.GenerateHtml(NumberGenerator.RandomNumberBetween(3, 10))
};
message.Body = builder.ToMessageBody();
DateTime t = DateTimeGenerator.AnyDateBetween(m_startDate, DateTime.Now);
t = t.Add(DateTimeGenerator.AnyTime());
DateTimeOffset dto = new DateTimeOffset(t);
message.Date = dto;
I was also able to do this in the past with EWS, but I needed to set some extended properties to do it, like this:
ExtendedPropertyDefinition deliveryTime = new Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x0E06, MapiPropertyType.SystemTime);
ExtendedPropertyDefinition clientSubmitTime = new Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x0039, MapiPropertyType.SystemTime);
ExtendedPropertyDefinition flags = new Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3591, MapiPropertyType.Integer);
EmailMessage m = new EmailMessage(m_exchangeService);
m.From = EmailAddressGenerator.AnyEmailAddress();
m.ToRecipients.Add(m_emailAddress);
DateTime t = DateTimeGenerator.AnyDateBetween(startDate, DateTime.Now);
t = t.Add(DateTimeGenerator.AnyTime());
m.SetExtendedProperty(deliveryTime, t);
m.SetExtendedProperty(clientSubmitTime, t);
m.SetExtendedProperty(flags, 1);
Both of these approaches can backdate a message to any point that I need. In this case I'm just populating a mailbox with test data to validate the API calls. Trying to do the same thing in graph like this:
Microsoft.Graph.Message message = new Microsoft.Graph.Message();
message.From = new Recipient { EmailAddress = new EmailAddress { Address = EmailAddressGenerator.AnyEmailAddress(), Name = NameGenerator.AnyName() } };
message.ToRecipients = new List<Recipient>();
message.ToRecipients.Append(new Recipient { EmailAddress = new EmailAddress { Address = m_O365UserID } });
message.Subject = StringGenerator.AnyStringOfSizeAndCase(NumberGenerator.RandomNumberBetween(20, 100), CaseType.TitleCase);
DateTime t = DateTimeGenerator.AnyDateBetween(m_startDate, DateTime.Now);
t = t.Add(DateTimeGenerator.AnyTime());
DateTimeOffset dto = new DateTimeOffset(t);
message.ReceivedDateTime = dto;
message.SentDateTime = dto;
message.CreatedDateTime = dto;
message.LastModifiedDateTime = dto;
timestamps the message as of the submission time. I thought I needed to set the same Mapi properties on the message as with EWS, but so far I haven't found a way to do that. I looked into extended properties as outlined here, which says they can be referenced by a type and MAPI property tag. This page says that extended properties can be created on new objects:
To create one or more extended properties in a new resource instance, use the same REST request as creating the instance, and include the properties of the new resource instance and extended property in the request body.
I tried that like this:
Dictionary<string, object> extendedProperties = new Dictionary<string, object>();
extendedProperties.Add("SystemTime 0x0E06",dto.DateTime);
extendedProperties.Add("SystemTime 0x0039", dto.DateTime);
extendedProperties.Add("Integer 0x3591",1);
message.Body = new ItemBody { ContentType = BodyType.Html, Content = LipsumGenerator.GenerateHtml(NumberGenerator.RandomNumberBetween(3, 10)), AdditionalData=extendedProperties};
Which throws an exception:
The property 'SystemTime 0x0E06' does not exist on type 'Microsoft.OutlookServices.ItemBody'. Make sure to only use property names that are defined by the type or mark the type as open type.
I also can't directly create anything on message.SingleValueExtendedProperties, and the same exception happens if I omit SystemTime and just try to set the property with the hex value. I'd like to be able to support Graph for this application-is there any way that anyone knows of to create messages with custom send/receive dates? If I was able to do it in EWS, I'd expect that the newer API should be able to do the same thing.
Edit
#Glen's answer works. I'd tried the same thing, but still had a second definition of the property that I was trying to add to the message body, which was what actually caused the exception. The only other thing to add to his answer is that the time format for the property needs to be in a very specific format, so you can format a standard DateTimeOffset to a mapi compatible time like this:
string mapiTime = $"{dto.UtcDateTime.Year}-{dto.UtcDateTime.Month.ToString("D2")}-{dto.UtcDateTime.Day.ToString("D2")}T{dto.UtcDateTime.TimeOfDay.ToString()}.0{dto.Offset.Hours.ToString("D2")}:00";
message.SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage()
{
new SingleValueLegacyExtendedProperty {Id = "Integer 0x0E07",Value = "1" },
new SingleValueLegacyExtendedProperty {Id = "SystemTime 0x0039", Value = mapiTime },
new SingleValueLegacyExtendedProperty {Id = "SystemTime 0x0E06",Value = mapiTime }
};
You should be able to do something like
Microsoft.Graph.Message message = new Microsoft.Graph.Message();
message.From = new Recipient { EmailAddress = new EmailAddress { Address = "blah#blah.com", Name = "blah" } };
message.ToRecipients = new List<Recipient>() { new Recipient { EmailAddress = new EmailAddress { Address = "ToBalh#blah.com" } } };
message.Subject = "Blah";
message.SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage()
{
new SingleValueLegacyExtendedProperty {Id = "Integer 0x0E07",Value = "1" },
new SingleValueLegacyExtendedProperty {Id = "SystemTime 0x0039", Value = "2020-05-12T10:10:47.2048+10:00" },
new SingleValueLegacyExtendedProperty {Id = "SystemTime 0x0E06",Value = "2020-05-12T10:10:47.2048+10:00" }
};
var SaveMessage = graphClient.Me.MailFolders["Inbox"].Messages.Request().AddAsync(message).Result;
works for me okay
I'm currently working on a JavaFX project.I'm using Autcomplete TextField of ControlFx .Each time i add new rows in database table, it should to update Autocomplete ,i did this but my problem is showing double Context-Menu ,we can say double autocompletes because i call method that create autocomplete each adding of new elements in table.
When i click a tab editBill i call this method :
public void showEditBill() {
if (!BillPane.getTabs().contains(EditBillTab)) {
BillPane.getTabs().add(EditBillTab);
}
SingleSelectionModel<Tab> selectionModel = BillPane.getSelectionModel();
selectionModel.select(EditBillTab);
/*it should remove the old autocomplete from textfield*/
pushBills(); //Call for cheking new items
}
pushBills method () :
public void pushBills() {
ArrayList list = new ArrayList<>();
bills = new BillHeaderDao().FindAll();
for (int i = 0; i < bills.size(); i++) {
list.add(bills.get(i).getIdClient());
}
//How can i remove the old bind before bind again
autoCompletionBinding = TextFields.bindAutoCompletion(SearchBill, SuggestionProvider.create(list));
}
How i can remove the old autocomplete and bind new automplete?
Just in any case if you need to keep instance of AutoCompletionTextFieldBinding object, thus avoiding use of:
autoCompleteBinding = TextFields.bindingAutoCompletion(TextField,List);
, which will change the instance, we could go a little bit deeper and use this:
// let's suppose initially we have this possible values:
Set<String> autoCompletions = new HashSet<>(Arrays.asList("A", "B", "C"));
SuggestionProvider<String> provider = SuggestionProvider.create(autoCompletions);
new AutoCompletionTextFieldBinding<>(textField, provider);
// and after some times, possible autoCompletions values has changed and now we have:
Set<String> filteredAutoCompletions = new HashSet<>(Arrays.asList("A", "B"));
provider.clearSuggestions();
provider.addPossibleSuggestions(filteredAutoCompletions);
So, through SuggestionProvider, we have "updated" auto completion values.
To avoid doubling of suggestions menu, don't use again (for the 2nd time):
TextFields.bindAutoCompletion(..)
In order to provide updates to the auto-complete suggestion list, retain a reference to the SuggestionProvider and update the suggestion provider instead:
TextField textField = new TextField();
SuggestionProvider suggestionProvider = SuggestionProvider.create(new ArrayList());
new AutoCompletionTextFieldBinding<>(textField, suggestionProvider);
When you want to update the suggestion list:
List<String> newSuggestions = new ArrayList();
//(add entries to list)
suggestionProvider.clearSuggestions();
suggestionProvider.addPossibleSuggestions(newSuggestions);
This will do the trick:
Instead of: TextFields.bindAutoCompletion(textField, list);
, try this:
List<String> strings = new ArrayList<>();
Then create binding between your textField with the list through:
new AutoCompletionTextFieldBinding<>(textField, SuggestionProvider.create(strings));
So any changes, including removing, from the list, will be reflected in the autoCompletion of the textField;
And you will have dynamic filtering of suggestions, showed in pop-up, when user enter some text in textField;
I had the same problem some time ago I try to do as #MaxKing mentions, but it didnt work. I managed to give it a soluciĆ³n even though I don't think it's the right way.
// Dispose the old binding and recreate a new binding
autoCompleteBinding.dispose();
autoCompleteBinding = TextFields.bindingAutoCompletion(TextField,List);
try this:
public void pushBills() {
ArrayList list = new ArrayList<>();
bills = new BillHeaderDao().FindAll();
for (int i = 0; i < bills.size(); i++) {
list.add(bills.get(i).getIdClient());
}
autoCompletionBinding.dispose();
autoCompletionBinding = TextFields.bindAutoCompletion(SearchBill, SuggestionProvider.create(list));
}
This is the scenario: I'm working with a listgrid that needs to be grouped, and also needs to have its records ordered within each group. I've already used the ListGrid.sort() and the ListGrid.sort(String, SortDirection) methods but none of them works properly.
This problem doesn't show up when the grid isn't grouped (it makes the sort perfectly); and when the sort (with the listgrid is grouped) is made by clicking the column header, works fine but I need to sort it by code (without user interaction) because the header sort option needs to be disabled (and context menu too).
I'm using SmartGWT 4.0
Here is the class I'm using:
public class Access extends ListGrid {
public Access() {
super();
setWidth("30%");
setHeight100();
// setShowHeaderContextMenu(false);
setCanResizeFields(false);
// setCanSort(false);
setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
setWrapCells(true);
setFixedRecordHeights(false);
setShowRecordComponents(true);
setShowRecordComponentsByCell(true);
ListGridField id = new ListGridField("id", "ID");
ListGridField user = new ListGridField("user", "User");
ListGridField access = new ListGridField("access", "Access");
id.setHidden(true);
user.setWidth("60%");
access.setWidth("40%");
access.setType(ListGridFieldType.BOOLEAN);
access.setCanEdit(true);
setFields(id, user, access);
groupBy("access");
access.setGroupTitleRenderer(new GroupTitleRenderer() {
public String getGroupTitle(Object groupValue, GroupNode groupNode, ListGridField field, String fieldName,
ListGrid grid) {
return (String) groupValue + " - " + groupNode.getGroupMembers().length;
}
});
getField("access").setGroupValueFunction(new GroupValueFunction() {
public Object getGroupValue(Object value, ListGridRecord record, ListGridField field, String fieldName,
ListGrid grid) {
Boolean access = (Boolean) value;
if (access)
return "With access";
else
return "Without access";
}
});
ListGridRecord lgr1 = new ListGridRecord();
lgr1.setAttribute("id", 1);
lgr1.setAttribute("user", "ewgzx");
lgr1.setAttribute("access", true);
ListGridRecord lgr2 = new ListGridRecord();
lgr2.setAttribute("id", 2);
lgr2.setAttribute("user", "Bgfths");
lgr2.setAttribute("access", false);
ListGridRecord lgr3 = new ListGridRecord();
lgr3.setAttribute("id", 3);
lgr3.setAttribute("user", "utcvs");
lgr3.setAttribute("access", true);
ListGridRecord lgr4 = new ListGridRecord();
lgr4.setAttribute("id", 4);
lgr4.setAttribute("user", "gfdjxc");
lgr4.setAttribute("access", false);
ListGridRecord lgr5 = new ListGridRecord();
lgr5.setAttribute("id", 5);
lgr5.setAttribute("user", "763");
lgr5.setAttribute("access", true);
ListGridRecord lgr6 = new ListGridRecord();
lgr6.setAttribute("id", 6);
lgr6.setAttribute("user", "2");
lgr6.setAttribute("access", false);
ListGridRecord lgr7 = new ListGridRecord();
lgr7.setAttribute("id", 7);
lgr7.setAttribute("user", "35");
lgr7.setAttribute("access", false);
ListGridRecord lgr8 = new ListGridRecord();
lgr8.setAttribute("id", 8);
lgr8.setAttribute("user", "123");
lgr8.setAttribute("access", true);
ListGridRecord lgr9 = new ListGridRecord();
lgr9.setAttribute("id", 9);
lgr9.setAttribute("user", "2342");
lgr9.setAttribute("access", true);
ListGridRecord lgr10 = new ListGridRecord();
lgr10.setAttribute("id", 10);
lgr10.setAttribute("user", "aqwc");
lgr10.setAttribute("access", false);
setRecords(new ListGridRecord[] { lgr1, lgr2, lgr3, lgr4, lgr5, lgr6, lgr7, lgr8, lgr9, lgr10 });
sort("user", SortDirection.ASCENDING);
}
}
I have been having a similar issue. Disclaimer: if the "grouping data" message is not appearing when you group then the following solution may not help.
In my case the sorting of a grouped column was screwed because of the "grouping data" pop up.
Let me clarify.
The "grouping data" pop up appears when trying to group a ListGrid that is displaying more than 50 records.
It appears because the ListGrid, internally, is doing the grouping operation asynchronously to avoid the "script running slowly" message from the browser.
What I did was to set the grouping async threshold to a higher value. The risk of doing this is getting the "script running slowly" browser message, even though this is likely to happen only with IE8/9.
In the end , in the grid constructor, just add (I used 500 as a threshold):
setInitialSort(new SortSpecifier[] {new SortSpecifier("user", SortDirection.ASCENDING)}));
setGroupByField("access");
setGroupByAsyncThreshold(500);
Also set the initial sort and the grouped column as shown above.
PROGRAMMATICALLY, FIRST SORT, THEN GROUP.
Hope this helps.
This is due to sort() being called before rendering the grid, and setRecords() complicates things further.
Initial rendering of the grid happens along with its parents when rootCanvas.draw() is called (in onModuleLoad or similar).
As setRecords() can be used to change data set in the grid anytime, it tries to redraw the grid regardless of whether its initial stage or not.
If in the real scenario, sort is triggered after UI initialization, it should work as given in following code sample.
Remove the sort() call at the end of the constructor.
final Access access = new Access();
Button button = new Button("Sort");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// toggle sort direction, using two different ways to do it
SortSpecifier sortSpecifier = access.getSortSpecifier("user");
if (sortSpecifier == null || SortDirection.DESCENDING.equals(sortSpecifier.getSortDirection())) {
access.sort("user", SortDirection.ASCENDING);
} else {
access.setSort(new SortSpecifier[]{
new SortSpecifier("user", SortDirection.DESCENDING)
});
}
}
});
Check http://www.smartclient.com/smartgwt/showcase/#grid_multilevel_sort to see how to use listGrid.setInitialSort().
Having setRecords() in the constructor could lead to other initialization issues as well.
Update
To have the grid grouped by and sorted on load, set an initial sort and a group by field as indicated below.
// along with other configuration methods, can not use after grid is drawn
SortSpecifier sortSpecifier = new SortSpecifier("user", SortDirection.ASCENDING);
setInitialSort(new SortSpecifier[]{sortSpecifier});
// use following instead of groupBy(), which is used to group the grid programmatically
// groupBy() causes a redraw
setGroupByField("access");
An overloaded ListGrid.setGroupByField(String... field) method is available to group by multiple fields.
I have a RootElement declared and set up how I want on a DialogViewController, using the element-based API rather than the reflection API. Looks great.
However I'm struggling to work out how I can get the values out. Using the reflection-based API this is easy, but I don't see how I can use BindingContext.Fetch() with an explicitly declared RootElement.
I can't find an example in the samples, nor can I work out how to do this myself.
var root = new RootElement(null){
new Section(){
new StringElement("Title here"),
new FloatElement(null, null, 5f)
}
};
var dv = new DialogViewController(root, true);
dv.ViewDisappearing += delegate {
// what goes here to get at the value of the FloatElement?
};
NavigationController.PushViewController(dv, true);
Any help appreciated.
You can store it in a variable, that is scoped where your anonymous method can access it.
Like this:
var floatElement = new FloatElement(null, null, 5f);
var root = new RootElement(null){
new Section(){
new StringElement("Title here"),
floatElement,
}
};
var dv = new DialogViewController(root, true);
dv.ViewDisappearing += delegate {
//You can access floatElement here
Console.WriteLine(floatElement.Value);
};
NavigationController.PushViewController(dv, true);
I'm new to Linq. I have searched and searched the web for a solution, and can't find anything. I have a Linq query and I want to insert a row ("Select User") to the top before I pass it to the drop down list. I've been trying to use the Union but to now avail (it keeps telling me that my object doesn't support the Union method). My code, prior to attempting to insert a row, is very simple.
public SelectList DropDown_Users()
{
var context = new VivarianDataContext();
var query = from t in context.AspnetUsers
select new { t.UserId, t.LastName };
list = new SelectList(query.AsEnumerable(), "UserId", "LastName");
return list;
}
Now I try to insert a row and I found this on the internet and it seems to say that his solution will work. But it is filled with errors. http://magicode.wordpress.com/2009/08/20/inserting-an-item-in-iqueryable-object-using-union-method-and-linq/
I tried to implement it using the following code, but it doesn't compile.
public SelectList DropDown_Users()
{
SelectList list;
//get the original data
var context = new SQL2005633131VivarianDataContext();
var query = from t in context.AspnetUsers
select new { t.UserId, t.LastName };
//create a dummy table with an empty row
var AllUsers = new List<AspnetUsers>();
var BlankUser = new AspnetUsers()
{UserId=System.Guid.Empty, LastName="Select One"};
AllUsers.Add(BlankUser);
//use Union to join the data - ERRORS HERE - doesn't support Union
var newTable = AllUsers.Union(query);
list = new SelectList(newTable.AsEnumerable(), "UserId", "LastName");
return list;
}
So tired I'm going blind. Any help?
You don't need to touch the query result. You can add that default option "Select User" in the dropdownlist.
Try this:
How can I add an item to a SelectList in ASP.net MVC