Parameters on Url.Action() have null properties - razor

I have the following code:
onClick="location.href='#Url.Action("StampPdf", "EditPdf", new {pView = currentPdfView})'" />
which when clicked calls a method called StampPdf(PdfView pView) on a controller called EditPdfController. The controller method is called, with the variable pView, but instead pView has all its properties equal to null. It's as if the PdfView class has been instantiated afresh. Within my cshtml razor file, currentPdfView is instantiated and has all properties with values assigned to them, but in the controller the properties are null.
This user here had the same issue, but there is no followup on whether it was resolved or not.
Is there something I need to do to make this work?

It doesn't know how to serialize the model into a query string :)
You need to break your model into multiple properties with simple values, or use a form POST to submit them as a model.
You can also serialize the model into e.g. JSON and pass it as a string.

Related

How can I configure an action that creates a variable number of objects?

I am looking to create an action type that can be used to create a variable number of objects of a given object type. In other words, a user should be able to use this action to create 3 objects at once, 5 objects at once, etc.
I tried to accomplish this using the action configuration UI in OMA, but ran into the following issues:
I noticed that in the “Rules” section, it is only possible to define a static number of objects to be created. In the example shown in the screenshot below, you’d only be able to create 2 objects rather than a variable number.
Similarly, there is no way to specify a variable number of parameters in the “Form” section, which would be necessary to capture the primary keys for each object the user would like to create. I thought of specifying a string parameter that takes in multiple values as an alternative, but that wouldn’t work because there is no way to assign a single value from this parameter to an object property.
How should I go about accomplishing this?
It would be possible to create a variable number of objects using a function backed action! In particular, you could take the following steps:
Create a new function that takes in a list of primary keys as input and creates an object for each primary key in the list. The code for this function could look something like this:
#Edits(ObjectA)
#OntologyEditFunction()
public createMultipleObjects(primaryKeys: string[]): void {
// Loop through pkeys and create a new object for each pkey
primaryKeys.forEach(k => {
Objects.create().objectA(k)
});
}
You can also reference the following documentation for more guidance on how to define Ontology edit functions.
Create an action in OMA that calls the function that you defined in step 1. You will need to define a multi-value string parameter for this action, which will be passed as an input to the function.
You can refer to the following documentation (https://www.palantir.com/docs/foundry/action-types/function-actions-getting-started/) for a step by step guide on how to configure a function backed action.

how to catch event in codes after linking events in an array of string inside “events” properties of form object variable in dynamic 4D form?

It's easy to catch events from 4D object's methods of 4D binary form (traditional 4D form) but didn't find any clue to do this in the json dynamic form.
I already gave a try with some 4D commands (CALL FORM, CALL WORKER or POST OUTSIDE CALL) as well to install a project method for a form side by side in a new process inside a loop where I handled events inside that project method. But couldn't get around it. Also I couldn't find any solution/example for this in kb or 4D blog or anywhere.
So any example or database template would be more helpful.
Ravi,
Simply string them in an array named "events".
The docs are your friend for things like this: 4D Manual/Dynamic Forms#Events
The "events" property accepts a JSON array (collection) of strings or
numbers. To call an event, enter the event's name or value (see form
event constant values). For exemple, "events":["onLoad"]) or
"events":[1]
I don't know if you can mix the literal and numeric references. I would expect so but haven't actually tested that.
Edit:
Ravi, if by "catch events in code" you mean have the form you've dynamically created respond to them then you will need to include the name of a project method in the "method" tag. You can't just write some code into an object when you build it dynamically, like you can in regular 4D, but you can call a project method. In that method you can use a Case of statement to test the Form event function to determine which event fired and respond appropriately.
You can't pass parameters to this method. But you can use Object get name or Object get pointer commands to determine the particular object that called it.
For example, let's say I include myMethod as the method. The code for myMethod might look like this:
Case of
:(Form event=On Clicked) // on Clicked is a 4D constant
// do something
:(Form event=on Data Change)
// do something else
End case
Or
Case of
:(Object get name(Object current)="myButton")
Case of
:(Form event=on Clicked)
...
End case
:(Object get name(Object current)="anotherName")
Case of
:(Form event=on Clicked)
...
End case
End case
This illustrates two approaches: 1) you write a separate method for each object or 2) write a single method and determine which object called it. I prefer #2 but that's strictly my opinion.

Yii2: Proper Structuring of Actions based on User Roles

