UI5 odata failed to drill down - odata

Hello i set the binding context for an oData request, and the request is called fine.
But on ui5, i get the following error:
Failed to drill-down into Id, invalid segment: Id - ../oData/Users('44ce4852-5985-44c3-9a75-03e252747d29')?$select=Email,FirstName,Id,LastName,UserName sap.ui.model.odata.v4.lib._Cache
Controller:
onInit: function () {
this.getRouter().getRoute("userDetails").attachPatternMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
var sUserId = oEvent.getParameter("arguments").userId;
console.log(sUserId);
this.getView().bindElement({
path: "/Users('"+sUserId+"')",
model: "som"
});
console.log(sUserId);
},
View:
<Page >
<fLayout:SimpleForm editable="true"
layout="ResponsiveGridLayout"
title="{i18n>settings.user.title}"
labelSpanXL="3"
labelSpanL="3"
labelSpanM="3"
labelSpanS="12"
emptySpanXL="4"
emptySpanL="4"
emptySpanM="4"
emptySpanS="0"
columnsXL="1"
columnsL="1"
columnsM="1" >
<fLayout:content>
<Label text="{i18n>settings.user.id}" />
<Input editable="false" value="{som>Id}" />
<Label text="{i18n>settings.user.userimage}" />
<f:Avatar press="onAvatarPressed" imageFitType="Contain" displaySize="XL" />
<Label text="{i18n>settings.user.username}" />
<Input value="{som>UserName}" />
<Label text="{i18n>settings.user.email}" />
<Input value="{som>Email}" />
<Label text="{i18n>settings.user.firstname}" />
<Input value="{som>FirstName}" />
<Label text="{i18n>settings.user.lastname}" />
<Input value="{som>LastName}" />
</fLayout:content>
</fLayout:SimpleForm>
</Page>

I found the solution, my request was returning a list ant not a single object.

Related

how to write onclick event in reactjs?

