I have one custom object in my ViewModel.I want to bind only one of its member to textview in my droid view.
I want to bind only string member of that object to textview
Currently I am doing this.
local:MvxBind = "Text Myobject.ItsMember"
Is it ok?
Or am I wrong?
Or Can I do Like this?
local:MvxBind = "ItemsSource MyObject ; Text ItsMember"
How can I achieve this?
local:MvxBind = "Text MyObject.ItsMember" is perfectly fine. Just make sure your spelling and capitalization are correct. Also, ItsMember should be a string or have a valid value returned as ToString.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Text MyObject.ItsMember"
/>
Related
I am using prime faces backing bean and Chart.js to draw a chart
I am selecting a row in the data table . On selection of row updating the Canvas which has the Chart in it. I am getting the values on Selection method and building two arrays one for X axis and another for y-axis. How can i pass these arrays to JavaScript to render the chart . I tried Prime faces JSON array to pass to JavaScript. I could not get the values in JavaScrip.
Here is my sample code .xhtml code
<p:dataTable id="myTbl" var="cars" value="#{bean.value}" rowKey="#{bean.carId}" selection="#{bean.selectedCar}" selectionMode="single" reflow="true" >
<p:ajax event="rowSelect" listener="#{bean.onRowSelect}" update=":chartForm" oncomplete="drawChart();" />
</p:dataTable>
<div class= "chart-container" >
<h:outputText id="outputid" value="#{bean.carId}" />
<canvas id="myChart" ></canvas>
</div>
function drawChart(){
var carId = '#{bean.carId}';
alert (carId)
I am selecting a row from the above table. On selection I want to capture the id of the line , get data and display the chart.js chart on same page
here is my bean class
In Bean Class
private String carId;
setter and getter methods
public void onRowSelect(SelectEvent event) {
Cars car= (Cars) event.getObject();
this.carId = car.Id ;
}
I got values into Primefaces JSON Array and passing into JavaScript .In JavaScript I am doing JSON.parse . Initially I got serialization error , so changed the bean to request scoped
The problem is I am not getting any values into JavaScript
I removed JSON Array and and just passing a String
I can get the bean.property on xhtml page as mentioned in my code but not able to get into JavaScript
Am i missing something
you can try to use jsf expression language in javascript code
For example:
//<![CDATA[
var jsVar = #{managedBean.property}
//]]>
Well, if you are concerned with the calling (and passing values) of JS function from bean, then you can call execute of RequestContext.getCurrentInstance() to directly invoke your scripting method from the bean, as following:
RequestContext.getCurrentInstance().execute("yourJSFunction('" + param1 + "');");
However, I think you will still be missing a trick of converting your JSONArray back to JSON object in JS, which you can do as following:
When passed from bean:
function yourJSFunction(coordinatesArray) {
coordinatesArray = JSON.parse(coordinatesArray);
}
Or when using as a bean property:
var coordinatesArr = JSON.parse('#{yourBean.strProperty}');
I started using observable ConcurrentDictionary because it's threadsafe. But now I face a problem how to bind it to the list.
local:MvxBind="ItemsSource SourceDictionary"
obviously cannot work because item consists of the KeyValuePair and not the object itself.
local:MvxBind="ItemsSource SourceDictionary.Values"
does not work. Which, I must admit, puzzles me.
I even tried a long shot and did some converter :
public class SourceDictionaryValueConverter : MvxValueConverter<KeyValuePair<string, SourceClass >, SourceClass >
{
protected override SourceClass Convert(KeyValuePair<string, SourceClass> value, Type targetType, object parameter, CultureInfo culture)
{
return value.Value;
}
}
and bind it like this
local:MvxBind="ItemsSource SourceDictionary, Converter=SourceDictionary"
but it didn't work. I suppose it asks for IList.
Is there any way to bind ListView to the Dictionary?
You should be able to bind to a Dictionary - or indeed to any IEnumerable.
If you are binding to the Dictionary itself (rather than to Values) then you will need to write your item bindings so that they know about KeyValuePair - e.g. so you might need to bind to Key.Name rather than to just Name.
However, Dictionary's themselves do not notify listeners of changes - so using a Dictionary is like using a List - not like using an ObservableCollection. If you want this type of behaviour then you will need to write or find a Dictionary class which implements INotifyCollectionChanged.
I have a working SmarGWT datasource that brings back nested JSON as follows:
{username:"tom",password:"pwd",userType:{id:1,name:"admin user type"}}
The sample DataSource looks like:
DataSourceTextField usernameField = new DataSourceTextField("username", "User Name");
DataSourceTextField passwordField = new DataSourceTextField("password", "Password");
DataSourceIntegerField userTypeIdField = new DataSourceIntegerField ("id", "User Type Id");
userTypeIdField.setValueXPath("userType/id");
I can then tie this DS to a listgrid and/or form, and that works ok to display data.
If I create a DynamicForm tied to this same DS, I want to create a new record.
I have a username and password textbox which are fine, and I have a SelectItem which gives me back the id to the usertype (1 for Admin, 2 for Oher).
When we get data from this form and look at the JSON sent from the form to the DS, it looks like:
{username:"newuser",password:"newpwd",userTypeId:1}
but I would prefer:
{username:"newuser",password:"newpwd",userType:{id:1}}
because this JSON version of the data would translate nicely into the object I want to send to the controller, which would then file this object. But I do not know if this is possible with the DynamicForm, and/or the SelectItem.
One possibility which I know would work would be to look at the JSON when I send it back for an insert or update. In the transformRequest, I could manually tweak the JSON to remove userTypeId:1 and add userType:{id:1} in it's place.
Or, I could look at a Nested DataSource which I haven't done in a long time.
I am just not sure from the SmarGWT perspective which would be a better mainstream solution.
If I need any more information, let me know, and I will update the question.
Thanks in advance for any help!
This was super simple. First in the datasource for UserType, I presume this is very simple. You have usertypeId, userTypeName, UserTypeDescription as follows:
private DataSourceIntegerField userTypeIdField;
private DataSourceTextField userTypeNameField;
private DataSourceTextField userTypeCodeField;
Now let's say you have a datasource for the user, you probably have fields for the userId, username, password, etc, and if UserType is part of that, then you would want to do this:
private DataSourceField userTypeField; // notice it is a DataSourcField
As for the declaration:
userTypeField = new DataSourceField();
userTypeField.setTitle("User Type");
userTypeField.setName("userType");
userTypeField.setTypeAsDataSource(UserTypeDataSource.getInstance());
This is a nice way to do it, if you know you are getting nested JSON or XML data. I have also known cases where, someone has flattened a nested JSON format to the DataSource bu using the XPath seting of a datasourcefield.
On the SmartGWT DynamicForm side, you can take fields and add an setDataPath binding also, such as the following:
userTypeField.setName("userType");
userTypeField.setPickListWidth(210);
userTypeField.setTitle("User Type");
userTypeField.setOptionDataSource(userTypeDS);
userTypeField.setRequired(true);
userTypeField.setDisplayField("userTypeName");
userTypeField.setValueField("userTypeId");
userTypeField.setDataPath("userType/userTypeId");
So, if you had a User DynamicForm, and wanted to set a UserType, the DataPath would preserve the nested JSON, so you'd have something like:
user:
{"userId":1,"username":"test","password":"password",
"userType":{"userTypeId":2}
}
This may seem like it is so simple now, but maybe this will help someone else out.
After executing a navigator.pushView with data object, I'm in need of the data object to be received into the next view, but at some stage transformed into a string to use in a sql function.
The code below shows what I'm working on at the moment.
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="{data.toString()}"
xmlns:model="model.*"
creationComplete = "{data=srv.findByCategory(data.toString())}"
>
.toString() was my quick attempt at it, but the resultant output is simply
[object Object]
There aren't any errors but it only shows during debug.
Any ideas?
As appendage, here is the code from the initial view where the data object originates from
<s:List id="list" top="0" bottom="0" left="0" right="0" width="100%"
alternatingItemColors="0xffffff"
contentBackgroundColor="0xffffff"
downColor="0xfc7d1a"
selectionColor="0xfc7d1a"
dataProvider="{data}"
labelFunction="getFullName"
change="navigator.pushView(CategoryView, list.selectedItem.toString())">
And here is some of the code which needs the data object to be a String.
public function findByCategory(searchKey:String):ArrayCollection
{
}
data is a keyed object containing containing the info you passed from the initial view. You need to access the correct key in your object.
It should be something like data.myKey.toString(). I would be able to tell you exactly if you paste your pushView code.
I am working with Struts2 with java action class and view JSP file.
My Action class has a variable named:
HashMap<Integer, Boolean> pcksHavingFet;
List<pck> pcks;
int fet;
In pcks, I am having a list of pck's with primary key pckId.
I am having a code function in action class that evaluates pcks and assign true/false based on if pck is/is not associated with fet in Database. So we get a fully evaluated expression for pcksHavingFet Map.
//Code that evaluates and set pcksHavingFet varaible.
//Create A JSON Object to access this Map variable in JSP.
public void function()
{
// code to populate pcksHavingFet with key/value pair.
//e.g, pcksHavingFet = {1:true, 2:fALSE, 6:TRUE, 17:false, 11:true .....}
//Create JSON Object to access Map in JSP file
JSONObject jasonfeat = new JSONObject();
jasonfeat.accumulateAll(pcksHavingFet );
}
In Jsp File,
I need to access this pcksHavingFet Map Variable.
I am using below function to show/hide fetDropdown drop down based on pckId is true/false calculated from Map pcksHavingFet.
function pcksOnChange(pckId)
{
var pcksHavingFet = <ww:property value="pcksHavingFet "/> ;
<ww:set name="pcksHavingFet" value="%{JSONObject.fromObject(pcksHavingFet)}">
</ww:set>
fetDropdown.style.display = (pcksHavingFet [pckId]) ? "" : "none";
}
But I am able to see populated values in my action class for pcksHavingFet variables. But In JSP file, unable to access it though. Its coming as empty Map.
Please help me in accessing successfully this variable. It will be a gr8 help. I am new to JSON, Please elaborate your suggestion/help.
Thanks in advance.
Why you are not using Struts2 Build in mechanism to handle JSON.Struts2 provide [Json-plugin].1
The JSON plugin is bundled with Struts since 2.1.7+
All you need to do is to add the plugin jar jar in your class path and need to extends json-default in place of struts-default and you are good to go.
Suggest you to read plugin page for details and example how to work with JSON inside Struts2
Strus2-Json
just as a side note ww represent web-work which has now merged in to Struts2 so its a bit more clear to use tag- alias as s in-place of ww, but the end choice is all yours.
When you are asking question about Struts2 better tag them with struts2 not struts :)