Is it possible to use a URL parameter as a property binding in UI5?
My problem is that I want to have different OData collections placed in the same UI5 aggregation. For example let's say I've "/Car("Mustang")/parts" and "/Car("Whatever")/parts". Both of them can be placed in the same view.
The application's URL contains the keyword like http://something/#/carMustang. This URL is coming from a routing pattern like "car{carHandle}".
How am I supposed to do stuff like this:
<List items="{/Car({carHandle})/parts}">
<StandardListItem title={someProperty}>
</StandardListItem>
</List>
So what would be the best practice to do this? I would like to avoid nasty fiddles in the controller.
In your view:
<List id="parts" items="{parts}">
<StandardListItem title="{someProperty}"/>
</List>
In your controller code which reacts on matched routes:
var carHandle = event.getParameter("carHandle");
this.byId("parts").bindObject("/Car/" + carHandle);
Related
In my XSOData service I have an entity based on calculation view with input parameters. I can to set these parameters as constants in my XML view, i.e.
<List items="{dicts>/AncParams(p_dict_name='GROUPS',p_rec_id=2)/Results}" >
<StandardListItem
title="{dicts>NAME}"
/>
</List>
and it will work fine.
But how I can set parameters p_dict_name and p_rec_id dynamically? I tried to use expression bindings to get values for parameters from another model (something like this: <List items="{= ${dicts>/AncParams(p_dict_name='GROUPS',p_rec_id=${DictUIProps>/parentId})/Results} }" >) but with no luck. As I understand, expression bindings won't work. Is there any other way?
As far as I'm aware you can't do the aggregation binding dynamically through XML. At least not in the versions I have used and I have to admit I haven't re-checked in a while. The string never gets interpreted for inner bindings before it's applied to the model.
The way I do this is through the controller:
<List id="myList" />
and in your controller (onBeforeRendering or onPatternMatched or wherever your model and view are known to the controller):
this.getView().byId('myList').bindItems({
model: 'dicts',
path: `{/AncParams(p_dict_name='${p_dict_name}',p_rec_id=${p_rec_id})/Results}`,
template: new sap.m.StandardListItem({
title: '{dicts>NAME}'
})
});
you can use the getModel('dicts').createKey function to generate the path name which is a little cleaner I suppose.
This is the way to apply dynamic filters as well, In case you ever build those.
I am quite new to oData webservices. I would like to get and populate the following output on mobile platform. I could able populate the following url data on mobile platform http://services.odata.org/V4/Northwind/Northwind.svc/Customers . However, once I started on doing another exercise. I am stuck with the following odata output. How could I access to properties, such as Name or Description?
PUT /OData/OData.svc/Products(1) HTTP/1.1 Host: services.odata.org DataServiceVersion:
1.0 MaxDataServiceVersion: 2.0 accept: application/atom+xml
content-type: application/atom+xml Content-Length: 1181
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Entry xml:base="http://services.odata.org/OData/OData.svc/"
xmlns:d=" http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m=" http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<id>http://services.odata.org/OData/OData.svc/Products(1)</id>
<title type="text"></title>
<updated>2010-02-28T10:23:02Z</updated>
<author>
<name />
</author>
<Link rel="edit" title="Product" href="Products(1)" />
<category term="DataServiceProviderDemo.Product"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:ID m:type="Edm.Int32">1</d:ID>
<d:Name>Milk</d:Name>
<d:Description>Low fat milk</d:Description>
<d:ReleaseDate m:type="Edm.DateTime">1995-10-21T00:00:00</d:ReleaseDate>
<d:DiscontinuedDate m:type="Edm.DateTime" m:null="true" />
<d:Rating m:type="Edm.Int32">4</d:Rating>
<d:Price m:type="Edm.Decimal">4.5</d:Price>
</m:properties>
</content>
</Entry>
There are several ways to access specific properties, as there are two kinds of properties on a entity: a non-navigation property and a navigation property.
A non-navigation property is either a primitive type property, a collection of primitive type property, a complex type property, a complex type property, or a stream property. When you query the entity set or a specific entity, the values of the non-navigation properties are by default inline of the entity payload:
e.g. ID, Name, Description, etc. are inline when you query:
GET http://services.odata.org/v4/odata/odata.svc/Products
If you want to choose the properties you need, you can use the $select query option. E.g.
GET http://services.odata.org/v4/odata/odata.svc/Products?$select=ID,Name
By appending such query option, you will find only the properties you need inline of the payload.
If you want to only access the property value, you should append the property name as a segment to the request URL to a single entity. E.g.
GET http://services.odata.org/v4/odata/odata.svc/Products(1)/ID
There is another kind of property: the navigation properties. They are either an entity type property or a collection of entity type property. Navigation properties describes the relationship between the different entities in the service. An example is the Categories navigation property on the Product entity.
Navigation properties are by default not shown inline of the entity payload. In order to include them inline, the $expand query option needs to be used:
GET http://services.odata.org/v4/odata/odata.svc/Products?$expand=Categories
If you want to only access the navigation property, the request URL is similar as it is for non-navigation properties:
GET http://services.odata.org/v4/odata/odata.svc/Products(1)/Categories
To learn more about how to issue different OData requests for different scenarios and what the URL conventions is, the following materials are helpful:
The tutorials on OData.org: http://www.odata.org/getting-started/basic-tutorial/ (basic), http://www.odata.org/getting-started/advanced-tutorial/ (advanced).
The URL convention spec of OData V4: http://docs.oasis-open.org/odata/odata/v4.0/os/part2-url-conventions/odata-v4.0-os-part2-url-conventions.html
The protocol spec of OData V4: http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html
Can I preserve object across actions in Struts2 without using session?
I'm working on a Struts2 project and curious if there are some ways to preserving object
value once an action is ended.
What I'm trying to do is:
Calling an action to read from an uploaded file and prepare its contents as a list of objects.
Then I display the list as an example for the user.
Then the user can click on a submit button to call an action to process the list which is created from the first action.
Usually the list would be lost once the action is end. So, I have to store the list as a session, but I think it should have some better methods to achieve the I'm working on.
If you want to preserve data across requests the session is the normal mechanism for doing so.
If you don't use the session you'd need to essentially duplicate its functionality to maintain the data associated with the current user/conversation.
If you need to preserve the List, then you have to use the Session.
But if you (if I've understood your problem) just need to handle the List through
ActionOne (that creates the List) ->
JSPOne (thast shows the List to the user) ->
ACtionTwo (that receives the List from JSPOne and does some business with it)
, without having to worry about the fact that the user can change the List client-side (for example manipulating the web page with FireBug), then you don't need the session.
You just need the List object to be declared on ActionOne and ActionTwo (with getters and setters, at least the getter on ActionOne and at least the setter on ActionTwo), and to include List name and index on name attribute of JSP tags.
If you just draw it (like with <s:property/> tag), instad of using some tag that will post the value, like <s:textfield />, then just use an <s:hidden /> to post te value.
For example, if you have:
List<MyObject> myList //with getters and setters
and assuming that MyObject has id and value fields (with getters and setters),
in JSP instead of
<s:iterator value="myList" >
<s:property value="id"/>
<s:textfield name="value"/>
</s:iterator>
use
<s:iterator value="myList" status="ctr" >
<s:hidden name="myList[#ctr.index].id" value="id"/>
<s:property value="id"/> <!-- no need here, you won't post this -->
<s:textfield name="myList[#ctr.index].value" value="value" />
</s:iterator>
You will eventually validate a List like this throught the Visitor Validator (somewhewre in the future after all the rest is done :)
Enjoy
I am using ASP.NET MVC 2 with SparkViewEngine 1.1 and I get the error message An object reference is required for the non-static field, method, or property 'Spark.Web.Mvc.SparkView.Url.get' when I use the following code in the Application.spark view file
<global baseImagePath='Url.Content(Context,"~/Content/_images")' type="string" />
What I am trying to accomplish is basically define a base image path as a global variable that can be referenced in the page templates.
For example, in Home/Index.spark, which uses the master Application.spark, I would have the following code snippet in the view
<img src="${baseImagePath}" alt="..." />
As a workaround, I can set a hard-coded value when I set baseImagePath by doing <global baseImagePath='"~/Content/_images"' type="string" />, but I want to also be able to resolve the "~" before hand.
Any suggestions?
Thank you!
Edit
I am adding my solution here per Rob's suggestions
In Shared/_global.spark, I added <use namespace="System.Web" /> so that I have access to the System.Web namespace.
In Shared/Application.spark, I added
<global baseImagePath='VirtualPathUtility.ToAbsolute("~/Content/_images")' type="string" />
The problem here is that Url.Content(... is accessing the UrlHelper class in System.Web.Mvc from the SparkView instance. The problem is that when the Application.spark is being parsed for globals, you don't yet have an instance of a view because global variables are defined before the generated view class is instantiated. Therefore accessing and instance variable like Url from the view is not possible.
From the looks of it though, you're just trying to get an absolute path from a relative one. For this you could potentially just use the static VirtualPathUtility class from System.Web.
There are a number of methods on there like ToAbsolute(...) that make life easier. Alternatively, you could get it from the HttpContext.Current.Server.MapPath(...) method if you have the current context.
Hope that helps,
All the best,
Rob G
In one of my controller actions, I'm generating some XML. One of the attributes in that XML is an href to another controller and action, with some parameters. The XML should look something like this:
<projects>
<project id="42" name="Project X", href="/projects/42"/>
<!-- etc. -->
</projects>
I don't mind if the URL is relative or absolute, but my question is this: how do I generate the URL in the controller code, in a type-safe way?
In other words, how do I do what HtmlHelper.ActionLink does, but from a controller?
Found it by using Reflector:
string href = Url.Action("DetailsAsXml", new { projectId = item.Id });