here is my code
this is simple form. I am trying to call on click event on button click
render: function () {
return (
<form className="commentForm">
<input
type="text"
placeholder="Your name"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
value={this.state.text}
onChange={this.handleTextChange}
/>
<input type="submit" value="Post" />
</form>
);
You forgot to pass the onSubmit event for form
render: function () {
return (
<form className="commentForm" onSubmit={this.submit}>
<input
type="text"
placeholder="Your name"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
value={this.state.text}
onChange={this.handleTextChange}
/>
<input type="submit" value="Post" />
</form>
);
submit: function() {
// do your stuff
}
try this:
<form className="commentForm" onSubmit={this.handleSubmit}>
<input
type="text"
placeholder="Your name"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
value={this.state.text}
onChange={this.handleTextChange}
/>
<input type="submit" value="Post" />
</form>
Can you try like this
handleTextChange(e) {
const { name, value } = e.target;
this.setState({
[name]: value
});
}
_handleSubmit(e) {
e.preventDefault();
let { author, text} = this.state;
// dispatch the submit function
}
render: function () {
return (
<form className="commentForm" onSubmit={this._handleSubmit}>
<input
type="text"
placeholder="Your name"
name="author"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
name="text"
value={this.state.text}
onChange={this.handleTextChange}
/>
<input type="submit" value="Post" />
</form>
);
u want onclick method here it is onsubmit same work of onclick.
handleSubmit(){
console.log(this.state.author);// u can see the value of autor and say somthing input vale in here it is coming right value or not
console.log(this.state.text);
axios.post(route,{
name:this.state.author, //these name and say are the variable whice are use to take the values to back end
Say :this.state.text
}).then({response}); //here u cn give some thing to disply after data add to database.
}
<form className="commentForm" onsubmit={this.handleSubmit.bind(this)}>
<input
type="text"
placeholder="Your name"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
value={this.state.text}
onChange={this.handleTextChange}
/>
<input type="submit" value="Submit" />
</form>
You need not have separate onChange for two fields unless you do something different in each of them.
Render:
<form className="commentForm" onSubmit={this.handleSubmit}>
<input
type="text"
placeholder="Your name"
name="author"
onChange={this.handleChange}
/>
<input
type="text"
placeholder="Say something..."
name="text"
onChange={this.handleChange}
/>
<button type="submit" >submit</button>
</form>
When submit is clicked :
handleSubmit = (e) => {
e.preventDefault();
console.log(this.state.author) //whatever you want to process the data with...
}
You can have single handleChange to set the state
handleChange = (e) => {
const { value, name } = e.target;
this.setState({ [name]: e.target.value })
}

sapui5 - unable to perform expand query in OData v2 model

I develop a little demo application with SAP Netweaver Gateway OData as a backend and SAPUI5 1.44 as UI. I am facing a problem with expanding data with the OData v2 model.
My OData service has 3 entity sets: INDSet, INFSet and INDINFSet. INDSet has a 1:N navigation to INDINFSet, so I'm able to get all INDINFs for particular IND via the following URL:
/sap/opu/odata/SAP/ZGW_ODATA_TEST_SRV/INDSet('IND0000001')/INDINFSet
My UI consists of 2 views:
master view: only has one table.
detail view: a form which I display as a dialog screen. The form has fields of the IND entity and a table which contains INDINFSet records.
The problem is that there is no data on detail view - neither in master entity fields, nor in details table. I don't see any requests in "Network" tab of Chrome dev tools when I open Dialog form - neither on mock server, nor on NW Gateway backend.
Here is a code in master controller which opens the form dialog:
var tbl = this.getView().byId('IndsTable');
var ctx = tbl.getContextByIndex(tbl.getSelectedIndex());
var oData = ctx.getProperty(ctx.sPath);
var sContentDensityClass = this.getOwnerComponent().getContentDensityClass();
var oView = this.getView();
var controller = sap.ui.controller("demo.modules.indform.controller.IndFormDialog");
controller._indFormDialog = oView.byId('IndFormDialog');
if (!controller._indFormDialog) {
controller._indFormDialog = sap.ui.xmlfragment(oView.getId(),
'demo.modules.indform.view.IndFormDialog', controller);
jQuery.sap.syncStyleClass(sContentDensityClass, oView,
controller._indFormDialog);
oView.addDependent(controller._indFormDialog);
}
oView.bindElement({
path: sPath,
model: 'mInd'
});
controller.openDialog(oView);
And here is the dialog itself:
<core:FragmentDefinition
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:l="sap.ui.layout"
xmlns:f="sap.ui.layout.form"
xmlns:t="sap.ui.table"
xmlns:fb="sap.ui.comp.filterbar"
xmlns:core="sap.ui.core">
<Dialog
id="IndFormDialog"
contentWidth="44rem"
contentHeight="49rem"
class="sapUiNoContentPManageing"
showHeader="false"
verticalScrolling="false"
>
<content>
<f:SimpleForm
class='IndForm'
id="IndForm"
maxContainerCols="2"
editable="false"
layout="ResponsiveGridLayout"
labelSpanL="12"
labelSpanM="12"
labelSpanS="12"
emptySpanL="0"
emptySpanM="0"
emptySpanS="0"
columnsL="2"
columnsM="2"
columnsS="2">
<f:content>
<core:Title/>
<Label text="Index code" />
<Input
type="Text"
value="{mInd>/Id}"
/>
<Label text="Index name" />
<Input
type="Text"
value="{mInd>/Sname}"
/>
<Label text="Actual till" />
<DatePicker
value="{mInd>/Eusdt}"
/>
</f:content>
</f:SimpleForm>
<t:Table
id="Infosystems"
rows="{mInd>INDINFSet}"
visibleRowCount="10"
visibleRowCountMode="Auto"
selectionMode="None"
enableSelectAll="false"
ariaLabelledBy="title"
>
<t:toolbar>
<Toolbar>
<Title
id="infosystableTitle"
text="Infosystems"
level="H3"/>
</Toolbar>
<Button
icon="sap-icon://add"
tooltip="Add record"
press="addInfosystem" >
<layoutData>
<OverflowToolbarLayoutData priority="NeverOverflow" />
</layoutData>
</Button>
</t:toolbar>
<t:columns>
<t:Column>
<Label text="Infosystem"/>
<t:template>
<ComboBox
items="{
path: 'mInfs>/INFSet',
sorter: { path: 'Name' },
templateShareable: true
}"
>
<items>
<core:Item key="{mInfs>Id}" text="{mInfs>Name}" selectedKey="{mInd>Infosys}"/>
</items>
</ComboBox>
</t:template>
</t:Column>
<t:Column
width="5em">
<Label text="Is source"/>
<t:template>
<CheckBox selected="{mInd>IsSrc}" />
</t:template>
</t:Column>
</t:columns>
</t:Table>
</content>
<buttons>
<Button
id="IndFormDialogButtonSave"
text="Save"
type="Accept"
press="onPressSave" />
<Button
id="IndFormDialogButtonCancel"
text="Close"
type='Reject'
press="onPressCancel" />
</buttons>
</Dialog>
</core:FragmentDefinition>
Could you try this? Let me know afterwards...
oView.bindElement({
path: sPath,
model: 'mInd',
parameters: {expand:'INDINFSet'}
});

Map class domain

I have my class domain
class domain Factura {
String name
BigDecimal value
}
in my html:
<g:form>
<input type="text" name="name" />
<input type="number" step="any" name="value" />
<inpu type="submit" value="save" />
</g:form>
in my controller
def save(Factura factura) {
//Suppose in the value I have put : 152.36
println "valor: " + factura.value => return 15236.0
//Suppose in the value I have put : 152,36
println "valor: " + factura.value => return 15236.0
}
How can I return as a decimal? I need 152.36
You can use text input and cast it to BigDecimal
Change this
<input type="number" step="any" name="value" />
to
<input type="text" name="value" />
In your save method
try{
params.value.toBigDecimal()
catch(e){
// error
}

Breeze SaveChanges

I am new to BreezeJS, and have recently created a project that is up and running. I am able to use Breeze to query data from my SQL server without a problem. However, whenever I try to save changes, the changes do not save. I have verified, in VS 2012, that the JavaScript save function is actually called, however the HttpPost method on the server side is never called.
Here is the Breeze Controller that I have set up:
using System.Linq;
using System.Web.Http;
using Newtonsoft.Json.Linq;
using Breeze.WebApi;
using FitnessTracker.Models;
namespace FitnessTracker.Controllers
{
[BreezeController]
public class BreezeController : ApiController
{
private readonly EFContextProvider<FitnessTrackerContext> _fitnessContext =
new EFContextProvider<FitnessTrackerContext>();
//
// GET: /Breeze/
[HttpGet]
public string Metadata()
{
return _fitnessContext.Metadata();
}
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
return _fitnessContext.SaveChanges(saveBundle);
}
[HttpGet]
public IQueryable<FitnessEquipment> FitnessEquipments()
{
return _fitnessContext.Context.FitnessEquipments;
}
}
}
Here is the save function that I am using:
function saveChanges() {
return manager.saveChanges()
.fail(saveFailed);
}
Here is the HTML:
<div class="box-body form" data-bind="foreach: exercises">
<input type="text" class="txt-m g2" data-bind="text: EquipmentName" />
<input type="text" class="txt-m g1" data-bind="text: EquipmentLevel" />
<input type="text" class="txt-m g2" data-bind="text: DurationSeconds" />
<input type="text" class="txt-m g2" data-bind="text: Weight" />
<input type="text" class="txt-m g4" data-bind="text: DateTime" />
<br class="clear" />
</div>
Save Changes
Thanks in advance for your help!!
Edit 9/12/2013:
I have fixed it thanks to Jay's help!!
The problem is that I was binding on the text instead of the value. I changed the html to:
<div class="box-body form" data-bind="foreach: exercises">
<input type="text" class="txt-m g2" data-bind="value: EquipmentName" />
<input type="text" class="txt-m g1" data-bind="value: EquipmentLevel" />
<input type="text" class="txt-m g2" data-bind="value: DurationSeconds" />
<input type="text" class="txt-m g2" data-bind="value: Weight" />
<input type="text" class="txt-m g4" data-bind="value: DateTime" />
<br class="clear" />
</div>
It is now saving without a problem. Thanks Jay for your help!
Have you confirmed that you are actually changing/or adding an entity within the EntityManager on the client? You can call the EntityManager's hasChanges method to confirm. Breeze does not attempt to call the server if there are no changes to save.
So try something like
if (manager.hasChanges()) {
manager.saveChanges()
.fail(saveFailed);
} else {
// my guess is that you will get here.
}
My guess is that you either have a binding issue or have not queried or created an entity that requires saving.

MVC 3 Pass multiple ints / collection via ajax to controller

On my form I have several hidden fields with the same name (RemoveId)
<input type="hidden" value="1" name="RemoveId" />
<input type="hidden" value="2" name="RemoveId" />
<input type="hidden" value="3" name="RemoveId" />
<input type="hidden" value="4" name="RemoveId" />
<input type="hidden" value="5" name="RemoveId" />
I would like to pass checked items (int(s)) to a controller via ajax/json
How would i do it?
thanks
here is something that should help
Using getElementsByName on the name "RemoveId" will give you an array
var list = document.getElementsByName("RemoveId");
var arrId = [];
for (var i = 0; i < list.length; i++) {
arrId.push(list[i].value);
}
Pass this list of id's prepared to the controller
$(function(){
$.ajax({
type: "POST",
url: "#Url.Action("PostArray")" %>",
data: {idArray: arrId},
dataType: "json",
success: function(msg){console.log(msg)}
});
})
and here is how your controller should look like
[HttpPost]
public ActionResult PostArray(int[] idArray)
{
// do your thing..
}
Try to do this:
<input type="hidden" value="1" name="RemoveId" />
<input type="hidden" value="2" name="RemoveId" />
<input type="hidden" value="3" name="RemoveId" />
<input type="hidden" value="4" name="RemoveId" />
<input type="hidden" value="5" name="RemoveId" />
<input type="button" value="do" class="send" />
<script type="text/javascript" >
$(function () {
$(".send").click(function () {
var myValues = [];
$("[name = 'RemoveId']").each(function (index, element) {
myValues.push($(element).val());
});
$.ajax({
type: "POST",
url: "/Home/Method",
data: { myValues: myValues }
});
});
})
</script>
[HttpPost]
public ActionResult Method()
{
var b = Request["myValues[]"].Split(',').ToList();
return null;
}

Resources