how to bind data to a Grid Layout in sapui5 xml view - json

I have a list of StandardListItem elements under a Grid and would like to bind them to a json file using a json model.
This is how I do the binding in my controller. I'm confident this part is correct as I'm doing it this way for a table.
var pricingModel = new JSONModel("./model/evaluation.json");
//set model(s) to current xml view
this.getView().setModel(pricingModel, "pricingModel");
This is a piece of my xml view where I'm trying to bind my data
<l:Grid class="sapUiSmallMarginTop"
id="priceEvalGridContainer" visible="false"
binding="{/PriceEstimate}">
<l:content>
<l:VerticalLayout id="priceEvalCol1" width="100%">
<StandardListItem title="NSN"
info="{NSNID}"/>
<StandardListItem title="DLA Price Estimate (DLA)"
info="{DLAPriceEstimate}"/>
<StandardListItem title="Proposed Price"
info="$20.00" />
</l:VerticalLayout>
<l:VerticalLayout id="priceEvalCol2" width="100%">
<StandardListItem title="$ Difference From DLA" info="$1.50" />
<StandardListItem title="Total Price Difference" info="$135.00" />
<StandardListItem title="PPI Price Adjusted For Inflation" info="$18.59" />
</l:VerticalLayout>
</l:content>
</l:Grid>
I have hard-coded a lot of the values as I haven't been able to properly connect the data. The only items being tested for now are info="{NSNID}" and info="{DLAPriceEstimate}"
I've seen examples on how to bind a StandardListItem within a List or a Grid with other type of objects, but haven't seen it being done together.
I tried doing the binding in the following way but it didn't work for me.
<l:Grid class="sapUiSmallMarginTop"
id="priceEvalGridContainer" visible="false"
binding="{
path: '/PriceEstimate'
}">
The app runs with no problems and there are no errors being shown, however the data does not show up in the grid. It's just blank.

this.getView().setModel(pricingModel, "pricingModel");
Since you are using named model, use:
binding="{pricingModel>/PriceEstimate}"
And if this data JSON is an array, you may have to give index in the content like:
info="{pricingModel>0/NSNID}"
else: info="{pricingModel>NSNID}" will do. (Similarly for others)
Either way, it depends on the data. So add how pricingModel looks.

Related

Iterate through DataContext items without casting it to a viewmodel type

Is their a way to access Items contained in a DataContext without having to explicitly cast it to this ViewModel.
Let's say I'm binding a DataContext on an MvxFrameControl view, then I obtain this DataContext in code-behind once it is binded. It will look like an anonymous object containing a list of Items that are known as the children of this ViewModel. Can I swiss-bind these items, or some properties of this DataContext to another object, and so on?
I.e.
this.DelayBind(() =>
{
var data = DataContext;
// It looks like data contains something called "Items" with a list of children viewModels.
});
Can I access DataContext.Items[0], or at least DataContext.Items, and bind it to an observable collection? Then finally swiss-bind some Items to views (MvxFrameControls) on their DataContext?
So, summary: I'm curious if there is a way to work in code-behind with DataContext and its content so I could create a generic MvxFrameControl that would dispatch the data to custom views based on swiss-binding.
I have ViewModels containing lists of lists, and I want to handle a lot of situations in code-behind as I've experienced a lot of memory problems with MvxListViews containing MvxListViews.
[Edit]
This is actually what I was doing in my code that led me to think I should completely redefine how bindings are done. I'll write a minimal fake axml:
// Warning to anyone: this is a fake layout, don't use that
view_myactivity_layout.axml :
<LinearLayout>
<MvxListView
android:MvxItemTemplate="#layout/food_category_item"
local:MvxBind="ItemsSource FoodCategories" />
</LinearLayout>
food_category_item.axml:
<LinearLayout>
<TextView
local:MvxBind="Text Category" />
<MvxListView
android:MvxItemTemplate="#layout/list_of_food_for_a_category_item"
local:MvxBind="ItemsSource FoodList" />
</LinearLayout>
list_of_food_for_a_category_item.axml:
<LinearLayout>
<TextView
local:MvxBind="Text NameOfThatFood" />
<MvxListView
android:MvxItemTemplate="#layout/list_of_colors_for_that_food_item"
local:MvxBind="ItemsSource FoodList" />
</LinearLayout>
[Etc...]
Nesting binded controls works well, but there are tons of GC happening when scrolling. So that's why I was thinking about making my own binding pattern using reflection for this case.

