Getting all return values of LOV programmatically - java

I'm currently working on a CRUD application and I have defined a LOV like this:
My question is how can I get all these return values in for example a ValueChangeListener defined like this:
public void onValueChanged(ValueChangeEvent ev){
BindingContext bctx = BindingContext.getCurrent();
oracle.binding.BindingContainer bindings = bctx.getCurrentBindingsEntry();
DCIteratorBinding iterBind = (DCIteratorBinding)bindings.get("MpStavkeulazaView5Iterator");
System.out.println("Vrijednost je" + ev.getNewValue());
}
This code only gives me the value of the list attribute, but I want the other values too.
Any other info please tell me.

First of all - using backing bean's value change listener is not ideal for such use case:
Try instead the setter on your Row Impl for the same purpose.
Remember: if you can't test your use case from BC tester, your ADF design is flawed.
Second of all: your LOV can return multiple values:
http://adfbugs.blogspot.co.uk/2009/11/returning-multiple-values-from-lov-in.html

You can bind row attributes and then get values of this bindings or just get this attributes from iterator. If you going to handle it in valueChangeListener you'll have to process updates, before getting this values:
public void onValueChanged(ValueChangeEvent ev){
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterBind = (DCIteratorBinding)bindings.get("MpStavkeulazaView5Iterator");
System.out.println("Vrijednost je" + ev.getNewValue());
ev.processUpdates(FacesContext.getCurrentInstance());
Row row = iterBind.getCurrentRow();
System.out.println("Proizvod: " + row.getAttribute("Proizvod"));
System.out.println("Jmjere: " + row.getAttribute("Jmjere"));
}
However its may be better to use Transient attribute in your ViewObject and do calculations there?

Related

I am only receiving partial output from an object Groovy

I have an object in Groovy and in this object there appears to be either a map. I am trying to get the "value" rather than the key from this objects map. How do I go about doing something like this?
This is the output I am receiving in my console the first is the object and the 2nd is the output for the property fromValues...
<com.atlassian.jira.issue.changehistory.ChangeHistoryItem#b791639b id=10130 changeGroupId=10113 userKey=Charley field=status projectId=10000 issueId=10217 issueKey=ICB-128 created=2019-03-12 14:19:22.0 nextChangeCreated=292278994-08-17 02:12:55.807 fromValues=[10003:To Do] toValues=[3:In Progress]>
[runner.ScriptRunnerImpl]: 10003
Here is my code below that I am working with so far in attempt to get this information: (Just so you understand the context... I am pulling an issue from Jira software and extracting the history of that particular issue.)
IssueManager issueManager = ComponentAccessor.getIssueManager();
def issue = issueManager.getIssueObject("ICB-128");
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getAllChangeItems(issue)
//def changeItems = changeHistoryManager.getChangeHistoriesSince(issue, since)
changeItems.eachWithIndex { item, index ->
//log.warn(changeItems.dump())
def last_change = changeItems[index]
log.warn(last_change.dump())
def text = "LAST MODIFIED FIELD:"+ last_change["field"] + "; FROM VALUE:"+ last_change["fromValue"] + "; TO VALUE:"+ last_change["toValue"]
if (last_change["fromValue"])
{
log.warn(last_change["fromValue"])
}
}
Edit 1: I have corrected for what #vahid suggested and now have both values returned how I want it. I have tried numerous ways to call and retrieve specifically the value for that map and nothing has worked (.get or .value or even .key)... Any suggestions?
Edit 2: Turns out this extracted field is now considered as a type "hashmap"

Extract Object Data into usable format

