Vaadin combobox.select() does not work no matter what I do - mysql

I am writing a basic CRUD app using Hibernate MySQL.
Adding new records is fine but I'm having some trouble getting an existing record's value to appear as the selected item by default when editing an existing record.
Here is the relevant code:
Criteria criteriaz = session.createCriteria(Organisation.class);
final List<Organisation> orgList = criteriaz.list();
BeanItemContainer<Organisation> srcOrgs = new BeanItemContainer<Organisation>(Organisation.class);
srcOrgs.addAll(orgList);
organisationId.setInvalidAllowed(false);
organisationId.setNullSelectionAllowed(false);
organisationId.setContainerDataSource(srcOrgs);
organisationId.setItemCaptionMode(ItemCaptionMode.PROPERTY);
organisationId.setItemCaptionPropertyId("name");
for (Organisation mOrg : orgList) {
if (mOrg.getRowid().equals(activity.getOrganisationId()))
mOrgID = mOrg.getName();
}
organisationId.select(mOrgID);
What am I doing wrong here?

Use just:
for (Organisation mOrg : orgList) {
if (mOrg.getRowid().equals(activity.getOrganisationId()))
organisationId.select(mOrg);
break;
}
BeanItemContainer contains beans as IDs, so you always work with beans only.

Although you set the caption property id to name it does not change the identifier ID for the items. So you can use the following on conjunction with BeanItemContainer:
organisationId.select(orgList.get(mOrgID));
and change this
mOrgID = mOrg.getName();
to
mOrgID = mOrg;
To make #Morfic happy:
organisationId.select(orgList.get(orgList.indexOf(mOrgID)));

Related

Update an Umbraco document's CreateDateTime in Razor?

I'm trying to change the CreateDateTime for a node/document, but it doesn't appear to be having any effect. This is what I'm trying to far:
dynamic node = new DynamicNode(1065);
Document n = new Document(node.Id);
n.CreateDateTime = node.articlePublishedDate;
n.Save();
n.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(n.Id);
Am I going about this in the right way? And also, am I correct in assuming that it can even be changed? The API seems to suggest the CreateDateTime has get/set, so it should work? Running the code through with breakpoints, it updates the CreateDateTime, but something with the save/publish seems to revert it back?
Your code is deprecated, so you need to use the "new" ContentService in umbraco:
https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService
It should be something like this:
var cs = Services.ContentService;
var node = cs.GetById(1065);
node.CreateDate = DateTime.Now;
cs.SaveAndPublish(node);

Combining a variable with a number

I'm trying to make a inventory using an array in a game I'm making.
What I need is a way to combine a number with a variable, something like this:
itemBoxNumber = "itemBox" + currentItemBox;
//In this case itemBoxNumber would say itemBox1
that I could use to replace the itemBox1.
function itemsMenuUpdate():void
{
for (var a:int = 0; a<maxInventory; a++){
var currentItemBox:Number = 1;
if(~inventory.indexOf("Potion")){
mainMenu.itemBox1.gotoAndStop("Potion");
}
if(~inventory.indexOf("Hi-Potion")){
mainMenu.itemBox1.gotoAndStop("Hi-Potion");
}
}
}
I can only find working methods for AS2. Any help is appreciated with this.
If I remember right, you can call a method from a String in AS3.
For example, if you want to call the method itemBox1 on mainMenu you can do:
mainMenu["itemBox1"]
Which is the same as:
mainMenu.itemBox1
So in your example you could do this:
mainMenu[itemBoxNumber].gotoAndStop("Potion");
You can retrieve the child display object via a name (which you need to set prior). So:
var itemBoxNumber = "itemBox" + currentItemBox;
mainMenu.getChildByName(itemBoxNumber).gotoAndStop("Potion"); //TODO ensure the child was given such a name
Make a LabelNumber Class, which has both a String label and a Number. You can then add a method that returns a String of the label and the number combined, while keeping the values independent of one another.

How do i populate an Array in one class based on a textfield in another class?(Actionscript 3.0)