I'm quite worried with the current way I structure actions in my controllers.
I'm not sure which is the more adopted method for implementing actions that show different things for different users based on their type.
For example:
Creating a Model when User is Type 1 uses the same action but passes more parameters to the view than User Type 2.
Creating a Model when User is Type 2 uses same action but passes less parameters to the view and hence there are if statements in the view to show/hide fields based on the User Type.
Is this a proper way of doing things? If not, can you direct me to some documentation that explains a good structure?
Thanks & appreciate your help.
A simple but trival way is this
you can pass an array (eg $param) and then evaluate the type for do the right thinghs inside your action
public function actionYourAction( $param)
{
$type = $param['type'];
switch($param['type']){
case 'TYPE1' :
....
break;
}
a more clean solution could be a proper object oriented class method specialization for user object, instantiate the proper user object where you nedd and pass thsi in action call. Inside the actione simply use the object (specilized) method .

Compatability when passing object to class

Ok, so this might be me being pendantic but I need to know the best way to do something:
(This is psudocode, not actual code. Actual code is huge)
I basically have in my package a class that goes like this:
internal class charsys extends DisplayObject {
Bunch of Variables
a few functions
}
I another class which I intend to add to the timeline I want to create a function like this:
public class charlist {
var list:Array = new Array();
var clock:Timer = new Timer(6000);
var temp:charsys;
function addObj(MC:DisplayObject, otherprops:int) {
temp=MC;
temp.props = otherprops;
list.push(temp)
}
function moveabout(e: event) {
stuff to move the items in list
}
function charlist() {
stuff to initialize the timers and handle them.
}
}
So the question is, is my method of populating this array a valid method of doing it, is there an easier way, can they inherit like this and do I even need to pass the objects like I am?
(Still writing the package, don't know if it works at all)
Yes, you can pass an object into a function, but you should be careful of what you are planning to do with that object inside that function. Say, if you are planning to pass only charsys objects, you write the function header as such:
function addObj(MC:charsys, otherprops:int) {
Note, the type is directly put into the function header. This way Flash compiler will be able to do many things.
First, it will query the function body for whether it refers to valid properties of a passed instance. Say, your charsys object does not have a props property, but has a prop property, this typing error will be immediately caught and reported. Also if that props is, for example, an int, and you are trying to assign a String value to it, you will again be notified.
Second, wherever you use that function, Flash compiler will statically check if an instance of correct type charsys is passed into the function, so if there is no charsys or its subclass, a compilation error is thrown.
And third, this helps YOU to learn how to provide correct types for functions, and not rely on dynamic classes like MovieClip, which can have a property of nearly any name assigned to anything, and this property's existence is not checked at compile time, possibly introducing nasty bugs with NaNs appearing from nowhere, or some elements not being displayed, etc.
About common usage of such methods - they can indeed be used to create/manage a group of similar objects of one class, to the extent of altering every possible property of them based on their corresponding values. While default values for properties are occasionally needed, these functions can be used to slightly (or not so slightly) alter them based on extra information. For example, I have a function that generates a ready-to-place TextField object, complete with formatting and altered default settings (multiline=true etc), which is then aligned and placed as I need it to be. You cannot alter default values in the TextField class, so you can use such a function to tailor a new text field object to your needs.
Hope this helps.
This would work, I think I would assign values to the properties of the charsys object before passing it into the add method though, rather than passing the properties and having a different class do the property assignment. If you have some common properties they could either have defaults in charsys class definition or you could set literals in the addObj method.

How to define binding with respect to MVC design pattern?

I have some confusion on what we call "binding" as ?
Is it :
1) Change in [Bindable] Model which leads to an automatic change in View ( bound to that model )
OR
2) Change in View and then an automatic change in the [Bindable] Model ( the View is bound with )
Thanks
The typical use of data binding in Flex is to bind some model object to a view object (#1).
In Flex 4, two way binding was introduced. This does both #1 and #2. That is any change made in the model is reflected in the view. But also, any change made to the value in the view updates the model value.
To use two way binding, add the # symbol to the binding expression in the view:
<s:TextInput text="#{model.someValue}" />
Note that when you make something Bindable, the mxml compiler generates a setter method for your Bindable variable, which dispatches an event anytime the variable changes. The mxml compiler then adds event listeners for this event to the view objects that are bound to the variable. So technically, any object (whether it is a view, model, controller, or something else) can be bound to a variable, as long as it can receive the event.