I am a real newbie so go easy on me and my terminology, I am still learning!
I have a Backendless database I would like to show in my app.
I have successfully connected it to my Android Studio app, queried it and returned the data in the following method:
Backendless.Data.of( "database" ).find( queryBuilder, new AsyncCallback>(){public void handleResponse(List'<'Map'>'response ){
The narrative on the Backendless SDK says "the "response" object is a collection of java.util.Map objects"
I then used an iterator:
Iterator itr = response.iterator();
And a while loop to 'get' the object:
Object element = itr.next();
I am happy up until this point, the next step is to extract the useful data from element.
I have tried many options of but the only one I have working is element.toString() and use various methods to pick out what I want. This seems so inefficient I thought I would ask the experts for a better option!?
Your question is rather about working with Java Map interface. So I'd advice you to look into its documentation and maybe some tutorials on this topic.
As to your Backendless question, it looks like you got the request part right. Here is the extended example from the docs, which shows you how to retrieve the object fields:
Backendless.Persistence.of( "Contact" ).find( new AsyncCallback<List<Map<String, Object>>>(){
#Override
public void handleResponse( List<Map<String, Object>> foundContacts )
{
Iterator<Map<String, Object>> contactsIterator = foundContacts.iterator();
while( contactsIterator.hasNext() )
{
Map<String, Object> contact = contactsIterator.next();
String name = (String) contact.get( "name" ); // in case you have STRING field 'name' in Backendless database
Integer age = (Integer) contact.get( "age" ); // in case you have INT field 'age' in Backendless database
// etc.
}
}
#Override
public void handleFault( BackendlessFault fault )
{
System.out.err( "Failed find: " + fault );
}
});
As you may see, the main concern is to retrieve a Map instead of Object from the response List.
And also your question would be more useful with code samples of what you tried and maybe direct link to the docs you used as an example.

Manipulate combobox using dictionary in java

I am consuming a web service which is returning me result of type "ArrayOfKeyValueOfintstring"
I am confused how to add this data to my combo box in java.
Here is my code
org.tempuri.ThirdPartyService service = new org.tempuri.ThirdPartyService();
org.tempuri.IThirdPartyService port = service.getBasicHttpBindingIThirdPartyService();
// TODO initialize WS operation arguments here
java.lang.String key = line.trim();
// TODO process result here
String>)port.getTests(key).getKeyValueOfintstring();
com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfKeyValueOfintstring result = port.getVulnerabilities(key);
EDIT
for(int i=0;i<=result.getKeyValueOfintstring().size();i++)
{
result.getKeyValueOfintstring().get(i).getKey();
result.getKeyValueOfintstring().get(i).getValue();
JOptionPane.showMessageDialog(null, "key is"+result.getKeyValueOfintstring().get(i).getKey());
JOptionPane.showMessageDialog(null, "Value is"+result.getKeyValueOfintstring().get(i).getValue());
model.addElement(new Item(key, value));
}
I have tried to get the key pair in dialog box and i got it correctly. But now i am not getting how to add them to my ComboBox. I have created table "Vector model = new Vector();" and adding it to the combo box like this "cbTestName = new JComboBox(model);"
Is it the correct way or do i need to apply anything else to add the key value pair to my combo box.
If you'll go to declaration of
port.getTests(key).getKeyValueOfintstring(),
you'll probably find its implemented as
List<KeyValuePairOfintstring>
and KeyValuePairOfintstring is looks like
...
protected Integer key;
...
protected String value;
So one of the ways you can do - is run over port.getTests(key).getKeyValueOfintstring() in the loop, and build your map with your java business objects, you want to display in Combo Box.
You can override your object's toString method as a simplest way to control how will they look in the ComboBox.

Trying to compare a HashSet element with an element in a List

I have a HashSet that I created and this is what it contains. It will contain more later on, this is pasted from standard out when I did a toString on it. Just to show the contents.
foo.toString(): Abstractfoo [id=2, serial=1d21d, value=1.25, date=2012-09-02 12:00:00.0]
INFO [STDOUT] price.toString(): Abstractfoo [id=1, serial=1d24d, value=1.30, date=2012-09-19 12:00:00.0]
I have a List that I also have and I need to compare the two. One of the elements in List is:
Bar.toString(): Bar [id=1d21d, name=Dell, description=Laptop, ownerId=null]
Here is what I am trying to do...
Bar contains all of the elements I want foo to have. There will only be one unique serial. I would like my program to see if an element in the list that is in HashSet contains the id for bar. So serial == id.
Here is what I've been trying to do
Removed code and added clearer code below
I've verified the data is getting entered into the HashSet and List correctly by viewing it through the debugger.
foo is being pulled from a database through hibernate, and bar is coming from a different source. If there is an element in bar I need to add it to a list and I'm passing it back to my UI where I'll enter some additional data and then commit it to the database.
Let me know if this makes sense and if I can provide anymore information.
Thanks
EDIT: Here is the class
#RequestMapping(value = "/system", method = RequestMethod.GET)
public #ResponseBody
List<AbstractSystem> SystemList() {
// Retrieve system list from database
HashSet<AbstractSystem> systemData = new HashSet<AbstractSystem>(
systemService.getSystemData());
// Retrieve system info from cloud API
List<SystemName> systemName= null;
try {
systemName = cloudClass.getImages();
} catch (Exception e) {
LOG.warn("Unable to get status", e);
}
// Tried this but, iter2 only has two items and iter has many more.
// In production it will be the other way around, but I need to not
// Have to worry about that
Iterator<SystemName> iter = systemName.iterator();
Iterator<AbstractSystem> iter2 = systemData .iterator();
while(iter.hasNext()){
Image temp = iter.next();
while(iter2.hasNext()){
AbstractPricing temp2 = iter2.next();
System.out.println("temp2.getSerial(): " + temp2.getSerial());
System.out.println("temp.getId(): " + temp.getId());
if(temp2.getSerial().equals(temp.getId())){
System.out.println("This will be slow...");
}
}
}
return systemData;
}
If N is the number of items in systemName and M is the number of items in systemData, then you've effectively built an O(N*M) method.
If you instead represent your systemData as a HashMap of AbstractSystem by AbstractSystem.getSerial() values, then you just loop through the systemName collection and lookup by systemName.getId(). This becomes more like O(N+M).
(You might want to avoid variables like iter, iter2, temp2, etc., since those make the code harder to read.)
EDIT - here's what I mean:
// Retrieve system list from database
HashMap<Integer, AbstractSystem> systemDataMap = new HashMap<AbstractSystem>(
systemService.getSystemDataMap());
// Retrieve system info from cloud API
List<SystemName> systemNames = cloudClass.getImages();
for (SystemName systemName : systemNames) {
if (systemDataMap.containsKey(systemName.getId()) {
System.out.println("This will be slow...");
}
}
I used Integer because I can't tell from your code what the type of AbstractSystem.getSerial() or SystemName.getId() are. This assumes that you store the system data as a Map elsewhere. If not, you could construct the map yourself here.

SmartGWT - Update ListGridRecord dynamically

I am using SmartGWT and I have a ListGrid populated with an array of ListGridRecords using the setData() call. I am trying to update a progress property of a single record (on a timer for testing) and have it update in the browser. I have tried various combinations of draw(), redraw(), markForRedraw() etc. to no avail.
I also tried overriding the updateRecordComponent() method in my table class, but it only gets called when the records are first created (after createRecordComponent()).
I should note that I do NOT want to accomplish this by binding to a DataSource. I just want to be able to update the attribute on the client-side.
ArrayList<SegmentSortRecord> mRecords;
mRecords.add(new SegmentSortRecord("03312010_M001_S004"));
mRecords.add(new SegmentSortRecord("03312010_M001_S005"));
mRecords.add(new SegmentSortRecord("03312010_M001_S006"));
mRecords.add(new SegmentSortRecord("03312010_M001_S007"));
SegmentSortRecord[] records = new SegmentSortRecord[mRecords.size()];
mRecords.toArray(records);
mSortProgressTable.setData(records);
.
.
.
mTestTimer = new Timer()
{
public void run()
{
mTestPercent += 5;
if (mTestPercent <= 100)
{
mSortProgressTable.getRecord(2).setAttribute(Constants.PROGRESS_COL_NAME, mTestPercent);
//mSortProgressTable.markForRedraw();
//mSortProgressTable.redraw();
}
else
{
mTestPercent = 0;
}
}
};
...
#Override
protected Canvas createRecordComponent(final ListGridRecord aRecord, Integer aColumn)
{
String fieldName = getFieldName(aColumn);
// Want to override the behavior for rendering the "progress" field
if (fieldName.equals(Constants.PROGRESS_COL_NAME))
{
Progressbar bar = new Progressbar();
bar.setBreadth(10);
bar.setLength(100);
// The JavaScript record object contains attributes that we can
// access via 'getAttribute' functions.
bar.setPercentDone(aRecord.getAttributeAsInt(Constants.PROGRESS_COL_NAME));
return bar;
}
Thanks in advance for any help.
I solved the dynamic update with:
grid.getRecord(i).setAttribute(name, value);
grid.refreshRow(i);
resp.
grid.refreshCell(i, j);
ListGrid has an updateData method, where you can pass a record. Have you tried it?
a blunt and not very high-performance way is simply setting your records array again with setData or setRecords
grid.setData(recordArr);
I use that in my app, but only because all records are updated anyway.
BTW: you could set up a clientside datasource
dataSource.setClientOnly(true);
dataSource.setTestData(...);

Categories

Resources