w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Struts2 - Setting a property from a static list String property using OGNL not working
You cannot nest tags like that. And to reference inner class you need to use $ sign. <s:hidden name="username_type" value="%{@com.packagename.models.UsernameModel$UsernameTypes@ALIAS}" /> IMO it is better to use that kind of static variables directly in class rather than send them from JSP.

Categories : Java

Setting property of class type with TypeConverter from Property Panel produces expanded XAML, not string
You almost there and needs only two minor adjustments on Complex class to make it work as you expect: 1) Remove default public constructor: public Complex() { } // <- delete this line 2) Add magical DesignerSerializationVisibility attribute to Real and Imaginary properties (or in general - to all properties with public setter): [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public double Real { get { return m_real; } set { m_real = value; } } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public double Imaginary { get { return m_imag; } set { m_imag = value; } } Hope this helps.

Categories : Wpf

How to make a list in Python distinct based on a property of the class in the list?
Assuming the property you wish to key on is immutable, you can use a dict: d = {} for x in xs: d[x.tag] = x Now d will contain a single x per tag value; you can use d.values() or d.itervalues() to get at the xs. NB. here last matching item wins; to have the first one win, iterate in reverse.

Categories : Python

Getting unique values from a list of objects with a List as a property
If I understand, you want a list of all of the unique certifications among all of the employees. This would be a job for SelectMany: var uniqueCerts = empList.SelectMany(e => e.Certifications).Distinct().ToList();

Categories : C#

If my dependency property is a class how do I get property changed to activate on a class property change?
Each one of the properties of User must also notify on change. E.g.: public class User { string _Name; public string Name { get { return _Name; } set { _Name = value; PropertyChanged("Name"); } ... } }

Categories : C#

GAE NDB String list property
How about (are you using ndb?): MyModel.query().filter(MyModel.myProp == 'a').filter(MyModel.myProp == 'b') In this case, == looks for the element being in the list.

Categories : Google App Engine

replace one class in bean property list in spring
For custom persistence handlers specifically, you can remove the core handlers by using the blCustomPersistenceHandlerFilters bean. So in your case you would define your beans like this: <bean id="blCustomPersistenceHandlerFilters" class="org.springframework.beans.factory.config.ListFactoryBean" scope="prototype"> <property name="sourceList"> <list> <bean class="org.broadleafcommerce.openadmin.server.service.handler.DefaultCustomPersistenceHandlerFilter"> <property name="filterCustomPersistenceHandlerClassnames"> <list> <value>org.broadleafcommerce.admin.server.service.handler.ProductCustomPersistenceHandler</value> </list>

Categories : Spring

Acces To Individual Property Of Listdatastructure of a class in WPF
You want srting SDepname=query.Depname; but query is a List<> so the question would be : which element? There could be 0, 1 or more candidates. Closest you can get: string SDepname=query.First().Depname; // throws on empty result set or maybe string (SDepname=query.FirstOrDefault() ?? new Info { Depname = "" }).Depname;

Categories : Wpf

