I know I can have SimpleType values like SimpleType.INTEGER, SimpleType.STRING in a CompositeData. But I wonder how do I get another instance of CompositeData into CompositeData. E. g.:
CompositeType type = new CompositeType("My Type", "My Type", new String[]{"item1", "item2"}, new String[]{"item1", "item2"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING});
CompositeData data = new CompositeDataSupport(type, new String[]{"item1", "item2"}, new String[]{"item value 1", "item value 2"});
CompositeType compType = new CompositeType("compData", "compData", new String[]{"compItem1"}, new String[]{"compItem1"}, new OpenType[]{I_DONT_KNOW_WHAT_TO_PUT_HERE});
CompositeData compData = new CompositeDataSupport(compType, new String[]{"compData"}, data);
See the "I_DONT_KNOW_WHAT_TO_PUT_HERE" above, I could not find out how to pass an OpenType of CompositeData. And I have seen an examples of recursively getting the instances of nested CompositeData from CompositeData.
Some references:
http://docs.oracle.com/javase/6/docs/api/javax/management/openmbean/CompositeData.html
http://docs.oracle.com/javase/6/docs/api/javax/management/openmbean/CompositeType.html
http://docs.oracle.com/javase/6/docs/api/javax/management/openmbean/OpenType.html
The value of I_DONT_KNOW_WHAT_TO_PUT_HERE is type, but the 2nd argument in the constructor on code line 4 should have the string "compItem1", not "compData" since this represents the item name you defined in the 3rd parameter on code line 4.
Here's the full code:
CompositeType type = new CompositeType("My Type", "My Type", new String[]{"item1", "item2"}, new String[]{"item1", "item2"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING});
CompositeData data = new CompositeDataSupport(type, new String[]{"item1", "item2"}, new String[]{"item value 1", "item value 2"});
CompositeType compType = new CompositeType("compData", "compData", new String[]{"compItem1"}, new String[]{"compItem1"}, new OpenType[]{type});
CompositeData compData = new CompositeDataSupport(compType, new String[]{"compItem1"}, new Object[]{data});
Have you considered using MXBeans ? Unless you really need all that additional meta-data, it's a much simpler (and maintainable) way to go for exposing complex attributes in JMX.
Related
Hi I am trying develop a feature something as below in the picture. When I am selecting option(Ex: Monthly) from left panel right side panel will automatically render the required components. When I select the option from the right side panel I want to type the required values in input box. When I click on input box I am not getting the focus to type. Facing same issue for Combobox as well. Attaching some code snippet as well.
radioGroup = new RadioButtonGroup<>();
radioGroup.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);
radioGroup.setItems("None", "Daily", "Weekly", "Monthly");
radioGroup.setValue("None");
VerticalLayout leftLayout = new VerticalLayout();
VerticalLayout rightLayout = new VerticalLayout();
radioGroup.addValueChangeListener(event -> {
if (event.getValue().equalsIgnoreCase("Monthly")) {
monthlyRadioGroup = new RadioButtonGroup<>();
monthlyRadioGroup.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);
monthlyRadioGroup.setItems("Day", "The");
monthlyRadioGroup.setValue("Day");
monthlyRadioGroup.setRenderer(new ComponentRenderer<>(item -> {
if ("Day".equals(item)) {
HorizontalLayout dayLayout = new HorizontalLayout();
IntegerField dayField = new IntegerField();
dayField.setValue(1);
dayField.focus();
dayField.setAutofocus(true);
dayField.setWidth("50px");
IntegerField monthField = new IntegerField();
monthField.setValue(1);
monthField.setWidth("50px");
dayLayout.add(new Label("Day"), dayField, new Label("of every"), monthField, new Label("month(s)"));
dayLayout.setAlignItems(Alignment.CENTER);
return dayLayout;
}else {
HorizontalLayout weekDayLayout = new HorizontalLayout();
ComboBox<String> weekNum = new ComboBox<String>();
weekNum.setItems("First", "Second", "Third", "Fourth", "Last");
weekNum.setValue("First");
weekNum.setWidth("100px");
ComboBox<String> day = new ComboBox<String>();
day.setItems("Day", "Weekday", "Weekend Day", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
day.setValue("Friday");
day.setWidth("120px");
IntegerField monthField = new IntegerField();
monthField.setValue(1);
monthField.setWidth("50px");
weekDayLayout.add(new Label("The"), weekNum, day, new Label("of every"), monthField,
new Label("month(s)"));
weekDayLayout.setAlignItems(Alignment.CENTER);
return weekDayLayout;
}
}));
rightLayout.add(monthlyRadioGroup);
}
});
It worked by adding below snippet in all the input fields
dayField.getElement().addEventListener("click", e -> dayField.focus());
I am trying to achieve the task of binding a dataset to a webgrid.
As per my knowledge, Webgrid accepts only model as datasource. But I need to acheive it using a dataset. I have created a Dataset property on the model itself.
Please do guide me. I am a newbie.
TIA
The WebGrid is not able to extract data from a dataset (or more properly, as datatable). You can use LINQ to DataSet to transform your data an IEnumerable. Borrowing the DataTable example from Dotnet Perls, here's how you might do that:
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
// Here we add five DataRows.
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
var data = table.AsEnumerable().Select(r => new {
Dosage = r.Field<int>("Dosage"),
Drug = r.Field<string>("Drug"),
Patient = r.Field<string>("Patient"),
Date = r.Field<DateTime>("Date")
});
var grid = new WebGrid(data);
Public Function GetSubjectList(ci As CultureInfo, EACode As String) As IEnumerable(Of SelectListItem)
Dim items
Dim innerQuery = (From c In _context.TblSchoolDatas
Where c.EACODE = EACode And c.AnalystedStudents >= 10
Select (c.SubjectID)).Distinct()
items = From s In _context.TblSubjects
Where innerQuery.Contains(s.SubjectID)
Order By s.Ordering
Select New SelectListItem With {.Text = s.ShortNameE, .Value = s.SubjectID}
**items.Insert(0, New SelectListItem() With {.Text = "All", .Value = "All"})**
Return items
End Function
Public member 'Insert' on type 'DbQuery(Of SelectListItem)' not found.
The error showed in bold, thanks
One more debug screen shot for your reference
http://i.imgur.com/GsX1NqP.png
You are trying to Insert into a LINQ expression. Try
items.ToList();
before
items.Insert()
I'm looking around for a good example to work with TFS 2010 collections,projects, and workitems to start with.
I am able to iterate through collections and Projects using the following code (thanks to original coder)
Dim tfsServer As String = "http://test.domain.com:8080/tfs"
tfsServer = tfsServer.Trim()
Dim tfsUri As Uri
tfsUri = New Uri(tfsServer)
Dim configurationServer As New TfsConfigurationServer(tfsUri)
configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri)
' Get the catalog of team project collections
Dim collectionNodes As ReadOnlyCollection(Of CatalogNode)
Dim gVar As Guid() = New Guid() {CatalogResourceTypes.ProjectCollection}
collectionNodes = configurationServer.CatalogNode.QueryChildren(gVar, False, CatalogQueryOptions.None)
Dim strName As New StringBuilder
Dim strCollection As New StringBuilder
For Each collectionNode In collectionNodes
Dim collectionId As Guid = New Guid(collectionNode.Resource.Properties("InstanceID"))
strName.Length = 0
Dim teamProjectCollection As New TfsTeamProjectCollection(tfsUri)
teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId)
Response.Write("Collection:" & teamProjectCollection.Name & "<br/>")
' Get a catalog of team projects for the collection
Dim hVar As Guid() = New Guid() {CatalogResourceTypes.TeamProject}
Dim projectNodes As ReadOnlyCollection(Of CatalogNode)
projectNodes = collectionNode.QueryChildren(hVar, False, CatalogQueryOptions.None)
' List the team projects in the collection
For Each projectNode In projectNodes
strName.AppendLine(projectNode.Resource.DisplayName & "<br>")
'System.Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName)
Next
Response.Write(strName.ToString())
Next
I want to read specific project from a collection and iterate through workitems (tasks,bugs,issues,etc). Any help would be highly appreciated.
Thanks.
You can run any query you like in the teamProjectCollection - level with:
WorkItemStore workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
WorkItemCollection queryResults = workItemStore.Query(query);
foreach (WorkItem workitem in queryResults)
{
Console.WriteLine(workitem.Title);
}
Now you only have to formulate the query - string in something that provides you with what you need.
Queries are WIQL - like. This very basic can give you all work items within a TeamProject:
SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItems WHERE [System.TeamProject] = #project
#project is in our case here the projectNode.Resource.DisplayName
(You can save any query you 've graphically set in TFS with 'Save as' as a *.wiq file & then use it's content programmatically)
I'm having problems with getting items in a multiselect to get selected.
I have this:
BookingObject bo = _bs.GetBookingObjects(bookingobjectID.Value).FirstOrDefault();
bo.BookingViews.Load();
MultiSelectList BookingViewsBookingObjects = new MultiSelectList(_bvs.GetBookingViews(), "BookingViewID", "BookingViewName", (IEnumerable<BookingView>)bo.BookingViews.ToList());
BookingViews <-> BookingViewsBookingObjects <-> BookingObjects
Its a many to many relationship. _bvs.GetBookingViews() returns IQueryable of BookingView, and I cant seem to get the items from bo.BookingViews selected.
What might be missing here? am I using the wrong type?
/M
Maybe you need to send the actual selected value in the last parameter the "BookingViewID" instead of the IEnumerable<BookingView> as a hole IEnumerable<object> it will be an IEnumerable<int> if BookingViewID is int, something like:
MultiSelectList BookingViewsBookingObjects = new MultiSelectList(_bvs.GetBookingViews(), "BookingViewID", "BookingViewName", (IEnumerable<int>)bo.BookingViews.Select(a=> a.BookingViewID).ToList());
EDIT: Full Code.
SetUp the Data(Controller/ViewModel):
List<KeyValuePair<int, string>> List = new List<KeyValuePair<int,string>>();;
List.Add(new KeyValuePair<int, string>(1,"Value1"));
List.Add(new KeyValuePair<int, string>(2,"Value2"));
List.Add(new KeyValuePair<int, string>(3,"Value3"));
List.Add(new KeyValuePair<int, string>(4,"Value4"));
List<int> selected = new List<int>{1,2};
ViewData["Multi"] = new MultiSelectList(List.AsEnumerable(), "Key", "Value", selected);
(View):
<%= Html.ListBox("MultiSelectList", ViewData["Multi"] as MultiSelectList)%>
The Result:
alt text http://www.diarioplus.com/files/pictures/multiselectlist.JPG