Passing a variable as a parameter to an ssrs report

I am trying to pass a variable from my classic asp page to ssrs. When I put in a literal value for the parameter, such as 296, it works fine. But I want to put in a variable that is sent by the URL so that it works in different ways for different people who are logged in. So, instead of a URL that is http://servername.net/reportserver....rs:Command=Render&Agency=296 (for the agency that is number 296) I want to use a variable that I have set to the agency of the person who has logged in. Let's say the variable is pAgency. I have tried Agency=" #pAgency (I set pAgency = to the logged in person's agency) and all sorts of other combinations, and have searched the web, but find no answer for this. I've even tried session variables but, no go. You must be able to do this but...
Thanks for any help you can give. Cheers!
That is not how a rest URI works to my knowledge. You need to build the string and present it first fully formed, not define a variable on it. You could do somthing in code like (using HTML Form as a base)
In the example below there are four clear things to understand:
A. The 'action' in the form must be the webservice location of a report and do a post to self. (Or you can do an iframe element potentialy but I have not messed with that as much)
B. The 'input' element is text based but you MUST match the id and name to the name of your parameter passing in.
C. The 'select' element gives a user 'option's of save methods to output directly to common types.
D. The 'input' for a type of 'submit' ensure the form will post to itself with the data prescribed.
<!DOCTYPE HTML>
<html>
<head>
<title>SSRS Tester</title>
</head>
<body>
<form id="SSRSRender" action="http:// (reportservername)/ReportServer?/(pathtoreport)" method="post" target="_self">
<H3>Enter some detail for the report to render</H3>
My Variable 'Test': <input type="text" id="Test" name="Test">
<br/>
My outputs:
<select ID="rs:format" name="rs:format" size=1>
<option value="HTML4.0">HTML 4</option>
<option value="IMAGE">Tiff Image</option>
<option value="PDF">PDF</option>
</select>
<br/>
<input type="submit" value="Render Report">
</form>
</body>
</html>
If you want to do more types of input variables to dynamically get SSRS to render as you want outside of the SSRS landing page you need to determine if you want to use:
The service with some front end with scripting like javascript with HTML
Something more easy to control will pre built tools like 'Report Viewer' with ASP.NET or a client application in C# or VB.NET
Create the service proxy yourself in a class library and do the calls in code directly as well as the formatting
Trying to create a rest URI programatically is better done by contacting the service and using built in methods IMHO rather than trying to make a string. It may be a little more of a learning curve but it will help you in the end.

Struts2 Jquery Plugin : proposal for an autocompleter doesn't reduce