i have a class (TheList.as). in which i have an array "Data" and it has a couple of values. Then i have a loop through which i am creating a scrollable list which uses the values from "Data" array. [I am trying make a unit converter]
Then i have another class "Units.as". In that class i have created three instances of "TheList". A main list ("myList"), and to sublists "ListFrom" and "ListTo". They are using values from "Data" array. Now i have text field whose value changes to whatever item is clicked. When i click "Angle" in the main list, i want the sublists to get populated with ("Degree", "Radian" etc)..
Here is what i tried
if(myList._TextLabel.text == "Angle")
{
ListFrom.Data = ["Degree", "Radian"];
}
But nothing happens, i do not get any error either. When i do this in an "ENTER_FRAME" event and trace (ListFrom.Data), i can see that the values change, but they do not get assigned to the list items in the list. I would really appreciate the help. Thanks!
Here are complete Classes for understanding the situation better(the code is pretty messy, as i am a newbie to OOP)
TheList.as: http://pastebin.com/FLy5QV9i
Units.as : http://pastebin.com/z2CcHZzC
where you call ListFrom.Data = ["Degree","Radian"], make sure when the data changed, the renders in the ListFrom have been set new data. for example, you may use MyRender in ListFrom for show, you should debug in the set data method in MyRender.
you should call the code below after you call ListFrom.Data = ["Degree","Radian"];
for (var i:int = 0; i < Data.legnth;i++) {
var render:MyRender = ListFrom[i] as MyRender;
if (render) {
render.data = Data[i];
} else {
var render:MyRender = new MyRender();
render.data = Data[i];
ListFrom.addChild(render);
}
}
You can use event listeners, singleton classes or reference one class to another, depending on the style you want. All are equally valid and fast / efficient.

AS3: Getting values of objects by referencing their name

I'm reading XML and attaching values to objects in two seperate movieclips. Like this
Map01:
Marker01.name = hello there
Marker01.short = hel
Marker01.value = 12
Map02:
Marker02.name = hello there
Marker02.short = hel
Marker02.value = 99
Now I'm clicking on Marker01 in Map01 and get its name and value. I want to compare its value to that of Marker01 in Map02, using the name, or better yet .short because the names are long and use special characters/spaces. How do I do this? I've pretty much tried everything that seemed logical!
EDIT: sample code for clarification
var marker01:mc_marker = new mc_marker();
marker01.name="hello there";
marker01.short="abc";
marker01.val="99";
marker01.x=10;
marker01.y=10;
this.mc_map01.addChild(marker01);
var marker02:mc_marker = new mc_marker();
marker02.name="hello there";
marker02.short="abc";
marker02.val="20";
marker02.x=10;
marker02.y=10;
this.mc_map02.addChild(marker02);
marker01.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
marker02.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
function showMarkerInfo(event:MouseEvent):void {
txt_ms.text=event.target.short;
txt_mv.text=event.target.val;
if (event.target.short==mc_map02.marker02.short){
txt_mvi.text="here should be the marker02 value";
}
}
You have a typo there. Map02 use Marker1 things.
If its a typo in Stackoverflow,
this.getChildByName( "Marker01" ) will return you the movieclip, buy its name. take care though, as "name" is what it searches for. You used "hello there" when you should put Marker01 as the name. I would suggest you put a property called "data" and put the xml info in it so it doesn't conflict.
In the end you have:
if( this.getChildByName( "Marker01" ).data.value == this.getChildByName( "Marker02" ).data.value ).
I assume this is because you generate Marker0X at runtime and you can't declare some variables and use them directly.
Browny points if you make "data" a instance of a custom class where you can compare two "data". If you need more help, add a comment ^_^

How can I remove a contact CompleteName.Title with EWS managed api v1.1?

Using EWS managed api v1.1, I can successfully save/set the contact "Title" or honorific (if you prefer) to a non-empty value, but I can't figure out how to remove or set it back to an empty string/null.
I've tried to set an empty value and I've tried to remove the extended property. Here is relevant code.
var titleDef = new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String);
// works when set to a non-empty string value
ewsContact.SetExtendedProperty(titleDef, "Mr.");
// throws null argument exception when set to String.Empty or null
ewsContact.SetExtendedProperty(propDefinition, String.Empty);
// isRemoved is equal to false and the value doesn't change
var isRemoved = ewsContact.RemoveExtendedProperty(titleDef);
I've also tried to use a different overload on the ExtendedPropertyDefinition as mentioned in this very similar question, but it didn't change my end result for removing the property. I'm not sure I understand the difference in the two signatures for the constructor.
var titleDef = new ExtendedPropertyDefinition(new Guid("{00062004-0000-0000-C000-000000000046}"), 0x3A45, MapiPropertyType.String);
// isRemoved is equal to false and the value doesn't change
var isRemoved = ewsContact.RemoveExtendedProperty(titleDef);
Brute Force Work-Around
I suppose I could take a complete copy of the contact (without the title) and delete the original, but that seems a bit over the top and would probably cause other bugs.
EWS lets you assign Extended Properties without first binding them. However, to remove an Extended Property - you need to include it in your initial binding call PropertySet. The following worked for me...
var titleDef = new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String);
Contact contact = Contact.Bind(service, id, new PropertySet(titleDef));
contact.RemoveExtendedProperty(titleDef);
contact.Update(ConflictResolutionMode.AutoResolve);
It is also strange that you can retrieve the Title as a first-class property, but you cannot assign it (since it's a complex type). They could have made this easier for us.
var title = contact.CompleteName.Title;