How to Use Internalization i18n in a Controller in SAPUI5? - internationalization

Could anyone please explain how it's possible to use a i18n text in a setValueStateText method in a controller?
oTP.setValueStateText("{i18n>co_Maximal_60_h}");
The error msg in the dialog shows only "{i18n>co_Maximal_60_h}" and not the real text.

the resource bundle is in the following way accessible in a controller:
...
var oResourceBundle = this.getView().getModel("i18n").getResourceBundle();
oTP.setValueStateText(oResourceBundle.getText("co_Maximal_60_h"));
...

You cannot set the binding string via setter method.
Here you have 2 options:
set the binding right in the view (use the same string but in XML)
utilize the ResourceBundle:
var oResourceBundle = this.getOwnerComponent().getModel("i18n").getResourceBundle();
var sTxt = oResourceBundle.getText("co_Maximal_60_h");
oTP.setValueStateText(sTxt);
I'd recommend to add a reusable method to your BaseController with a name "i18n", so whenever you need it, call 'this.i18n("i18n_key")'.

Related

presentViewController does not exist

I am building a plugin in NativeScript.
When I try to access "presentViewController" method on rootViewController, I get the error "property presentViewContrller does not exist".
const rvc = UIApplication.sharedApplication.keyWindow.rootViewContrller;
rvc.presentViewContrller(myViewController, true, completion() {});
It suggests to use presentViewContrllerAnimatedCompletion which does not accept my view controller.
Could you please assist what part of my code (or maybe setup!) is wrong?
The right method name is presentViewControllerAnimatedCompletion only.
You should combine the parameter names with method name while marshalling Objective C to JS/TS.
presentViewController:animated:completion

In CakePHP 3, how can I use the UrlHelper in a Shell to generate an URL?

To use Emails, I just
use Cake\Network\Email\Email;
$email = new Email();
but trying that with UrlHelper is unsuccessful.
As unsuccessful is with a
$url_helper = new UrlHelper;
because it gives me
Argument 1 passed to Cake\View\Helper::__construct() must be an instance of Cake\View\View.
But I don't have View in Shell, I suppose.
Thanks.
Using a helper in the shell is not the right way to approach this. The helper as well is just wrapping the Router. So instead use the Router directly:
use Cake\Routing\Router;
$url = Router::url([/*...*/], true);
Also note that you can change the base URL as needed by calling Router::fullBaseUrl(), it's a getter and setter. See the documentation.
This is better because:
It's introducing less dependencies
Less tight coupling (OK, you get a singleton instead...)
Doesn't violate MVC
Smaller footprint
You could probably follow a similar method for mocking out a helper in the shell as they do for mocking out a helper for unit testing. Try:
<?php
use Cake\View\View;
use Cake\View\Helper\UrlHelper;
class FooShell extends Shell
{
public $url_helper = null;
public function bar()
{
$view = new View();
$this->url_helper = new UrlHelper($view);
// URL Helper functionality created here
}
}
Here is the docs I used for mocking out a helper in CakePHP 3.

Return JsonNet type JSON from WebAPI in Orchard

In standard MVC I use JsonNet to return JSON that is in camelCase and sucessfully serializes entities that have related entities (which otherwise reports a "cycles" error" using the default serializer).
I'd like to do the same for a WebAPI controller in an Orchard module. By default it returns PascalCase JSON and reports a "cyles" exception when given a list of entities.
Can anyone explain how best to configure the JSON output from within the Orchard module, to mimic what JsonNet would produce?
I've found a workaround, which is to set the JSON formatters settings to camelCase in an ActionFilter:
public class CamelCaseJsonAttribute : ActionFilterAttribute {
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var jsonFormatter = actionContext.ControllerContext.Configuration.Formatters.OfType<JsonMediaTypeFormatter>().First();
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
}
But this seems inefficient, as it gets set on each request, rather than globally, once.
I'm guessing there is an extensibility point somewhere in a module to set the HttpConfiguration - can anyone tell me one way or the other?
Many thanks.

How can I specify the name of the controller in ASP.NET Web API?

I have an ApiController, quite simple, like this:
public class AssetController : ApiController
{
// removed for brevity
}
When I insert a route to it from a view, the url created is something like:
http://host/Asset
but I would like to customize the name, so that it becomes this:
http://host/assets
How can I specify a custom name for my controller, without resorting to a complete custom routing table?
When I insert a route to it from a view, the url created is something like: http://host/Asset
You haven't really shown how you are doing this inserting but the following should work fine:
#Url.RouteUrl("DefaultApi", new { httproute = "false", controller = "assets" })
and if you want an absolute url you could specify the protocol scheme as third argument:
#Url.RouteUrl("DefaultApi", new { httproute = "false", controller = "assets" }, "http")
And in order to obey RESTFul conventions you should rename your controller to AssetsController.
I'd recommend looking at the https://github.com/mccalltd/AttributeRouting library. It handles this aspect quite well by putting an attribute right on each function and giving it a specific route (which can be anything).
I've had to resolve this issue so I've opted to adjust my routing table to reflect the API that I really want.

MVC3 URL Parameters

I have some parameters in URL, which I would like to be present in the URL for all pages in my MVC3 app. For example:
mycompany.com/home?param=1
mycompany.com/cart?param=1
mycompany.com/logout?param=1
Whether the user is navigating to a new page or submitting a form, how can I have my parameter
be present in all my pages? Right now the only way I can think off is somehow reconstruct the URL for every new view I need to render. Is there built in functionality in MVC to do this?
Thanks
That sounds like something you should store in Session instead of updating all of your links to add the same parameter.
You could use a Session variable as the other poster suggested, or you could use a base view model which holds this static param value.
So your base view would be something like this:
public class BaseViewModel
{
public static int ParamValue = 1;
}
then in each view model you use for each view, you'd have something like this:
public class PageViewModel : BaseViewModel
{
// properties
}
This way, in each view, you can just reference #Model.ParamValue whenever you need to access it:
#Model Namespace.PageViewModel
My param value is <b>#Model.ParamValue</b>

Resources