I have made some code inside of the spring boot back-end application which allows me to change a property of a specific object, this property which needs to be changed is the "status" property:
#Entity
public class Pakketje {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private int code;
private String status = "In magazijn";
public Pakketje() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
To change the property of that object, i will need to state the ID of that object (i think) inside of the react frontend application, and then fetch the PUT-method.
I will show you the method to change the property inside of my spring boot back-end application, this method can be found in the 'Service' class. 'bestaandPakketje' means existing pakketje.
#Override
public Pakketje getPakketjeById(int id) {
return pakketjeRepository.findById(id).orElse(null);
}
#Override
public Pakketje statusOnderweg(Pakketje pakketje) {
Pakketje bestaandPakketje = pakketjeRepository.findById(pakketje.getId()).orElse(null);
bestaandPakketje.setStatus(pakketje.getStatus());
return pakketjeRepository.save(bestaandPakketje);
}
}
And here is the controller:
public class PakketjeController {
#SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
#Autowired
private PakketjeService pakketjeService;
#PostMapping("/add")
public String add(#RequestBody Pakketje pakketje) {
pakketjeService.pakketjeOpslaan(pakketje);
return "Pakketje opgeslagen!";
}
#GetMapping("/getAll")
public List<Pakketje> getAllePakketjes(){
return pakketjeService.getAllePakketjes();
}
#GetMapping("/getById/{id}")
public Pakketje findPakketjeById(int id) {
return pakketjeService.getPakketjeById(id);
}
#PutMapping("/updateOnderweg")
public Pakketje statusIsOnderweg(#RequestBody Pakketje pakketje) {
return pakketjeService.statusOnderweg(pakketje);
}
}
Now the next step is verry hard for me. Each 'pakketje' has his own button which can be clicked to change the property (I will upload the picture so please check it). When that button is clicked the property automatically should change from "In magazijn "to "onderweg".
I would appreciate some help!
Now I face with some problems about principal data. Maybe it sounds like a fool. But I'm new to Spring..
I wanted to get some specific data from principal data, but it occured an error, So I cant.
this is my customUserDetails that implement UserDetails.
private String id;
private String pw;
private String name;
private String auth;
private String level;
private String label;
private int enabled;
#Override
public Collection<? extends GrantedAuthority> getAuthorities() {
ArrayList<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
authList.add(new SimpleGrantedAuthority(auth));
return authList;
}
#Override
public String getPassword() {
return pw;
}
#Override
public String getUsername() {
return id;
}
#Override
public boolean isAccountNonExpired() {
return true;
}
#Override
public boolean isAccountNonLocked() {
return true;
}
#Override
public boolean isCredentialsNonExpired() {
return true;
}
#Override
public boolean isEnabled() {
return enabled==1?true:false;
}
public String getName() {
return name;
}
public String getLabel() { return label;} // 4월 19일 동현 추가
public void setName(String name) {
this.name = name;
}
public String getAuth() {
return auth;
}
And this is principal data I got from console.log
CustomUserDetails(id=admin, pw=$2a$10$Z9C0gTGV0weknBvNi4YFY.l41vjrYo4UgO3MlPwgmIn4uDeYlepFq, name=Admin, auth=ROLE_ADMIN, level=null, label=N, enabled=1)
I want to extract label value from Principal, so I tried to do this code, but I can't.
console.log('${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.label}');
How can I get 'label' data from principal?
Thank you for your kind support :)
In your Controller or any other bean, autowire user details like
public String doSomething(#AuthenticationPrincipal CustomUserDetails userDetails) {
String label = userDetails.getLabel();
}
How To Refresh RecyclerView List Like YouTube By Swiping Refresh layout
activity_main.xml:-
This Is My Main Activity java
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ImagesActivity">
<ProgressBar
android:id="#+id/progress_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/Swipe_Refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
MainActivity.java
And This Is My MainActivity.Java+
please tell me the code
public class ImagesActivity extends AppCompatActivity implements ImageAdapter.OnItemClickListener {
private RecyclerView mRecyclerView;
private ImageAdapter mAdapter;
private ProgressBar mProgressCircle;
private FirebaseStorage mStorage;
private DatabaseReference mDatabaseRef;
private ValueEventListener mDBListener;
private List<Upload> mUploads;
private SwipeRefreshLayout mySwipeRefreshLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_images);
mySwipeRefreshLayout = findViewById(R.id.Swipe_Refresh);
mySwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
}
}
);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mProgressCircle = findViewById(R.id.progress_circle);
mUploads = new ArrayList<>();
mAdapter = new ImageAdapter(ImagesActivity.this, mUploads);
mRecyclerView.setAdapter(mAdapter);
mAdapter.setOnItemClickListener(ImagesActivity.this);
mStorage = FirebaseStorage.getInstance();
mDatabaseRef = FirebaseDatabase.getInstance().getReference("uploads");
mDBListener = mDatabaseRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
mUploads.clear();
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Upload upload = postSnapshot.getValue(Upload.class);
upload.setKey(postSnapshot.getKey());
mUploads.add(upload);
}
mAdapter.notifyDataSetChanged();
mProgressCircle.setVisibility(View.INVISIBLE);
}
#Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(ImagesActivity.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
mProgressCircle.setVisibility(View.INVISIBLE);
}
});
}
#Override
public void onItemClick(int position) {
Toast.makeText(this, "Normal click at position: " + position, Toast.LENGTH_SHORT).show();
}
#Override
public void onWhatEverClick(int position) {
Toast.makeText(this, "Whatever click at position: " + position, Toast.LENGTH_SHORT).show();
}
#Override
public void onDeleteClick(int position) {
Upload selectedItem = mUploads.get(position);
final String selectedKey = selectedItem.getKey();
StorageReference imageRef = mStorage.getReferenceFromUrl(selectedItem.getImageUrl());
imageRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
mDatabaseRef.child(selectedKey).removeValue();
Toast.makeText(ImagesActivity.this, "Item deleted", Toast.LENGTH_SHORT).show();
}
});
}
#Override
protected void onDestroy() {
super.onDestroy();
mDatabaseRef.removeEventListener(mDBListener);
}
}
ImageAdapter.java
This Is My Image Adapter
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private Context mContext;
private List<Upload> mUploads;
private OnItemClickListener mListener;
public ImageAdapter(Context context, List<Upload> uploads) {
mContext = context;
mUploads = uploads;
}
#Override
public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.image_item, parent, false);
return new ImageViewHolder(v);
}
#Override
public void onBindViewHolder(ImageViewHolder holder, int position) {
Upload uploadCurrent = mUploads.get(position);
holder.textViewName.setText(uploadCurrent.getName());
Picasso.with(mContext)
.load(uploadCurrent.getImageUrl())
.placeholder(R.mipmap.ic_launcher)
.fit()
.centerCrop()
.into(holder.imageView);
}
#Override
public int getItemCount() {
return mUploads.size();
}
public class ImageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,
View.OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener {
public TextView textViewName;
public ImageView imageView;
public ImageViewHolder(View itemView) {
super(itemView);
textViewName = itemView.findViewById(R.id.text_view_name);
imageView = itemView.findViewById(R.id.image_view_upload);
itemView.setOnClickListener(this);
itemView.setOnCreateContextMenuListener(this);
}
#Override
public void onClick(View v) {
if (mListener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
mListener.onItemClick(position);
}
}
}
#Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Select Action");
MenuItem doWhatever = menu.add(Menu.NONE, 1, 1, "Do whatever");
MenuItem delete = menu.add(Menu.NONE, 2, 2, "Delete");
doWhatever.setOnMenuItemClickListener(this);
delete.setOnMenuItemClickListener(this);
}
#Override
public boolean onMenuItemClick(MenuItem item) {
if (mListener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
switch (item.getItemId()) {
case 1:
mListener.onWhatEverClick(position);
return true;
case 2:
mListener.onDeleteClick(position);
return true;
}
}
}
return false;
}
}
public interface OnItemClickListener {
void onItemClick(int position);
void onWhatEverClick(int position);
void onDeleteClick(int position);
}
public void setOnItemClickListener(OnItemClickListener listener) {
mListener = listener;
}
}
**Upload.java**
This My Upload Class
package com.codinginflow.firebaseuploadexample;
import com.google.firebase.database.Exclude;
public class Upload {
private String mName;
private String mImageUrl;
private String mKey;
public Upload() {
//empty constructor needed
}
public Upload(String name, String imageUrl) {
if (name.trim().equals("")) {
name = "No Name";
}
mName = name;
mImageUrl = imageUrl;
}
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
public String getImageUrl() {
return mImageUrl;
}
public void setImageUrl(String imageUrl) {
mImageUrl = imageUrl;
}
#Exclude
public String getKey() {
return mKey;
}
#Exclude
public void setKey(String key) {
mKey = key;
}
}
In MVC 4, you could install this package Twitter.bootstrap.mvc and this would add lots of HTML helpers.
Once istalled you could send alert to view right from controller.
For example:
public class AccountController : BaseController
{
public ActionResult AlertExample()
{
Success("This is a success alert");
Error("This is error alert");
Information("This is information alert");
...
etc.
}
}
This would send the success alert right from controller to the view.
Objective: Sending Growl Messages from controller
I've tried to implement same thing from the project I mentioned.
So, this is what I've added to my project.
Base controller that other controller derives from
public class BaseController : Controller
{
//
// GET: /Base/
public void Warning(string message)
{
TempData.Add(Alerts.WARNING, message);
}
public void Success(string message)
{
TempData.Add(Alerts.SUCCESS, message);
}
public void Information(string message)
{
TempData.Add(Alerts.INFORMATION, message);
}
public void Error(string message)
{
TempData.Add(Alerts.ERROR, message);
}
}
ControlGroupExtensionClass
namespace BootstrapSupport
{
public class ControlGroup : IDisposable
{
private readonly HtmlHelper _html;
public ControlGroup(HtmlHelper html)
{
_html = html;
}
public void Dispose()
{
_html.ViewContext.Writer.Write(_html.EndControlGroup());
}
}
public static class ControlGroupExtensions
{
public static IHtmlString BeginControlGroupFor<T>(this HtmlHelper<T> html, Expression<Func<T, object>> modelProperty)
{
return BeginControlGroupFor(html, modelProperty, null);
}
public static IHtmlString BeginControlGroupFor<T>(this HtmlHelper<T> html, Expression<Func<T, object>> modelProperty, object htmlAttributes)
{
return BeginControlGroupFor(html, modelProperty,
HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}
public static IHtmlString BeginControlGroupFor<T>(this HtmlHelper<T> html, Expression<Func<T, object>> modelProperty, IDictionary<string, object> htmlAttributes)
{
string propertyName = ExpressionHelper.GetExpressionText(modelProperty);
return BeginControlGroupFor(html, propertyName, null);
}
public static IHtmlString BeginControlGroupFor<T>(this HtmlHelper<T> html, string propertyName)
{
return BeginControlGroupFor(html, propertyName, null);
}
public static IHtmlString BeginControlGroupFor<T>(this HtmlHelper<T> html, string propertyName, object htmlAttributes)
{
return BeginControlGroupFor(html, propertyName, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}
public static IHtmlString BeginControlGroupFor<T>(this HtmlHelper<T> html, string propertyName, IDictionary<string, object> htmlAttributes)
{
var controlGroupWrapper = new TagBuilder("div");
controlGroupWrapper.MergeAttributes(htmlAttributes);
controlGroupWrapper.AddCssClass("control-group");
string partialFieldName = propertyName;
string fullHtmlFieldName =
html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(partialFieldName);
if (!html.ViewData.ModelState.IsValidField(fullHtmlFieldName))
{
controlGroupWrapper.AddCssClass("error");
}
string openingTag = controlGroupWrapper.ToString(TagRenderMode.StartTag);
return MvcHtmlString.Create(openingTag);
}
public static IHtmlString EndControlGroup(this HtmlHelper html)
{
return MvcHtmlString.Create("</div>");
}
public static ControlGroup ControlGroupFor<T>(this HtmlHelper<T> html, Expression<Func<T, object>> modelProperty)
{
return ControlGroupFor(html, modelProperty, null);
}
public static ControlGroup ControlGroupFor<T>(this HtmlHelper<T> html, Expression<Func<T, object>> modelProperty, object htmlAttributes)
{
string propertyName = ExpressionHelper.GetExpressionText(modelProperty);
return ControlGroupFor(html, propertyName, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}
public static ControlGroup ControlGroupFor<T>(this HtmlHelper<T> html, string propertyName)
{
return ControlGroupFor(html, propertyName, null);
}
public static ControlGroup ControlGroupFor<T>(this HtmlHelper<T> html, string propertyName, object htmlAttributes)
{
return ControlGroupFor(html, propertyName, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}
public static ControlGroup ControlGroupFor<T>(this HtmlHelper<T> html, string propertyName, IDictionary<string, object> htmlAttributes)
{
html.ViewContext.Writer.Write(BeginControlGroupFor(html, propertyName, htmlAttributes));
return new ControlGroup(html);
}
}
public static class Alerts
{
public const string SUCCESS = "success";
public const string WARNING = "warning";
public const string ERROR = "error";
public const string INFORMATION = "info";
public static string[] ALL
{
get { return new[] { SUCCESS, WARNING, INFORMATION, ERROR }; }
}
}
}
ViewHelperExtensionClass
namespace BootstrapSupport
{
public static class DefaultScaffoldingExtensions
{
public static string GetControllerName(this Type controllerType)
{
return controllerType.Name.Replace("Controller", String.Empty);
}
public static string GetActionName(this LambdaExpression actionExpression)
{
return ((MethodCallExpression)actionExpression.Body).Method.Name;
}
public static PropertyInfo[] VisibleProperties(this IEnumerable Model)
{
var elementType = Model.GetType().GetElementType();
if (elementType == null)
{
elementType = Model.GetType().GetGenericArguments()[0];
}
return elementType.GetProperties().Where(info => info.Name != elementType.IdentifierPropertyName()).ToArray();
}
public static PropertyInfo[] VisibleProperties(this Object model)
{
return model.GetType().GetProperties().Where(info => info.Name != model.IdentifierPropertyName()).ToArray();
}
public static RouteValueDictionary GetIdValue(this object model)
{
var v = new RouteValueDictionary();
v.Add(model.IdentifierPropertyName(), model.GetId());
return v;
}
public static object GetId(this object model)
{
return model.GetType().GetProperty(model.IdentifierPropertyName()).GetValue(model, new object[0]);
}
public static string IdentifierPropertyName(this Object model)
{
return IdentifierPropertyName(model.GetType());
}
public static string IdentifierPropertyName(this Type type)
{
if (type.GetProperties().Any(info => info.PropertyType.AttributeExists<System.ComponentModel.DataAnnotations.KeyAttribute>()))
{
return
type.GetProperties().First(
info => info.PropertyType.AttributeExists<System.ComponentModel.DataAnnotations.KeyAttribute>())
.Name;
}
else if (type.GetProperties().Any(p => p.Name.Equals("id", StringComparison.CurrentCultureIgnoreCase)))
{
return
type.GetProperties().First(
p => p.Name.Equals("id", StringComparison.CurrentCultureIgnoreCase)).Name;
}
return "";
}
public static string GetLabel(this PropertyInfo propertyInfo)
{
var meta = ModelMetadataProviders.Current.GetMetadataForProperty(null, propertyInfo.DeclaringType, propertyInfo.Name);
return meta.GetDisplayName();
}
public static string ToSeparatedWords(this string value)
{
return Regex.Replace(value, "([A-Z][a-z])", " $1").Trim();
}
}
public static class PropertyInfoExtensions
{
public static bool AttributeExists<T>(this PropertyInfo propertyInfo) where T : class
{
var attribute = propertyInfo.GetCustomAttributes(typeof(T), false)
.FirstOrDefault() as T;
if (attribute == null)
{
return false;
}
return true;
}
public static bool AttributeExists<T>(this Type type) where T : class
{
var attribute = type.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
if (attribute == null)
{
return false;
}
return true;
}
public static T GetAttribute<T>(this Type type) where T : class
{
return type.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
}
public static T GetAttribute<T>(this PropertyInfo propertyInfo) where T : class
{
return propertyInfo.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
}
public static string LabelFromType(Type #type)
{
var att = GetAttribute<DisplayNameAttribute>(#type);
return att != null ? att.DisplayName
: #type.Name.ToSeparatedWords();
}
public static string GetLabel(this Object Model)
{
return LabelFromType(Model.GetType());
}
public static string GetLabel(this IEnumerable Model)
{
var elementType = Model.GetType().GetElementType();
if (elementType == null)
{
elementType = Model.GetType().GetGenericArguments()[0];
}
return LabelFromType(elementType);
}
}
//public static class HtmlHelperExtensions
//{
// public static MvcHtmlString TryPartial(this HtmlHelper helper, string viewName, object model)
// {
// try
// {
// return helper.Partial(viewName, model);
// }
// catch (Exception)
// {
// }
// return MvcHtmlString.Empty;
// }
//}
}
and the _alert partial View
#using BootstrapSupport
#if (TempData.ContainsKey(Alerts.WARNING))
{
<div class="alert alert-block">
<a class="close" data-dismiss="alert" href="#">x</a>
<h4 class="toast-title">Attention!</h4>
#TempData[Alerts.WARNING]
</div>
}
#foreach (string key in Alerts.ALL.Except(new[] { Alerts.WARNING }))
{
if (TempData.ContainsKey(key))
{
<div class="toast toast-top-full-width toast-key">
<button type="button" class="toast-close-button" data-dismiss="alert">x</button>
#TempData[key]
</div>
}
}
After all this I can send alert messages right from controller:
And it works!
For example
public ActionResult Test()
{
Success("Person was successfully added to your addressbook");
}
above code would result this in view
but it is just displaying as content block. Not as I expected to work, as it just appears in view, no effect, nothing. I wanted it to work as in this site Toastr.
I'm guessing I have to implement javascript somewhere in my _alert view and get the message and type(success, error,...) and then use javascript to growl it, to make it behave it as it should.
But i don't have much knowledge about it.
Something like below? Thats just idea, because of my lack of knowledge of Javascript and jquery i couldn't make it work
#*if (TempData.ContainsKey(key))
{
<div class="toastMessageHolder" style="display: none">
<div class="toastMessage">#TempData[key]</div>
<div class="toastMessageType">#key</div>
</div>
if($(".toastMessageHolder"))
{
//loop all toastMessageHolders
$(".toastMessageHolder").foreach(function(){
var message = $(".toastMessage", this).html();
var messageType = $(".toastMessageType", this).html();
});
//feed this parameters to javascript
}*#
Could somebody help me how to make my growling from controller behave as mentioned in example of Toastr?
If I had to growl from any normal view if I hadn't implemented sending msgs from controller to view this is how I would do using toastr:
function foo(response) {
if (response.SomeTest) {
toastr.error(response.ErrorMessage, "Error");
}
else {
$(#Html.IdFor(m=>m.abc)).val('');
}
};
Asp.Net MVC version: 5.1.1
Growling package used: Toastr
This is what I ended up doing.
_alert view(partial). To send alert messages right from controller.
#using BootstrapSupport
<script>
toastr.options = {
closeButton: true,
debug: false,
positionClass: "toast-top-full-width",
onclick: null,
showDuration: "300",
hideDuration: "1000",
timeOut: "5000",
extendedTimeOut: "1000",
showEasing: "swing",
hideEasing: "linear",
showMethod: "fadeIn",
hideMethod: "fadeOut"
}
</script>
#if (TempData.ContainsKey(Alerts.SUCCESS))
{
foreach (var value in TempData.Values)
{
<script>
toastr.success("#value.ToString()");
</script>
}
TempData.Remove(Alerts.SUCCESS);
}
#if (TempData.ContainsKey(Alerts.ERROR))
{
foreach (var value in TempData.Values)
{
<script>
toastr.error("#value.ToString()");
</script>
}
TempData.Remove(Alerts.ERROR);
}
#if (TempData.ContainsKey(Alerts.INFORMATION))
{
foreach (var value in TempData.Values)
{
<script>
toastr.warning("#value.ToString()");
</script>
}
TempData.Remove(Alerts.INFORMATION);
}
#if (TempData.ContainsKey(Alerts.WARNING))
{
foreach (var value in TempData.Values)
{
<script>
toastr.warning("#value.ToString()");
</script>
}
TempData.Remove(Alerts.WARNING);
}
I just don't understand what I have to set as the service name for the EntityManager.
I hava two controllers: an ApiController and a 'normal' controller:
API Controller:
[BreezeController]
public class TournamentApiController : ApiController
{
private EFContextProvider<TournamentContext> _contextProvider;
public TournamentApiController()
{
_contextProvider = new EFContextProvider<TournamentContext>();
}
[HttpGet]
public string Metadata()
{
return _contextProvider.Metadata();
}
[HttpGet]
public IQueryable<Tournament> Tournaments()
{
return _contextProvider.Context.Tournaments;
}
[HttpGet]
public IQueryable<Team> Teams()
{
return _contextProvider.Context.Teams;
}
}
'Normal' controller:
public class TournamentController : Controller
{
public ActionResult Index()
{
return PartialView();
}
public ActionResult Details()
{
return PartialView();
}
}
And in my DataSrvice.js file:
app.dataservice = (function (breeze) {
breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
var serviceName = '/TournamentApi'; // What exactly do I need to set here?
// *** Cross origin service example ***
//var serviceName = 'http://todo.breezejs.com/breeze/todos'; // controller in different origin
var manager = new breeze.EntityManager(serviceName);
// manager.enableSaveQueuing(true);
var dataservice = {
getAllTournaments: getAllTournaments,
};
return dataservice;
/*** implementation details ***/
function getAllTournaments() {
var query = breeze.EntityQuery
.from("Tournament");
return manager.executeQuery(query);
}
})(breeze);
Can someone explain what is meant by a service name and thus, what I should use as the service name?
The serviceName identifies the service end-point, the route to the Web API controller. This will be the "root" of the URL you use to communicate with the server. So if the actual endpoints to query 'teams' and 'tournaments' are
http://foo/bar/tournamentApp/teams ...
http://foo/bar/tournamentApp/tournaments ...
then your service name will be
"foo/bar/tournamentApp"