Can you define a Vector in MXML? - actionscript-3

Can you define a vector in MXML?
I have vector property on my class:
public var columns:Vector.<Number>;
On my class and I want to use in MXML:
<MyComponent>
<columns>
<Vector>
<fx:Number>200</fx:Number>
<fx:Number>300</fx:Number>
<fx:Number>400</fx:Number>
<Vector>
<columns>
<MyComponent>

You need to specify the Vector type:
<fx:Vector type="Number">
<fx:Number>200</fx:Number>
<fx:Number>300</fx:Number>
<fx:Number>400</fx:Number>
</fx:Vector>
another example can be found in this documentation

Related

How to separate html code that is sent from one razor component to another?

I'm calling a part of a table from a razor component to a component that can be viewed. But the the problem is that there is an audio element i want to separate so it can be called at a different place.
Right now the audio element is included in the call in the loop. Is there any way the audio element can be separated in the CallComponent.razor, such that it can be called at a different loaction in index.razor?
Here is some code:
Index.razor
//I want to call the separated audio element here
...
<tbody>
#foreach (var fileGroup in GroupedAndSorted)
{
<CallComponent fileGroup="fileGroup" />
}
</tbody>
...
CallComponent.razor
<audio src="#audioUrl" controls>
</audio>
<tr>
<td>
<a #onclick="#(() => PlayAudio(Mp3.Url))"
class="link-primary"
role="button">
#fileGroup.Key
</a>
</td>
</tr>
...
Here is one way, there are other ways involving various ways to handle application state, but this demonstrates possibly the simplest.
Index.razor
#childMarkup
<Component1 ExtraMarkup=#( em => childMarkup = em) />
#code
{
RenderFragment childMarkup;
}
Component1.razor
<h1>Component1</h1>
#code
{
[Parameter] public EventCallback<RenderFragment> ExtraMarkup { get;set;}
protected override void OnInitialized()
{
ExtraMarkup.InvokeAsync( #<div>I am extra markup</div> );
}
}
In this example, Component1 has a parameter that takes an EventCallback<RenderFragment> - in other words, you give it a method that accepts a RenderFragment and Component1 will call your method supplying it with some markup. Here we just store the incoming RenderFragment in a local field - which is then rendered in the parent markup.
Try it: https://blazorrepl.telerik.com/cQbPGRPT48cbMaCe55
It is not really clear what you want to achieve. Have you looked into #ref That way you can reference you Razor child component elsewhere.

Static and dynamic class in the same element. Polymer

How to define in the same DOM element a dynamic class and another static?
I tried this:
class$="{{clase}} my-static-class"
class$="[{{clase}}, 'my-static-class']"
class$="{{clase}}" class="my-static-class"
but doesn't work.
String interpolation is not yet supported on Polymer 1.0. However, you can use a computed binding for this.
Polymer({
...
computeClass: function(someClass) {
return someClass + ' my-static-class';
}
});
And use accordingly:
<div class$="{{computeClass(clase)}}"></div>

GWT uibinder autocorrect off

im using GWT uibinder method and my html contains a textbox like
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:idmw="urn:import:com.testing.wid.impl">
<g:HTMLPanel>
<table align="center" valign="center" height="25%">
<tr><td><g:TextBox ui:field='searchS' /></td></tr>
</table>
</g:HTMLPanel>
How can i TURN OFF autocorrect and autocapitalize for this Textbox??
i tried
<g:TextBox ui:field='searchS' autocapitalize="off" autocorrect="off"/>
but i get
[ERROR] Class TextBox has no appropriate setAutocorrect()
method Element <g:TextBox autocapitalize='off' autocorrect='off' ui:field='searchS'>
Any other way i can do this???
Thanks
As already pointed by #Boris Brudnoy there is no built-in way to do it with TextBox. Takin futher his suggestion it will be nice to extract this into new custom component (to simplify reuse and support):
Add new package (for example com.app.shared.customcontrol)
Add new CustomTextBox:
public class CustomTextBox extends TextBox {
public void setAutocomplete(String value){
this.getElement().setAttribute("autocomplete", value);
}
public void setAutocapitalize(String value){
this.getElement().setAttribute("autocapitalize", value);
}
}
Declare new namespace using UI binder and use your component:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:c="urn:import:com.app.shared.customcontrol">
<g:HTMLPanel ...>
<c:CustomTextBox ui:field="..." autocomplete="off" autocapitalize="off" />
</g:HTMLPanel>
</ui:UiBinder>
As alternative way if you want apply these settings system wide you can do it via constructor:
public class CustomTextBox extends TextBox {
public CustomTextBox() {
this.getElement().setAttribute("autocomplete", "off");
this.getElement().setAttribute("autocapitalize", "off");
}
....
}
What you've tried will not work since GWT doesn't translate UiBinder attributes directly into HTML element properties. Instead, as your error message hints, it looks up widget setter methods of the form set[UiBinder_attribute]. Since there is neither setAutocorrect nor setAutocapitalize method in the TextBox class, the errors you're getting are expected.
What you could do is drop to the element level and write something like this, e.g. in your widget's constructor:
public MyWidget() {
initWidget(uiBinder.createAndBindUi(this));
searchS.getElement().setProperty("autocapitalize", "off");
searchS.getElement().setProperty("autocorrect", "off");
}

Registering components with castle that are dynamically created by DynamicProxy

So I've been working hard for a while to build a solution which creates certain components using nothing but Castle DynamicProxy (version 2.2) and an interceptor. Everything looks great except that at the end of all this I realized I need to register these components with the windsor container. Is this possible or has my work been for naught?
I'll fabricate 2 castle configurations to explain my problem. The first one works, while the second does not.
First config (this has been working great for a while):
<castle>
<facilities>
<facility
id="factory.support"
type="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel" />
</facilities>
<components>
<component
id="Factory"
service="Foo.IFactory, Foo"
type="Foo.Local.LocalFactory, Foo.Local" />
<component
id="Loader"
service="Foo.Contracts.ILoader, Foo.Contracts"
type="Foo.Local.Loader, Foo.Local"
factoryId="Factory" factoryCreate="GetLoader" />
</components>
</castle>
Second config (I don't know what to put in the type attribute and it doesn't work without it):
<castle>
<facilities>
<facility
id="factory.support"
type="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel" />
</facilities>
<components>
<component
id="Factory"
service="Foo.IFactory, Foo"
type="Foo.Remote.RemoteFactory, Foo.Remote" />
<component
id="Loader"
service="Foo.Contracts.ILoader, Foo.Contracts"
type="I DUNNO, WHAT'S THE TYPE?"
factoryId="Factory" factoryCreate="GetLoader" />
</components>
</castle>
So my fabricated configs register the factory facility, then I register a factory, then register my "ILoader" component. The "LocalFactory" creates an actual type for the ILoader component, whereas the "RemoteFactory" creates the ILoader component using dynamic proxy, creating the proxies without targets. I.e., I use the ProxyGenerator.CreateInterfaceProxyWithoutTarget method, so there is no underlying class.
So, is there any hope in registering components as per the second config?
EDIT:
Unfortunately, using the fluent configuration API is not an option at the moment. So to narrow my question down, is it possible to achieve this using the XML configuration?
I believe this is possible via the Fluent Registration API and the "UsingFactoryMethod" mechanism. I have tried to replicate your fabricated scenario in the below test case.
UPDATE
This is in fact possible with XML configuration as well. The trick is just to list the interface itself as the "type" in the configuration (or, equivalently, only specify the "type", as the "service" will be set to the "type" if it is not explicitly provided). I have updated the test case below to include a "TestXml" test that uses xml configuration to achieve your desired result. The "TestFluent" test uses the fluent registration API to achieve it. FYI, I am using Castle Windsor 2.0 here, as I'm guessing that's what you're using.
using Castle.DynamicProxy;
using Castle.Facilities.FactorySupport;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using NUnit.Framework;
namespace CastleTests
{
public interface ILoader
{
void Load();
}
public interface ILoaderFactory
{
ILoader GetLoader();
}
public class LoaderFactory : ILoaderFactory
{
public ILoader GetLoader()
{
return GetLoaderStatic();
}
public static ILoader GetLoaderStatic()
{
return (ILoader) new ProxyGenerator().CreateInterfaceProxyWithoutTarget(typeof (ILoader));
}
}
[TestFixture]
public class DynamicFactoryTests
{
[Test]
public void TestFluent()
{
using (var container = new WindsorContainer())
{
container.AddFacility<FactorySupportFacility>();
container.Register(
Component.For<ILoader>().UsingFactoryMethod(() => LoaderFactory.GetLoaderStatic())
);
var loader = container.Resolve<ILoader>();
Assert.That(loader.GetType().FullName, Is.EqualTo("Castle.Proxies.ILoaderProxy"));
}
}
[Test]
public void TestXml()
{
using (var container = new WindsorContainer("factory.xml"))
{
var loader = container.Resolve<ILoader>();
Assert.That(loader.GetType().FullName, Is.EqualTo("Castle.Proxies.ILoaderProxy"));
}
}
}
}
The content of "factory.xml" is thusly:
<castle>
<facilities>
<facility
id="factory.support"
type="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel" />
</facilities>
<components>
<component
id="foo"
service="CastleTests.ILoaderFactory, CastleTests"
type="CastleTests.LoaderFactory, CastleTests" />
<component
id="bar"
type="CastleTests.ILoader, CastleTests"
factoryId="foo" factoryCreate="GetLoader" />
</components>
</castle>

RadioButtonGroup with each RadioButton added in components?

Working in Flex 3, I have a series of components being rendered on a canvas, each of which should represent a single potential selection, ideally in a RadioButtonGroup. So in my parent canvas I am defining the RadioButtonGroup, and each component provides a single RadioButton. However, this doesn't seem to work.
Suppose there is a component called aComponent defined as such:
<mx:Canvas ...>
...
<mx:RadioButton id="someButton" groupName="myRadioButtonGroup" ... />
</mx:Canvas>
The outer canvas:
<mx:Canvas id="outerCanvas" ...>
...
<mx:Script>
public function doesSomething():void
{
var myComponent:aComponent = new aComponent();
outerCanvas.addChild(myComponent);
}
</mx:Script>
...
<mx:RadioButtonGroup id="myRadioButtonGroup" />
</mx:Canvas>
So my guess was that at this point if, say, four of these components were added, the radio buttons would behave in mutually exclusive fashion and I'd be able to access myRadioButtonGroup.selectedValue to get the current selection. However, it doesn't seem to work that way.
Is what I'm trying to do even possible, or have I maybe just missed something?
Thanks!
Edit - got to the bottom of it:
The radiobuttongroup isn't available to the component. It's parent has 'myRadioButtonGroup', but not the component.. Pass the 'myRadioButtonGroup' to the constructor and use it..
outerCanvas function:
var myComponent:aComponent = new aComponent(myRadioButtonGroup);
aComponent definition:
private var radioGroup:RadioButtonGroup;
function aComponent(radioGroup:RadioButtonGroup):void {
this.radioGroup = radioGroup;
}
</mx:Script>
<mx:RadioButton id="someButton" groupName="radioGroup" ... />
untested, but hopefully gives you the idea