Update value from inputText - oracle-adf

I'm working with ADF BC and I have several inputTexts.
Let's say I have the folowing scenario:
Step 1: inserting 1, 2, 3 in three different inputTexts (it1, it2 and it3, all three with autoSubmit == true).
Step 2: Click a button who calls the following method:
public String aplicarFiltro() {
Object it1param = null, it2param = null, it3param = null, sos1param = null;
Parametros_IndicadoresLoadAll pila = Parametros_IndicadoresLoadAll.getInstance();
pila.clear();
if(it1.getValue() == null || it1.getValue().toString().isEmpty()) {
it1param = "";
} else {
it1param = it1.getValue();
if(it2.getValue() == null || it2.getValue().toString().isEmpty()) {
it2param = "";
} else {
it2param = it2.getValue();
if(it3.getValue() == null || it3.getValue().toString().isEmpty()) {
it3param = "";
} else {
it3param = it3.getValue();
}
}
}
if(sos1.getValue() != null) {
sos1param = sos1.getValue();
}
pila.init(it1param, it2param, it3param, sos1param);
if (it1.getValue() == null || it1.getValue().toString().isEmpty()) {
showPopup(p1, true);
/* } else if (sos3.getValue() == null) {
showPopup(p2, true); */
}
return null;
}
Step 3: I erase the values from it2 and it3, I click the button again and call the same method. However, the value from it2 and it3 stays the same.
Why does this happen and how can I fix it?

Try to re-think your approach: instead of doing the business in backing beans, try to use BC layer. So you can move the method
public String aplicarFiltro() {..} into Application Module Impl.
There, programatically get a reference to your VO's current Row and read the attribute's values.
First, test your scenario (your method) from BC Tester. Then, you can expose the method through bindings, and call it from backing beans.
ALso, I would expose the RowImpl class for your VO and put some debug info into setIt1(), setIt2(), setIt3() attributes, to see how the change.
Remember, is always far more simple to manage your business on BC layer than managed beans. Stay away from JSF life cycle.

Don't know if more things are wrong. But you're only setting "i2param" to something other than null if i1 has a value and "i3param" to something other then null if i1 and i2 has a value.
So start with the following. Change this:
if(it1.getValue() == null || it1.getValue().toString().isEmpty()) {
it1param = "";
} else {
it1param = it1.getValue();
if(it2.getValue() == null || it2.getValue().toString().isEmpty()) {
it2param = "";
} else {
it2param = it2.getValue();
if(it3.getValue() == null || it3.getValue().toString().isEmpty()) {
it3param = "";
} else {
it3param = it3.getValue();
}
}
}
to:
if(it1.getValue() == null || it1.getValue().toString().isEmpty()) {
it1param = "";
} else {
it1param = it1.getValue();
}
if(it2.getValue() == null || it2.getValue().toString().isEmpty()) {
it2param = "";
} else {
it2param = it2.getValue();
}
if(it3.getValue() == null || it3.getValue().toString().isEmpty()) {
it3param = "";
} else {
it3param = it3.getValue();
}

Related

How to remove multiple returns from this function

