How can I write hashMap inside an fxml. I tried like this, but my IDE doesn't recognize the "entry" tag name. This must create a Map<String, Integer>
<FXCollections fx:factory="observableHashMap">
<entry>
<String fx:value="Vandaag" />
<Integer fx:value="1"/>
</entry>
<entry>
<String fx:value="Deze week" />
<Integer fx:value="7"/>
</entry>
<entry>
<String fx:value="Deze maand" />
<Integer fx:value="31"/>
</entry>
</FXCollections>
Defining as
<FXCollections fx:factory="observableHashMap">
<foo>123</foo>
<bar>456</bar>
</FXCollections>
works. However you loose the type safety and may not able to define a space separated key like
<kung foo>123</kung foo>
So defining the map in controller seems more appropriate.
There isn't much about maps in the introduction to FXML. However, you can do something like this: (in fxml)
<Group fx:id="mapWrapper">
<properties Vandaag="1" Deze_week="7" Deze_maand="31" />
</Group>
Then in your controller class you can have:
#FXML
private Group mapWrapper;
private ObservableMap map;
public void initialize() {
// the properties object is backed up by observable hash map
map = mapWrapper.getProperties();
// do something with the map
map.forEach((key, value) -> System.out.println(key + ":" + value));
}
prints the following:
Deze_maand:31
Vandaag:1
Deze_week:7
It probably isn't exactly what you wanted but it works
Related
I don't want few aspects to be visible in manage aspect for a particular site. So I changed share config custom XML. But this change is being reflected for all sites. How can I make this specific for a site?
Any help is appreciated.
Thanks in advance!!!
You should use the concept of seperate share modules per site, using a site evaluator:
create a share-extension-mysitename-module.xml file in alfresco\site-data\extensions\ that looks like so:
<id>My site module</id>
<auto-deploy>true</auto-deploy>
<evaluator type="site.module.evaluator">
<params>
<sites>mysitename</sites>
<applyForNonSites>false</applyForNonSites>
</params>
</evaluator>
<customizations>
<customization>
<targetPackageRoot>org.alfresco</targetPackageRoot>
<sourcePackageRoot>com.mypackage</sourcePackageRoot>
</customization>
</customizations>
<configurations>
<config evaluator="string-compare" condition="DocumentLibrary" >
...
<aspects>
<visible>
<aspect name="my:visibleaspect" />
</visible>
</aspects>
</config>
</configurations>
</module>
</modules>
As far as I know, I don't think this is possible to have a custom share-config by site.
I see two (probably unsatisfying) solutions :
You can create your custom evaluator and use it to make some parts accessibles (or not).
<bean id="evaluator.doclib.action.siteBased" class="xx.xx.xx.web.evaluator.SiteBasedEvaluator">
<property name="sites">
<list>
<value>mysite</value>
</list>
</property>
</bean>
public class SiteBasedEvaluator extends BaseEvaluator {
private List<String> sites;
public SiteBasedEvaluator() {
super();
}
public SiteBasedEvaluator(String... pSites) {
super();
sites = Arrays.asList(pSites);
}
public boolean evaluate(JSONObject jsonObject) {
Boolean isFound = false;
if (sites != null) {
for (String site : sites) {
isFound = site.equals(getSiteId(jsonObject));
if (isFound) {
break;
}
}
}
return isFound;
}
You can deploy two share war in your tomcat, each one having the share-config-custom.xml you want
I want to inject a string value into a property using Unity. I can't find a syntax that works. In this case, PutBunniesHere
In this case the error is it doesn't recognise "type" as a valid attribute of value. I added that because it couldn't resolve the type before.
The class has this property:
[Dependency("PutBunniesHere")]
public string PutBunniesHere { get; set; }
And this is the config I'm using for unity.
<?xml version="1.0" encoding="utf-8" ?>
<unity2 xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IInjectMe1" type="CommonLib.IInjectMe1, CommonLib"/>
<alias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<container name="unity2">
<register type="CommonLib.IInjectMe2, CommonLib" name="Injected2" mapTo="CommonLib.InjectMe2, CommonLib">
<lifetime type="singleton"/>
<constructor>
<param name="theDependency" dependencyType="IInjectMe1" />
</constructor>
<property name="PutBunniesHere">
<value value="my bunnies" type="System.String"/>
</property>
</register>
</container>
</unity2>
Ok, solved the problem. Once again it was a problem with having a name on the register element. This makes value on the value element take on a different meaning. value means name of a registered type, or a type if there is a name attribute on the parent register element. Take out the name and value means a value (and possibly also a type)
Yuk.
I have seen numerous examples on how to remove duplicates in ArrayCollection but I can't seem to transpose this to XMLList. In most ArrayCollection examples, the example compares the key of the array with hasOwnProperty method and return a bool. That's fine, but what would I compare to when using an XMLList? Let's say I have:
<fx:XML id="testXML" xmlns="">
<universe>
<category cname="cat 1">
<item iname = "All"/>
<item iname = "item 1"/>
<item iname = "item 2"/>
</category>
<category cname="cat 2">
<item iname = "All"/>
<item iname = "item 3"/>
<item iname = "item 4"/>
</category>
</universe>
</fx:XML>
[actionscript]
var myList:XMLList = testXML..#iname;
will give two occurences of the item "ALL".
I know I might have to convert the XMLList to an XMLListCollection to use the filterFunction (how would I go about doing that - or should I just define myList as an XMLListCollection right from the start). then on to the filterFunction:
private function remove Duplicate (item:Object): Boolean
{
here I don't know how to compare the item to tell me if the object already exist
or not. I guess I need to compare the item to a copy of the list and see if the
item has already been seen in the copy of the list. Or is there a clean way to
do this?
}
then all this is passed to a dropDownList:
<s:DropDownList id="myDDL" dataProvider="{myList}" />
Using E4x filter function you can for example put the key into an Object (if the key is a String, otherwise use a dictionary instead of an Object) and look if it is already present to build your XMLList :
var xml:XML=<universe>
<category cname="cat 1">
<item iname="All"/>
<item iname="item 1"/>
<item iname="item 2"/>
</category>
<category cname="cat 2">
<item iname="All"/>
<item iname="item 3"/>
<item iname="item 4"/>
</category>
</universe>
function filter(xml:XML):XMLList {
var seen:Object={}
return xml..#iname.(!seen[valueOf()]&&(seen[valueOf()]=true))
}
trace( filter(xml) )
Here a live example at wonderfl : http://wonderfl.net/c/10xr
The easiest way I know how to do this is to use ActionLinq. This code will take your e4x code and turn it into an Enumerable, cast the attributes as strings, make the items in the list distinct and dump it out as an ArrayCollection.
myList = Enumerable.from(testXML..#iname)
.cast(String)
.distinct()
.toArrayCollection();
If you don't want to use ActionLinq, you can implement this using a Dictionary:
[Bindable]
private var myList:ArrayList;
private function removeDuplicates(data:XMLList):ArrayList {
var result:ArrayList = new ArrayList();
var found:Dictionary = new Dictionary();
for each(var item:String in data) {
if(item in found) {
continue;
}
found[item] = true;
result.addItem(item);
}
return result;
}
And then when the XML is ready, you can call it:
myList = removeDuplicates(testXML..#iname);
I'm trying to write a custom field that is representing the time spend on the task. The field derives from NumberField (number is representing minutes) but I want to display it on the list as HH:MM for that purpose I've tried to override the fallowing function:
protected override void RenderFieldForDisplay(System.Web.UI.HtmlTextWriter output)
{
Label timeSpan = new Label();
timeSpan.Text = ((int)this.Value / 60).ToString() + ":" + ((int)this.Value % 60).ToString();
timeSpan.RenderControl(output);
//base.RenderFieldForDisplay(timeSpan.RenderControl());
}
I'm not an ASP.NET developer so I'm trying to avoid defining DisplayTemplate.
Can you show me the way how to render it programmatically or just push me in the right direction?
Solution
Solved with help from Kusek answer. In fldtypes_HourField.xml:
<RenderPattern Name="DisplayPattern">
<HTML><![CDATA[<div align='right'>]]></HTML>
<Switch>
<Expr>
<Column />
</Expr>
<Case Value="" />
<Default>
<HTML><![CDATA[<script src="/_layouts/hourField.js"></script>]]></HTML>
<HTML><![CDATA[<div><SCRIPT>formatHourField("]]></HTML>
<Column />
<HTML><![CDATA[");</SCRIPT></div>]]></HTML>
</Default>
</Switch>
</RenderPattern>
And the hourField.js
function formatHourField(t) {
var m = t % 60;
var h = (t - m)/ 60;
document.write(h + ":" + m);
}
Having in mind what I've tried before - this solution looks beautifully simple :)
The value that is rendered in the All Items view is not based on the Template or control. It is rendered from the
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr><Column /></Expr>
<Case Value="" />
<Default>
<Column SubColumnNumber="1" HTMLEncode="TRUE" />
<HTML><![CDATA[, ]]></HTML>
<Column SubColumnNumber="0" HTMLEncode="TRUE" />
</Default>
</Switch>
</RenderPattern>
Tag of the Field Schema that you have defined. Display Template Defines the look of how it is being displayed in the Disp Form. Hope this helps.
It will be bit trick to get your format in the CAML Representation .
You can get some infomration about the subject here
I am trying to build a messaging system and for this i have the table definition below
Message
Id
From
To
Body
ParentId // Subcollection, i want to get Asnwers (Message.ParentId== Message.Id)
IsRead
and i have this in the Message.cs
IList<Message> Answers;
I have tried this but it gives me all the messages and all the answers in the main collection.
But i dont want answers to be seen like a message (like the main item).
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RealEstate.Core" namespace="RealEstate.Core.Domain">
<class name="Message" table="Message" lazy="true">
<id column="id" type="Int64" name="Id">
<generator class="native" />
</id>
<property name="From" column="[From]" type="Int64" />
<property name="To" column="[To]" type="Int64" />
<property name="Body" column="Body" />
<property name="ParentId" column="ParentId" type="Int64" />
<property name="SenderType" column="SenderType" type="Byte" />
<property name="IsRead" column="IsRead" type="Boolean" />
<bag name="Answers" lazy="true" cascade="delete">
<key column="ParentId" />
<one-to-many class="Message"/>
</bag>
</class>
</hibernate-mapping>
How can this mapping be done, they are in the same table ?
Thank you very much
Before attempting an answer, I'd strongly recommend that you search the NHibernate Users Group as there are tons of helpful NHibernate folks that lurk there answering all kinds of questions.
But let me see if I can help here.
Hmmm, I'm not totally sure I understand the question. You say:
I have tried this but it gives me all
the messages and all the answers in
the main collection.
But i dont want answers to be seen
like a message (like the main item).
Do you mean that the Answers collection contains all answers in the database?
Can you post up more code, showing the query your running, and the class code?
One potential problem you have with your scenario is that ParentId can be NULL in the database. This gives NHibernate problems when mapping a one-to-many.
Try making the association bidirectional (documentation reference). That sometimes helps avoid a few traps.
To do that, add this to your class
public class Message {
///<summary>Reference to parent message</summary>
public Message Parent {get;set;}
//... rest of class
Add this to your mapping:
<bag name="Answers" lazy="true" cascade="delete" inverse="true">
<key column="ParentId" />
<one-to-many class="Message"/>
</bag>
<many-to-one name="Parent"/>
The inverse=true will make NHibernate manage the relationship from the Parent property, not the collection. This is necessary because ParentId can be null.
In your code, rather than using myMessage.Answers.Add( blah ); you can use answer.Parent = myMessage. Of course, you can write nice helper methods to make this more meaningful.
someMessage.AddAnswer( someAnswer );
Which looks like this:
public void AddAnswer(Message answer)
{
answer.Parent = this;
if( ! this.Answers.Contains(answer) )
this.Answers.Add(answer);
}
Hope this helps.
You want to map a tree ?
Maybe this could help:
how to map a tree in nhibernate