How does the Form.getCommand(int index) work? - codenameone

I have a current Form(previousForm) with a previousForm as a parameter. My goal is to get a specific Command of this previousForm (reload the data of the previousForm and then do showBack()) from the current Form. The problem is that I can't reach this specific Command from my current form. While doing research on this problem, I found getCommand(int index) method, and I would like to clarify how it works.
The documentation of Form says that it
Returns the command occupying the given index
How can I find the index of my Command? Or how can I set it?
I see there is a Command's constructor Command(String command, int id) , however this id is not the index.

I suggest going at this in a different route. Just do something like this:
public class MyForm extends Form {
public void reload() {
//...
}
}
Then in your back command just downcast to MyForm and invoke reload. Make sure all forms are of type MyForm.
getCommand() is meant for use with getCommandCount() so you can loop over all commands and extract them from the parent Form.

Related

Instance of 'PostgrestFilterBuilder<dynamic>' to bool

i'm working on a flutter app and supabase. I have a table with some information and one of the column is a bool type.
when I recall an information of that column, I receive Instance of 'PostgrestFilterBuilder' and not a true/false information.
the code i used is this:
autorizzazione = supabase.from('profili').select('autorized').textSearch('usernumber', matricola!)
I think I'm so wrong with that code.
Update (31/12/2022)
I tried some experiments and I found a part of solution: Future function asynced.
If I use a function like this:
Future<Map<String, String>> _nameOfFunction(BuildContext context, String Input) async {
var output = supabase.from('table').select('column1, column2').textSearch('column1', Input);
...other code here...
return userinfo;
}
I receive exactly what I want, because "userinfo" saved the info. But, if I recall that funcion in a `Widget build(BuildContext context) {}', that doesn't work. It returns "Instance of 'Map<String, String>' " and not the real output.
However, my problem is to recall that info stored in that table on supabase before create the SideBar and used it for enable or disable the buttons.

PageInit does not work when on different class

As the title says I am using PageFactory to initialize my elements.
When I use PageFactory.initElements on the page I want to use my elements everything is fine and works correctly, but when I try to create a new class with PageFactory to have it initialize all elements there I get a null pointer exception.
Below you will find the code I am using:
Actions.java
TestIds testIds = new TestIds();
public void initElements(WebDriver driver) {
PageFactory.initElements(driver, cashierIds);
}
The above lines work when included in my Actions class but when I create a new Class called ElementInitialization.java, move everything in it and then call it my elements throw nullPointerException.
Is there a different way to call the specific faction to work everywhere?

AngularJS 2.0 binding & event handling

I am playing around with AngularJS 2.0
My very simple scenario consists of a select box that is bound to a property of component attribute, like this:
<select [(ngModel)]="zeitraum" [value]="zeitraum" (change)="calculate()">
<option>....</option>
</select>
The component class looks like this:
export class MyComponent
{
constructor
(
public zeitraum: number = 10,
public result: number = 0
)
{
}
public calculate()
{
this.result = this.zeitraum * 5;
}
}
So, I have a select box with a couple of options and I want the following behaviour: when a new option is selected, call the calculate() method which simply multiplies 'zeitraum' by 5 and then sets the value of 'result' which is then displayed on the page.
<h1>Result: {{result}}</h1>
The problem is as follows: The calculate method is called but it uses the OLD value of 'zeitraum' (that is, the value before a new option was selected).
I wonder which event to use here. I tried a workaround by using (mouseleave) and (mousemove) events and that seemed to work but it's a really dirty hack so there should be a more elegant solution.
Either I am using the wrong event or I got something else wrong with my Angular code.
Has anybody a suggestion? Thanks a lot in advance.
You should be able to do it like this:
<select [(ngModel)]="zeitraum" (change)="calculate($event.target.value)">
<option>....</option>
</select>
public calculate(zeitraum)
{
this.result = zeitraum * 5;
}

How to show computed property values in EPiServer 8?

In page edit mode I want to show a read-only text that is based on a page property value. The text could for example be "A content review reminder email will be sent 2015-10-10", where the date is based on the page published date + six months (a value that will be configurable and therefore can change anytime). So far I've tried to accomplish something like this by adding another property on the page.
I've added the property CurrentReviewReminderDate to an InformationPage class we use. In page edit mode the property name is shown, but it doesn't have a value. How do I do to show the value in page edit mode (preferably as a label)?
[CultureSpecific]
[Display(
Name = "Review reminder date",
Description = "On this date a reminder will be sent to the selected mail to remember to verify page content",
Order = 110)]
[Editable(false)]
public virtual string CurrentReviewReminderDate
{
get
{
var daysUntilFirstLevelReminder =
int.Parse(WebConfigurationManager.AppSettings["PageReviewReminder_DaysUntilFirstLevelReminder"]);
if (CheckPublishedStatus(PagePublishedStatus.Published))
{
return StartPublish.AddDays(daysUntilFirstLevelReminder).ToString();
}
return "";
}
set
{
this.SetPropertyValue(p => p.CurrentReviewReminderDate, value);
}
}
EPiServer internally uses the GetPropertyValue method (i.e. the opposite of SetPropertyValue) when retrieving content for the UI.
This makes sense, otherwise your "made-up" value would be stored as the real value whenever the content is saved. This would make fall-back values etc impossible to implement.
So, this is by-design (and quite wisely so) in EPiServer. :)
However, you can customize how properties work by:
Using custom editors by applying UI hints
Modifying property metadata (for example, to display a generated value as a watermark in a textbox without interfering with the actual value being saved)
I could be misunderstanding what you're trying to do, but off the top of my head it looks like a custom editor could be a viable option for your use case?
Another solution would be to hook into the LoadedPage-event and add the value from there. This might not be the best way performance-wise since you need to do a CreateWritableClone, but depending on the site it might not matter.
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class EventInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
ServiceLocator.Current.GetInstance<IContentEvents>().LoadedContent += eventRegistry_LoadedContent;
}
void eventRegistry_LoadedContent(object sender, ContentEventArgs e)
{
var p = e.Content as EventPage;
if (p != null)
{
p = p.CreateWritableClone() as EventPage;
p.EventDate = p.StartPublish.AddDays(10);
e.Content = p;
}
}
}

What use has RoutedCommand' class constructor ownertype argument?

The constructor of the RoutedCommand has "owner type" as a last argument. What is its significance? When it is used?
MSDN documentation gives completely no clue about why it's needed and whether I could use one type for all commands
Quote from MSDN
ownerType
Type: System.Type The type
which is registering the command.
There is one more thing. What type should I use when creating new routed commands dynamically from array of names. It looks like that any type works, so I'm using UIElement, but if there is a more suited type for this I would like to know.
The source for RoutedCommand shows that the type becomes the OwnerType property. This property is queried ultimately by the following private method when getting InputGestures. So it looks as though this type is being used to lookup a (hard-coded) set of Commands based on the type that created the RoutedCommand.
private InputGestureCollection GetInputGestures()
{
if (this.OwnerType == typeof(ApplicationCommands))
{
return ApplicationCommands.LoadDefaultGestureFromResource(this._commandId);
}
if (this.OwnerType == typeof(NavigationCommands))
{
return NavigationCommands.LoadDefaultGestureFromResource(this._commandId);
}
if (this.OwnerType == typeof(MediaCommands))
{
return MediaCommands.LoadDefaultGestureFromResource(this._commandId);
}
if (this.OwnerType == typeof(ComponentCommands))
{
return ComponentCommands.LoadDefaultGestureFromResource(this._commandId);
}
return new InputGestureCollection();
}
I know this is a very old question, but it's the top search hit for "routedcommand ownertype".
Storing an OwnerType and Name within each RoutedCommand object gives you a hint on how to find references to it in code. Suppose you are running the debugger on some method that has an arbitrary ICommandSource parameter. You can examine the Command property, and if you see that OwnerType is CommonCommands and Name is "DoSomething", you can navigate to the DoSomething field of the CommonCommands class, where there might be a useful comment, or search for references to CommonCommands.DoSomething to find associated CommandBindings or something. Without those properties, the RoutedCommand would just be an anonymous object.
I don't know if that reason was what the API designers actually had in mind when they included the argument, but it has been useful to me at least.

Resources