My autocompleter
<sj:autocompleter
id="auto"
name="credit"
href="%{url}"
list="objectsList"
listValue="name"
listKey="id"
delay="50"
loadMinimumCount="2"
forceValidOption="false"
onChangeTopics="autocompleteChange"
onFocusTopics="autocompleteFocus"
onSelectTopics="autocompleteSelect"
/>
recognizes the json source but when typing a value it highlights the result without reducing the list (700 members long so it's impossible to use).
This works implementing a term attribute in the json action and filtering the result on it.

Spring Security multiple filterChainProxy mapping/filters, custom filters Json Output

I have a part of my web application that is an RESTfull api and part a more standard web-pages.
I wish to have the REST part with some custom filters such as the EntryPoint, SuccessHandler and FailureHandler. This part is within the /rest/** mapping.
In the other hand, everything else needs to have more common filters and is mapped with /**.
The problem is to find an easy way to define the filterChainProxy with different mapping-filters.
Right now this solution doesn't work:
<!-- Normal web app -->
<http auto-config="true" use-expressions="true" authentication-manager-ref="authenticationManager">
<form-login/>
<logout/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
</http>
<!-- Configure RESTfull services -->
<http use-expressions="true" authentication-manager-ref="authenticationManager" entry-point-ref="restAuthenticationEntryPoint" >
<form-login authentication-success-handler-ref="restAuthenticationSuccessHandler" login-page="/rest/login" username-parameter="username" password-parameter="password" />
<logout logout-url="/rest/logout" />
<intercept-url pattern="/rest/**" method="GET" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/rest/**" method="POST" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/rest/**" method="PUT" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/rest/**" method="DELETE" access="hasRole('ROLE_ADMIN')" />
</http>
It complains with: the univseral match being before other patterns.
Is there a way to define such a thing without resorting to define the filterChainProxy with the definition? The http version does help quite a lot to reduce the amount of configuration as I will have to manually set a UsernamePasswordAuthenticationFilter etc.
The next problem is more simple: I have to respond, after the form-login authentication with a JSON object.
So far, I have implemented a SuccessHandler (actually a version of the SimpleUrlAuthenticationSuccessHandler without the redirect part).
How do I write my JSON output?
I must have something like this:
HTTP 200 OK
with:
{"success":true,"customer {"email":"customer#email.com","session_id":"b83a41dfaca6785399f00837888886e646ff9088"}}
and a similar thing with the FailureHandler. It must be quite simple and it's surely is some very basic thing, but how do you do that? Redirecting to a custom controller is not a solution since I will have the 301 redirect status that a very simple REST client might not be able to understand.
At the very least, I wish to have only the http header and no body at all.
thanks!
If you can upgrade to Spring Security 3.1 it supports multiple chains using namespace configuration.

set var value from input field value

I started short time ago with JSP, JSTL, HTML and JavaScript so here is my problem:
I need to set the value of a var the value of an input hidden. Other option is if it possible to compare using
<c:if test="....">
the value of a variable that I sent with the request with the value of the hidden input.
Thanks.
Update
I've been trying but can't make it work.
I have this field that contains the id of and object. I also have the list with the objects so what I have to do is find the object related to that ID.
<input type="text" name="id1" />
but if I do this:
<c:set var="dd" value="${param.id1}" />
<input type="text" value="${dd}" />
The input text is empty but the text related to id1 displays 850 (i.e. the value is dinamic)
Any suggestion why is not working?
Update 2
I need the "multipart/form-data" because in the form I need to upload a picture. I understand how to get the parameters from Java, but since I'm not using the server but the JSP pages, there's any way to do it? Just need to read that input element and save it in a variable.
You can access request parameters by implicit ${param} variable.
E.g. http://example.com/context/page.jsp?foo=bar in combination with
<c:if test="${param.foo == 'bar'}">
The foo's param value is bar!
</c:if>
<c:if test="${param.foo != 'bar'}">
The foo's param value is not bar, it is: ${param.foo}
</c:if>
would show the first condition.
If you actually want to retain some hidden input element in subsequent requests (which wasn't really made clear in your question), then all you basically need to do is:
<input type="hidden" name="foo" value="${param.foo}">
Update: as per your update: you need to give the input element a name as well. Thus, e.g.
<input type="text" name="id1" value="${param.id1}" />
This way it's available by request.getParameter("id1") and inherently also ${param.id1}. Do you see it now?
Update 2: as per your comment here: certainly this is related to enctype="multipart/form-data". With this encoding, the request parameters aren't in the parameter map anymore, but instead in the request body, because of the mixup with binary data (file uploads). It's going to be a long story to explain it all, but basically you need to parse the request yourself. If you're on Servlet 2.5 or older, then the Apache Commons FileUpload is very helpful here. Read especially "User Guide" and "Frequently Asked Questions" over there to see code examples and to learn how to use it the right way (also in MSIE!). You can even decide to abstract the FileUpload away so that you can stick using HttpServletRequest#getParameter() and ${param} the usual way, also see this article.
If you're already on Servlet 3.0, then you can just make use of HttpServletRequest#getParts(). You can even abstract it away so that you can stick using HttpServletRequest#getParameter() and ${param} the usual way, also see this article.
Update 3: Oh, you really don't want to use JSP to do all the processing. There it is not for. It's high time to learn Servlet. Besides, when using a Filter which puts all parameters from the request body back in the request parameter map (as described in the both articles), you also don't necessarily need a Servlet after all.