i have written a function that calculates the intersection of two sorted linked lists (in a recursive way), but i need to remove those "return" inside the if statement and readapt the code without them. Any suggestions? Thanks in advance
t_nodo *intersezione_insieme(t_nodo *insieme_A, t_nodo* insieme_B)
{
t_nodo *tmp;
if (insieme_A == NULL || insieme_B == NULL) {
tmp = NULL;
}
else if (insieme_A->info < insieme_B->info) {
return intersezione_insieme(insieme_A->succ, insieme_B);
}
else if (insieme_A->info > insieme_B->info) {
return intersezione_insieme(insieme_A, insieme_B->succ);
}
else
{
tmp = (t_nodo*)malloc(sizeof(t_nodo));
tmp->info = insieme_A->info;
tmp->succ = intersezione_insieme(insieme_A->succ, insieme_B->succ);
}
return tmp;
}
Like it was outlined in the comments, having multiple returns in a function is not necessarily bad form. It all depends on the context. For example, a long-ish function might check for a few "return now" conditions before executing the function's code.
But I can see readability being increase by having a single return statement in your function.
Here's my humble suggestion :
t_nodo *intersezione_insieme(t_nodo *insieme_A, t_nodo* insieme_B)
{
t_nodo *temporaneoNodo;
if (insieme_A == NULL || insieme_B == NULL) {
temporaneoNodo = NULL;
}
else if (insieme_A->info < insieme_B->info) {
temporaneoNodo = intersezione_insieme(insieme_A->succ, insieme_B);
}
else if (insieme_A->info > insieme_B->info) {
temporaneoNodo = intersezione_insieme(insieme_A, insieme_B->succ);
}
else
{
temporaneoNodo = (t_nodo*)malloc(sizeof(t_nodo));
temporaneoNodo->info = insieme_A->info;
temporaneoNodo->succ = intersezione_insieme(insieme_A->succ, insieme_B->succ);
}
return temporaneoNodo;
}

mxGraph connection handler mouse cursor does not change to hand cursor