MVC4 model property should be a list or an ICollection of another class
I asked a .NET professor friend of mine this question, and this is his response: Both of your declarations are invoking collections. A list is a typed collection while ICollection is untyped. Typed Collection (List) has two advantages over untyped collections. The type of each collection is checked at compile time and thus preventing runtime errors. Second, they reduce the amount of casting that is needed when retrieving objects. I first implemented the ICollection solution, and it was clunky in a couple of places (for example, the Initializer for seed data): var mcQuestions = new List<MultipleChoiceQuestion> { new MultipleChoiceQuestion { QuestionText = "What is the value returned by the expression (true == false? 'yes': 'no')?",

Categories : Asp Net Mvc

How do I sort a list(of T) by a property x when x is a string and I don't know about the properties on T
One way to do this is to write an extension method. Module imnotgoodwithnames ''' <summary> ''' Sorts a list of type T. ''' </summary> ''' <typeparam name="T">The type of the objects in the list</typeparam> ''' <param name="context">The list</param> ''' <param name="sortExpression">The column to sort by</param> ''' <param name="sortDirection">The sort direction</param> ''' <returns>The sorted list</returns> ''' <remarks></remarks> <System.Runtime.CompilerServices.Extension()> _ Public Function Sort(Of T As {Class, New})(ByVal context As List(Of T), ByVal sortExpression As String, ByVal sortDirection As SortDirection) As IOrderedEnumerable(Of T) Dim param = Expression.Parameter(GetType(T), sortE

Categories : Vb.Net

How to get class name in code as static string property
class Test { public static string ClassName { get { return MethodBase.GetCurrentMethod().DeclaringType.Name; } } }

Categories : C#

How do I bind a property of custom class List to Spinner in Android?
You can either: Override toString() method in your custom object to return the good value based on your custom property public class Department { public int ID; public String DepartmentName; @Override public String toString() { return DepartmentName; } } And then in your view public void populateSpinner(Context context, List<Department> departments, Spinner spinner) { ArrayAdapter<Department> adapter = new ArrayAdapter<Department>(context, android.R.layout.simple_spinner_item, departments); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); } Create a temporary List<String> for your spinner adapter public void populateSpinner(Context context, List<Departme

Categories : Android

passing a List that is a class generates error, List that is string does not
It's pretty obvious what's going on here, everything you need to know is in your error message. You have 2 different declarations for the Rooms class, one in your RoomViewController and the other in your TableSource and appear to be leaking them across your classes. You need to make sure you are passing the expected type into the TableSource class. To elaborate further, your TableSource constructor looks like: public TableSource(List<CupuleAdmin.TableSource.Rooms> table) { } And you are trying to pass: List<CupuleAdmin.RoomViewController.Rooms> allrooms = new List<...>(); table.Source = new TableSource(allrooms);

Categories : C#

Initialize String List property on User Control
You can do it by other way. Add other property of type string, you can name it is as ListData. This will be in usercontrol public string ListData { get; set; } Assign string with comma separator to this property <uc1:MyListControl ID="MyListControl1" runat="server" ListData="ABC,XYZ" /> You can parse this string to List in page_load of usercontrol. protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(ListData)) { MyList = ListData.Split(new char[] { ',' }).ToList(); } } Now you can use this MyList as list populated with data

Categories : Asp Net

How to use a case class to deserialize an array of json objects to List[Map[String,String]]
As I replied to you on the Salat mailing list, Salat doesn't support deserializing nested collections right now. https://github.com/novus/salat/wiki/Collections

Categories : Scala

C# Linq or Lambda to get Dictionary> from a class
Instead of x.ToList you have to select the string property of the anonymous type first: Dictionary<string, List<string>> procTasks = baseSettings .GroupBy(x => x.ProcessStr) .ToDictionary(g => g.Key, g => g.Select(x => x.TaskStr).ToList());

Categories : C#

How to assign values for multiple class property like a list of items using for loop?
You can use object initializers to do this. VS will give you intellisense for the properties. http://msdn.microsoft.com/en-us/library/vstudio/bb384062.aspx Example: class Helper { public bool A { get;set;} public bool B { get;set;} } Helper myclass = new Helper { A = false, B = false }; This is not using a for loop but it is cleaner in my opinion.

Categories : C#

String property in partial class of the entity framework is not serialized
The [XmlElement] suggests you are using XmlSerializer; now, if we consider: public String testA { get { return "ok"; } } Note that XmlSerializer will ignore this because it knows it can't deserialize it (there is no setter). A serializer wants to also be able to deserialize the data afterwards. It doesn't serialize it because it can't offer deserialization without a setter. Add a setter. Ideally, for example: [XmlElement("testA")] public string TestA {get;set;} (and give it the value "ok" separately) Note also that your list won't deserialize properly at the moment either; I would suggest: private readonly List<string> testB = new List<string>(); [XmlElement("TestB")] public List<string> TestB { get { return testB; } } (and again - add the

Categories : C#

Entity Framework add property to partial class that will get model or list of models from database
EF will ignore the SpokenLanguage property in your case. However, you can make EF retrieve the SpokenLanguage using a INNER JOIN by adding a relation in your model between the two tables. You can also make it retrieve the SpokenLanguage lazily (on demand)-it will actually make a better version on what you wrote, but if you are sure you want to print the language label in your view, it's better to retrieve it using a INNER JOIN.

Categories : C#

AngularJS evaluate a string in a function to call property on json list
If I understand correctly: $scope.moveUser = function(fromId, toId, index) { if (users.hasOwnProperty(fromId) && users.hasOwnProperty(toId)) { scope.users.toId.list.push(scope.users.fromId.list[index]); scope.users.fromId.list.splice(index, 1); return true; } else { return false; } };

Categories : Javascript

How to handle property changed event of a property in One class from another class in MVVM
You can subscribe the event PropertyChanged. myModel.PropertyChanged+=(s,e)=>{ /* your handler here */}; as the @stijn comment point, unsubscribing can be required if the model became unused to avoid memory leaks.

Categories : C#

List String within a class
Let's break down this line: instancenam.p.AddRange(string.Split(new char[] {':',':'})[2]); I'm going to assume that the string part is actually the name of a variable (string isn't a valid identifier). I'll call it text below. The expanded code looks like this: char[] delimiters = new char[] {':',':'}; string[] splitValues = text.Split(delimiters); string singleValue = splitValues[2]; List<string> list = instancenam.p; list.AddRange(singleValue); That will give the same error, because you're calling AddRange which is meant to take a collection of values - but you're only providing a single value. If you just want to add a single value, use Add: instancenam.p.Add(text.Split(new char[] {':',':'})[2]); I'd recommend breaking the code into something a bit more like the code abo

Categories : C#

c# property setter body without declaring a class-level property variable
You need to set a field variable and store the value there, if you're going to use custom getter and setter. With the code you have right now you will be running into a stack overflow exception. When you assign something to mongoFormId, you'll execute the line this.MongoFormId = value;. This is an assignment to mongoFormId, resulting in executing the line this.MongoFormId = value;, and so on. It won't ever stop. The correct way is a field: private string _mongoFormId; public string mongoFormId { get { return this._mongoFormId; } set { this._mongoFormId = value; revalidateTransformation(); } }

Categories : C#

Bind an control property to a property of a Class of the Window ViewModel
You have implemented INotifyPropertyChanged on your ViewModel but you never call it when Property is changed try: public class ViewModel : INotifyPropertyChanged { private foo _property; public foo Property { get{ return _property; } set{ _property = value; OnPropertyChanged(); } } .................

Categories : C#

Giving data to a class property according to another classes property which I get from the database
Get member payments: public List<Payment> GetMemberPaymnets(int memberId) { List<Payment> Payments = new List<Payment>(); string SELECT = "SELECT ID,AMOUNT,STARTDAY,ENDDAY FROM Payments WHERE Id = @Id order by endday desc"; using (sqlConnection = new SqlConnection(sqlConnectionString_WORK)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand(SELECT, sqlConnection)) { sqlCommand.Parameters.Add("@Id", SqlDbType.Int).Value = entity.Id; var sqlReader = sqlCommand.ExecuteReader(); while (sqlReader.Read()) { var payment = new Payment { Id = Convert.ToI

Categories : C#

Java Collection: what to convert Collection> to ArrayList> or List>?
You can use the appropriate constructor: List<List<String>> yourList = new ArrayList<>(yourCollection); The order of the elements in the list is the order of the iterator of the collection.

Categories : Java

Hydrate property via joining another List on unique Id
This piece of code should match your needs: public class Equipment { public int ProcessId { get; set; } public string Name { get; set; } } public class WorkflowItem { public Equipment { get; set; } public void LoadEquipmentFrom(IEnumerable<Equipment> cache){ var equipment = cache.FirstOrDefault(e => e.ProcessId == Equipment.ProcessId); if(equipment != null) Equipment.Name = equipment.Name; } } You could also assign the instance from cache to the existing one, it wouldn't matter since both must have the same Identifier Equipment = equipment;. That would be easier if you have more properties to set. To optimize further use an IDictionary<int, Equipment> instead of that IEnumerable<Equipment>, because you'll be reading

Categories : C#

Set the css property of a class based on its visibility property using CSS only
yes with css attributre selectors you can do it try the below css: .div-class[style*="visible"] { color: green; } .div-class[style*="hidden"] { color: red; }

Categories : CSS

Adding a string to a List inside of a List>
You are correct, with the error, you need to understand that the List<List<string>> will take a List<string> and NOT A String. Try something like this; List<string> listOfString = new List<string>; for (int i = 0; i <= filesToRead.Count; i++) { using (var reader = new StreamReader(filesToRead[i])) { string line; while ((line = reader.ReadLine()) != null) { listOfString.add(line); } } } Then, _toLoad.add(listOfStrings);

Categories : C#

property of type list modifying the original set of values in the list even when it's readonly
The readonly keyword means the variable is read-only -- but it doesn't guarantee that the object itself is immutable. For illustration: class Numbers { readonly List<int> num; public Numbers() { // ok - can write to read-only variables in the owner's constructor num = new List<int> { 1, 2, 3, 4 }; } void Test() { // this is fine -- I'm not writing to "num", just changing its state num.Clear(); // compiler error: "a readonly field cannot be assigned to" num = new List<int>(); } } If you want a read-only collection, there are .Net types that serve that purpose; see for example ReadOnlyCollection<T>. Related: Eric Lippert's famous article on different kinds of immutability.

Categories : C#

Using linq group by to get from a list of objects with a DateTime property to a list with an interval StartDate, EndDate
You can use GroupBy in combination with SelectMany and Aggregate for this: var setups = bookedRooms.GroupBy(x => Tuple.Create(x.TimePeriodId, x.VenueId)) .SelectMany(x => x.Aggregate( new List<EventSetup>(), AccumulateRooms)) .OrderBy(x => x.StartDate) .ToList(); List<EventSetup> AccumulateRooms(List<EventSetup> existingSetups, BookedRoom currentRoom) { var setup = existingSetups.LastOrDefault(); if(setup == null || setup.EndDate.AddDays(1) != currentRoom.Day.Date) { setup = new EventSetup { VenueId = currentRoom.VenueId, TimePeriodId = currentRoom.TimePeriodId, StartDate = currentR

Categories : C#

Enum property in parent class should change inside derive class
That's not a parent class, but an interface. You can have an enum inside a class, you'd refer to it as ClassA.ConditionEnum.*: . class MyClass : IArticle { public enum ConditionEnum { Red, Blue, Yellow }; public ConditionEnum myenum; } MyClass c = new MyClass(); c.myenum = MyClass.ConditionEnum.Red;

Categories : C#

Is there any way to access Base Class Property via Derived Class object directly in PHP
Since you override $name in the child, the property will have the child's property value. You cannot access the parent value then. It wouldn't make sense any other way because the property is public, which means the property is visible to the child (and outside) and modifications to it will change the very base value. So it's effectively one and the same property and value for that instance. The only way to have two separate properties of the same name is to declare the base property private and the child property non-private and then call a method that has access to the base property, e.g. class Foo { private $name = 'foo'; public function show() { echo $this->name; } } class Bar extends Foo { public $name = 'bar'; public function show() {

Categories : PHP

Nhibernate unit testing. Child class cannot use Base class property
I would suggest using [TestInitialize] and [TestCleanup] in your abstract base class and doing something like the following: [TestInitialize] public void TestInitialize() { Console.Out.WriteLine("Get a ISession object"); } [TestCleanup] public void TestCleanup() { Console.Out.WriteLine("Dispose ISession"); } Then in your child classes continue to do what you are doing: [TestMethod] public void DoDbWork() { Console.Out.WriteLine("Running a query via nhibernate"); } You really just want to ensure you have a clean session for each test. The attributes for TestInitialize and TestCleanup will run before and after each unit test. Here is the documentation for those attributes. To ensure your ISession is in the righ

Categories : Unit Testing

How can I update a MVC model list property first be compiling the list on client
It sounds like what you want is to asynchronously post the new item back to the server, and refresh the model. Here is a great example of how to do exactly that: http://blog.krisvandermast.com/UsingJQueryAjaxToLoadAPartialViewInASPNETMVC2AndThenRetrieveTheInputOnTheServerAgain.aspx In short, when the user clicks "Add Worker", the view posts the new worker to the server, which then retrieves the full list of workers to return to the view. The view can then be updated to show the full list of workers.

Categories : C#

I need to get information from a form, assign it to a property in class, and then use it in a method in another class. How?
first of all you should add container for your OrderItem in ShoppingBasket. Like Lis<OrderItem> products, and then public void AddProduct(string productName, decimal latestProductValue, int quantity) { products.Add(new OrderItem(productName, latestProductValue, quantity)); } to access OrderItem's properties your just write OrderItem.Quantity = 3 and better create Add method wich will just accept OrderItem: public void AddProduct(OrderItem sb) { } and something about your OrderItem, TotalOrder property should be readonly(have only get method): public decimal TotalOrder { get; }

Categories : C#

How to restrict a derive class from accessing one of the property of a base class in c#
public class Employee { public double Salary { get; private set; } } Assuming: you want the property to be readable by everyone you don't want subclasses to be able to write to Salary If, however, you want external classes to write to Salary, but not subclasses of Employee, then that's not possible. Subclasses will always have at least as much privileges as external classes. And if you don't want anyone to be able to read/write to that property (except the Employee class), then just make it private like so public class Employee { private double Salary { get; set; } }

Categories : C#

Find class with a specific property value - and then create instance of this class
Assuming that all relevant classes derive directly from BaseException and are in the same assembly as it, you can use this code: var exceptionType = typeof(BaseException) .Assembly.GetTypes() .Where(x => x.BaseType == typeof(BaseException)) .Select(x => new { ExceptionType = x, Property = x.GetProperty("ErrorBitNumber", BindingFlags.Public | BindingFlags.Static) }) .Where(x => x.Property != null) .FirstOrDefault(x => x.Property.GetValue(null, null) == errorBitNumber) .ExceptionType; if(exceptionType == null) throw new InvalidOperationException("No matching exception has been found"); var exception = (BaseException)Activator.CreateInstance(exceptionType); throw exception; This should work, but it is nothing I would eve

Categories : C#

Setting base class property using derived class Constructor
Pass the field down in the constructor. (Note: normally you should name fields starting with a lower case character and properties with uppercase). Here is an example where I fixed the naming. public abstract class Converter { private readonly MyData data; protected Converter(MyData data) { this.data = data; } public MyData Data { get { return data; } } } public class MyData { private readonly int value; public MyData(int value) { this.value = value; } public int MyValue { get { return value; } } } public class Converter1 : Converter { public Converter1() : base(new MyData(5)) { } } I recommend the practice of using readonly fields and getters only for properties to start with. Doing so will make y

Categories : C#

implementing get/set property in a concrete class which inherits from an abstract class
Interesting, I got it to work by simply defining the properties block before the methods block in the subclass (the order seems to matter here): classdef subClass < superClass properties a; end methods function val = get.a(obj) val = obj.a; end end end I think this is an issue with the MATLAB parser, perhaps you should file a bug report.

Categories : Matlab



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.