Android Pass String Data Between Fragments - android-fragments

How to pass string data between fragments like we did in Activity using intents?Plea

Use setArguments(...) and getArguments(...) if you are loading one fragment from another

Use interfaces demonstrated here
http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity

Related

Do axon state-based aggregates have a way of specifying #CreatedDate and #LastModifiedDate?

When creating an Axon JPA state-based aggregate is there a way to mark certain fields as being the #CreatedDate and #LastModifiedDate (as is possible with spring data jpa)?
In other words does Axon have the functionality where if any state of the aggregate is changed then axon automatically updates the #LastModifiedDate without us having to repeat it in every #CommandHandler?
Try using #CommandHandlerInterceptor inside your aggregate to intercept all commands and set
lastModifiedDate field.
#CommandHandlerInterceptor
public Object intercept(Object myCommand, InterceptorChain interceptorChain) throws Exception {
this.lastModifiedDate = Instant.now();
return interceptorChain.proceed();
}
I believe the proper solution would be to implement Axon's HandlerEnhancerDefinition interface to update these fields. This way you can grab the same timestamp (Instant) from the event that gets persisted in the event store and use that on your state-stored aggregate to make them match.
I wrote a blog post with a working example with a detailed explaination how to do this: https://michael.jeszenka.com/automatically-updating-timestamp-fields-for-axon-state-stored-aggregates/
Essentially, you will need to implement the wrapHandler() method to specify which types of event handlers you want to wrap with your enhancer. Then you will need to define a wrapper class to execute your desired behavior, which in our case is automatically handling the timestamps of the state-stored aggregate. This wrapper class will need to implement the Object handle(Message<?> message, T target) method which will allow us to grab the event timestamp from the meta data and use it to set the state-stored aggregate fields.

Converting a JsonDocument to its mapped entity

I use CouchbaseRepository in my project but sometimes I use lower level couchbase sdk methods to retrieve JsonDocument. Is there a way I can use spring-data-couchbase to convert a JsonDocument to lets say a User?
This is all done internally in CouchbaseTemplate in the method private <T> T mapToEntity(String id, Document<String> data, Class<T> entityClass)
But as you can see it's private so I can't call it myself.
You can create a wrapper which uses Jackson to convert the JsonDocument to any object you want.
mapper.readValue(doc.content().toString(), SomeClass.class);
The first argument is the JsonDocument, the content method is what contains the actual Json.

is there a way to populate an existing object from json using json.net based upon an interface

Looking for a way to do something like the following:
NewtonSoft.Json.JsonConvert.Populate<IMyContract>(jsonStr, currentObj);
where the json.net engine would only attempt to populate the properties that are identified in the IMyContract.
Any suggestions?
Maybe u can use
PopulateObject(String, Object, JsonSerializerSettings)
And use your own JsonSerializerSettings. See: http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonSerializerSettings.htm
Try to use one of the delegates to restrict the properties that are set yourself. That can be based on an Interface, using reflection.
I don't know any other way. If you don't get it with the JsonSerializerSettings you can always write your own PopulateObject method using the Json framework.

EF4: The closed type 'xxxx' does not have a corresponding element settable property

I'm using this guide to call stored procedure in my projet which using EF4 EDMX through WCFDataservice.
I have mapped a complex type to return items from the stored procedure. If I call the method by http, the XML'result is perfect, but when I call with this code:
public void Test()
{
Uri methodUri = new Uri(entities.BaseUri + "/GetCase");
List<CaseFiltered> result = entities.Execute<CaseFiltered>(methodUri).ToList();
}
I get this exception The closed type CaseFiltered does not have a corresponding element settable property.
I had try this solution but it doesn't work for me.
Have you a solution?
Thank you!
Ok I find the solution according this article
Actually, you did everything
right...However, our client library
does not support materialization of a
collection of complex types directly
(yet). If you look at the output of
the service op, you would see a list
of tag, rather than an Atom
Feed.
My workaround: I'm using Case entities, not the CaseFiltered complex type

How to pass array from Asp.net server side to Javascript function on client side

How do I pass an array I have created on the server side onto the client side for manipulation by Javascript?
Any pseudo code will help
You'll need to embed it as a javascript array declaration into the page. There are a number of ways to do this, but it generally means turning the array into text that you write to the page, probably using the ClientScriptManager.
I'm hoping for better javascript integration in a upcoming verison of ASP.Net. Moving the value of a server variable —any server variable— to the client ought to be supported with a simple, one-line function call. Not the back-flips we need right now.
Convert it to string representation of a javascript array ("['val1','val2','val3']") and shove it into the value field of a hidden input.
Another way would be to use the RegisterArrayDeclaration method of the Page object (deprecated) or in the ClientScriptManager class. See MSDN for details.
The way I do it is like this:
aspx:
private string buttonarray = "'but1','but2','but3','but4'";
public string Buttonarray
{
get { return buttonarray; }
}
javascript
var buttonarray = new Array(<%=Buttonarray%>);
I hope this helps.
Easiest way is to convert it to json. Then just put it at the top of the page in a variable. I've found this the best json implementation for .net: http://litjson.sourceforge.net/

Resources