I created a new mxgraph react project.
When mouse moved to vertex cursor changes to move_cursor. but I want to create a link and cursor will be hand cursor. how can i solve this problem?
There is a code snippet about connection settings.
settingConnection = () => {
const { graph } = this.state;
mxConstraintHandler.prototype.intersects = function(
icon,
point,
source,
existingEdge
) {
return !source || existingEdge || mxUtils.intersects(icon.bounds, point);
};
var mxConnectionHandlerUpdateEdgeState =
mxConnectionHandler.prototype.updateEdgeState;
mxConnectionHandler.prototype.updateEdgeState = function(pt, constraint) {
if (pt != null && this.previous != null) {
var constraints = this.graph.getAllConnectionConstraints(this.previous);
var nearestConstraint = null;
var dist = null;
for (var i = 0; i < constraints.length; i++) {
var cp = this.graph.getConnectionPoint(this.previous, constraints[i]);
if (cp != null) {
var tmp =
(cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
if (dist == null || tmp < dist) {
nearestConstraint = constraints[i];
dist = tmp;
}
}
}
if (nearestConstraint != null) {
this.sourceConstraint = nearestConstraint;
}
// In case the edge style must be changed during the preview:
// this.edgeState.style['edgeStyle'] = 'orthogonalEdgeStyle';
// And to use the new edge style in the new edge inserted into the graph,
// update the cell style as follows:
//this.edgeState.cell.style = mxUtils.setStyle(this.edgeState.cell.style, 'edgeStyle', this.edgeState.style['edgeStyle']);
}
mxConnectionHandlerUpdateEdgeState.apply(this, arguments);
};
if (graph.connectionHandler.connectImage == null) {
graph.connectionHandler.isConnectableCell = function(cell) {
return false;
};
mxEdgeHandler.prototype.isConnectableCell = function(cell) {
return graph.connectionHandler.isConnectableCell(cell);
};
}
graph.getAllConnectionConstraints = function(terminal) {
if (terminal != null && this.model.isVertex(terminal.cell)) {
return [
new mxConnectionConstraint(new mxPoint(0.5, 0), true),
new mxConnectionConstraint(new mxPoint(0, 0.5), true),
new mxConnectionConstraint(new mxPoint(1, 0.5), true),
new mxConnectionConstraint(new mxPoint(0.5, 1), true)
];
}
return null;
};
// Connect preview
graph.connectionHandler.createEdgeState = function(me) {
var edge = graph.createEdge(
null,
null,
"Edge",
null,
null,
"edgeStyle=orthogonalEdgeStyle"
);
return new mxCellState(
this.graph.view,
edge,
this.graph.getCellStyle(edge)
);
};
};
Mouse cursor only change to move cursor, but I want to changes to hand cursor when mouse moved to vertex.
When I deleted some codes,
var mxConnectionHandlerUpdateEdgeState =
mxConnectionHandler.prototype.updateEdgeState;
mxConnectionHandler.prototype.updateEdgeState = function(pt, constraint) {
if (pt != null && this.previous != null) {
var constraints = this.graph.getAllConnectionConstraints(this.previous);
var nearestConstraint = null;
var dist = null;
for (var i = 0; i < constraints.length; i++) {
var cp = this.graph.getConnectionPoint(this.previous, constraints[i]);
if (cp != null) {
var tmp =
(cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
if (dist == null || tmp < dist) {
nearestConstraint = constraints[i];
dist = tmp;
}
}
}
if (nearestConstraint != null) {
this.sourceConstraint = nearestConstraint;
}
// In case the edge style must be changed during the preview:
// this.edgeState.style['edgeStyle'] = 'orthogonalEdgeStyle';
// And to use the new edge style in the new edge inserted into the graph,
// update the cell style as follows:
//this.edgeState.cell.style = mxUtils.setStyle(this.edgeState.cell.style, 'edgeStyle', this.edgeState.style['edgeStyle']);
}
mxConnectionHandlerUpdateEdgeState.apply(this, arguments);
};
if (graph.connectionHandler.connectImage == null) {
graph.connectionHandler.isConnectableCell = function(cell) {
return false;
};
mxEdgeHandler.prototype.isConnectableCell = function(cell) {
return graph.connectionHandler.isConnectableCell(cell);
};
}
And I wrote this codes,
// Enables connect preview for the default edge style
graph.connectionHandler.createEdgeState = function(me) {
var edge = graph.createEdge(null, null, null, null, null);
return new gr.mxCellState(
this.graph.view,
edge,
this.graph.getCellStyle(edge)
);
I solve this problem :)

Handling Response datas and moving into array

I have a response from backend. Where I need to pass the state based on selected country in dropdown and City based on selected state in dropdown for my form.
I am able to push them into array , but it is getting replaced. For instance.Country India also will have states of USA ,it has been replaced with india states.Need Assistance.
Response :
Geography :
[{"countryname":"India",
"states":[{"statename":"Karnataka",
"cities":[{"city":"Bangalore","segments":[{"segment":""}]},
{"city":"Hubli","segments":[{"segment":""}]}]},
{"statename":"Tamil Nadu",
"cities":[{"city":"Chennai","segments":[{"segment":""}]},
{"city":"Coimbatore","segments":[{"segment":""}]}]}]},
{"countryname":"USA",
"states":[{"statename":"California",
"cities":[{"city":"San Francisco","segments":[{"segment":""}]},{"city":"San Jose","segments":[{"segment":""}]}]},
{"statename":"New Jersey",
"cities":[{"city":"Princeton","segments":[{"segment":""}]},
{"city":"South Brunswick","segments":[{"segment":""}]}]}]}]
JS :
UserService.Geography(json).then(function(response) {
$scope.model.countries = [];
$scope.model.countries.push("ALL");
if (response.json.response.statuscode == 0 && response.json.response.statusmessage == 'Success') {
var geography = response.json.response.geography;
console.log("Geography : " + JSON.stringify(geography));
$scope.geography = geography;
for (var i = 0; i < geography.length; i++) {
$scope.model.countries.push(geography[i].countryname);
console.log($scope.model.countries);
if (($scope.model.countries != []) || ($scope.model.countries != null)) {
$scope.model.states = [];
$scope.model.states.push("ALL");
for (var j = 0; j < geography[i].states.length; j++) {
if (geography[i].states) {
$scope.model.states.push(geography[i].states[j].statename);
} else {
$scope.model.states.push(geography[i].state[j].statename);
}
console.log($scope.model.states);
if (($scope.model.states != []) || ($scope.model.states != null)) {
$scope.model.cities = [];
$scope.model.cities.push("ALL");
// for first time combobox loading,
// load only cities for first state
if (j === 0) {
for (var k = 0; k < geography[i].states[j].cities.length; k++) {
console.log('======k=====:'+k);
console.log('geography[i].states[j].cities[k].city=====:'+geography[i].states[j].cities[k].city);
if (geography[i].states) {
$scope.model.cities.push(geography[i].states[j].cities[k].city);
} else {
$scope.model.cities.push(geography[i].state[j].cities[k].city);
};
console.log('$scope.model.cities: '+ $scope.model.cities);
if (($scope.model.cities != []) || ($scope.model.cities != null)) {
$scope.model.segments = "_ALL";
console.log($scope.model.segments);
}
}
}
$scope.model.selectedCity = $scope.model.cities[0];
}
}
$scope.model.selectedState = $scope.model.states[0];
}
}
$scope.model.selectedCountry = $scope.model.countries[0];
}
});
}
Just transform your data to array of objects with format like
{ country, state, city }
example transform with lodash:
var data = [];
var cities = _.flatMap(data, mapCountries);
function mapCountries(country){
return _.flatMap(country.states, mapStates).map(setAttr('country', country.countryname));
}
function mapStates(state){
return state.cities.map(setAttr('state', state.statename));
}
function setAttr(key, value){
return function(obj){
obj[key] = value;
return obj;
}
}

Typescript sorting array with objects on multiple properties

I like to sort an array with objects that have multiple properties. My objects have a string called name and a boolean called mandatory.
First i want to sort on age, next on the name.
How do I do this?
Ordering by age is easy...:
this.model.mylist.sort((obj1: IObj, obj2: IObj => {
if (obj1.age < obj2.age) {
return -1;
}
if (obj1.age > obj2.age) {
return 1;
}
return 0;
});
Well, you only add comparation for case when the two age values are the same. So something like this should work:
this.model.mylist.sort((obj1: IObj, obj2: IObj) => {
if (obj1.age < obj2.age) {
return -1;
}
if (obj1.age > obj2.age) {
return 1;
}
return obj1.name.localeCompare(obj2.name);
});
Something like this should work. The method compares the current and next values and adds comparison to the case when the two age values are the same. Then assume the column name in order based on age.
private compareTo(val1, val2, typeField) {
let result = 0;
if (typeField == "ftDate") {
result = val1 - val2;
} else {
if (val1 < val2) {
result = - 1;
} else if (val1 > val2) {
result = 1;
} else {
result = 0;
}
}
return result;
}
-
this.model.mylist.sort((a, b) => {
let cols = ["age", "name"];
let i = 0, result = 0, resultordem = 0;
while (result === 0 && i < cols.length) {
let col = cols[i];
let valcol1 = a[col];
let valcol2 = b[col];
let typeField = "string";
if (col == "age") {
typeField = "number";
}
if (valcol1 != "null" && valcol1 != "null") {
resultordem = this.compareTo(valcol1, valcol2, typeField);
if (resultordem != 0) {
break;
}
}
i++;
}
return resultordem;
});

AS3: A term is undefined

All right so the first piece of code here is for when the user is re-selecting a button for it to clear and then set the Array spot to a blank number. The second piece is where the issue is with the error A term is undefined. Now i haven't had this issue until I added the first piece.
if(tempArray[1] == pickFive[0]){
Game.BARR.balls.balls2.b1.num1.text = '';
pickFive.splice(pickFive.indexOf(tempArray[1]), 1);
pickFive[0] = ("");
}
if(pickFive[0] != null){
//trace(Game.NumberBoard_mc.Pick5['btn_' + pickFive[0]].name);
Game.NumberBoard_mc.Pick5['btn_' + pickFive[0]].gotoAndStop(2);//Saying this line
Game.BARR.balls.balls2.b1.num1.text = pickFive[0];
}
if (pickFive.indexOf(tempArray[1]) != -1) {
if(event.target.currentFrame == 2) {
event.target.gotoAndStop(1);
}
if(tempArray[1] == pickFive[0]){
Game.BARR.balls.balls2.b1.num1.text = '';
pickFive[0] = "";
}
if(pickFive[0] != null){
    if(pickFive[0] != ""){
    Game.NumberBoard_mc.Pick5['btn_' + pickFive[0]].gotoAndStop(2);
    Game.BARR.balls.balls2.b1.num1.text = pickFive[0];
    }
  }

Resources