Dagger 2 injection of recreated module - dagger-2

I have NameComponent and NameModule. Also I have list of names. When user select one of item in list I create new NameModule.
In my Application class I have following code:
public NameComponent createNameComponent(String name) {
nameComponent = DaggerNameComponent
.nameModule(new NameModule(name))
.build();
return nameComponent;
}
I have textView with a current selected name Name1.
name field is injected.
When user select name Name2 in list I need refresh so I do this:
textView.setText(name);
but it does not refresh name.
My question is how to force to inject field on module change? Do I have to recreate Activity every time when I change module?

Since the component returned by the second call to createNameComponent is different from first one, you need to call component.inject(this) every time.

Related

Sync data from component back to the calling page in ionic 5

In my Ionic 5 project, I have created a custom component and passing the data from a Page.
HomePage HTML:
<app-userItem [inUser]="user (outSync)="syncUser($event)"></app-userItem>
Where user is.
let user = {
Name: 'Test User',
Age: 23
}
Now I want if inside component UserItem I change the value of Age, it should be synced back in the Homepage user variable. It is not happening automatically.
To Achieve this I am using the outSync event emit method for now. My question is as I am using [] to pass value of parameter inUser, shouldn't the user variable be in sync from both sides?
Now I want if inside component UserItem I change the value of Age, it should be synced back in the Homepage user variable. It is not happening automatically.
I think the reason why it's not happening automatically is because Angular compares the object identity to see if something has changed, but in your case, user === user is true even after changing user.age because the instance is still the same.
It doesn't mean the object is not being updated – it's just that Angular doesn't know that because the instance of the object is the same so as far as Angular knows, nothing have been changed.
A better approach would be if the UserItemComponent only presents the data, but doesn't change it directly (which would make it a dumb or presentational component).
For example, if that component could change both the name and the age properties, it'd be better if it just notifies the parent that those properties should be changed, and it's the parent who updates the user.
<app-userItem
[inUser]="user
(updateAge)="updateAge($event)"
(updateName)="updateName($event)"
></app-userItem>
And then the parent component would modify the data, creating a new instance of the object so that the child receives the update:
public updateAge(newAge: number): void {
this.user = {
...this.user,
age: newAge
};
}

Add into embedded list of type embedded link map additional objects

i have a class of users with an attribute of address which is an embedded list of link type is embedded link map i already was entering with update #rid set address = { "k1":"v1", "k2:"v2" } this object is being placed fine, whenever i use the same query but replacing set with add in order to place a second object into the same list it is throwing a java.lang exception, whenever i am adding into the address directly accessing the vertex record its working fine so i want to know how can i add more objects of type map into the same list?
I don't know if I understood you problem correctly, but here's a possible workaround:
create class Adress
create property Adress.city string
create property Adress.zipcode string
create class User
create property User.adress EMBEDDEDLIST Adress
insert into User set adress = [{"#type":"d","#class":"Adress","city":"london", "zipcode":"4323"}]
update User add adress = [{"#type":"d","#class":"Adress","city":"lisbon", "zipcode":"1516"}]

GXT 3 dynamically update an element in a treeStore

i'm currently using GXT 3 to display elements in a Tree.
These elements are retrieved from database and identified in the Tree by their id (by that, I mean that the id is the ModelKeyProvider of my store).
I also made it possible for users to create objects locally in the tree with the following code:
private Tree<EntityDAO, String> tree;
private TreeStore<EntityDAO> store;
int count = 1;
// instanciation and irrelevant stuff
...
EntityDAO sel = tree.getSelectionModel().getSelectedItem();
EntityDAO child = new EntityDAO();
child.setId((long) count);
store.add(store.getParent(sel), child);
count++;
tree.setExpanded(sel, true);
tree.getSelectionModel().select(child, false);
As you can see, i set a temporary id (count) to my local object.
The issue occurs when I save my object in database. A permanent id is then set to my EntityDAO but when i try to set this id to my local object to sync it with the database, it doesn't work.
I've tried to modify the child id directly
child.setId(result);
tree.update(child);
I've tried to add a copy of my object with the proper id, and then to remove my object from the tree
EntityDAO newPR = child;
newPR.setId(result);
store.add(store.getParent(child), newPR);
store.remove(child);
But the display is never updated. Any clue?
Let's discuss about the first way you tried, the update method:
child.setId(result);
tree.update(child);
From the update method API state this :
Replaces the item that matches the key of the given item, and fires a
StoreUpdateEvent to indicate that this change has occurred. Any
changes to the previous model via it's record instance will be lost
and the record will be removed. This will not cause the sort or filter
to be re-applied to the object. Overrides: update(...) in Store
Parameters: item the new item to take its place in the Store.
So basically, the update method will replace the item inside the store that have the same key with your parameter. Your data have a new key that doesn't exist inside the store, that's why it doesn't effected anything to your tree display.
Second, let's discuss the create a copy of your object and set it with the proper id:
EntityDAO newPR = child;
newPR.setId(result);
store.add(store.getParent(child), newPR);
store.remove(child);
This way actually will work, but you only have one small problem. The first line of your code actually just give you a variable that have a reference to your old object (the child object), so whenever you remove the child, the newPR also removed. You should really create a new object using the constructor, here how I think you should do it:
EntityDAO newPR = new EntityDAO();
newPR.setId(result);
newPR.setOtherProperty(child.getOtherProperty());
// just copy all property of child to newPR
store.add(store.getParent(child), newPR);
store.remove(child);
Hope this can help you.

Use a GWT Entity Proxy to temporarly save changes. Implementing 'Apply changes' pattern

I have a CellTable<UserProxy>. So in other words it manages directly entity proxies of my database entities. With that I use an AsyncDataProvider<UserProxy> that fetches the data using a request factory.
The cells of my columns are EditTextCell. And I added a FieldUpdater<UserProxy, String> to edit the values. Except here is my problem: if I update the value of the entity and save it immediately it works fine, but I don't know how I can differ the save to a click on a button later.
Basically, I want to implement the Apply-changes pattern (see: http://patterns.holehan.org/Review/ApplyChanges), so I want the user to be able to edit several values in the table and once he is done he can click the 'apply' button which will save all the changes.
So my idea for this was to change the value in the proxy entity without invoking save and then saving all modified entities in the clickhandler of the button.
But to make the change to a value in a proxy entity, I must call ctx.edit(user) first:
nameColumn.setFieldUpdater(new FieldUpdater<UserProxy, String>() {
#Override
public void update(int index, UserProxy object, String value) {
if (!value.equals(object.getName())) {
UserRequest ur = presenter.getClientFactory().getRequestFactory().getUserRequest();
ur.edit(object);
object.setName(value);
saveButton.setEnabled(true);
}
}
});
And this makes it impossible to save them afterwards in the clickhandler of the apply button:
private void saveModifications() {
List<UserProxy> items = cellTable.getVisibleItems();
for (UserProxy item : items) {
UserRequest ur = presenter.getClientFactory().getRequestFactory().getUserRequest();
ur.save(item).fire();
}
cellTable.setVisibleRangeAndClearData(cellTable.getVisibleRange(), true);
}
Because calling save(item) throws this exception: java.lang.IllegalArgumentException: Attempting to edit an EntityProxy previously edited by another RequestContext
How to avoid this without having to make yet another class representing the same entity?
You must use a single RequestContext instance where you edit() all your proxies. You can edit() several times the same proxy with no error and no overhead.
So:
store presenter.getClientFactory().getRequestFactory().getUserrequest() in a variable/field somewhere
in the FieldUpdaters, ctx.edit(object).setName(value) will enqueue the changes in the RequestContext; possibly put the UserProxy in a Set too for later reference
in saveModifications, loop over your proxies (possibly only those from the Set built on step 2) and ctx.save(item) and then at the end of the loop ctx.fire()

How to customize register and contact forms in PrestaShop?

I need to know how to customize my contact and register forms. How to add new fileds ( and ) and make the information from these fields required or not required.
I need to know which files I must edit for these forms...
I use prestashop 1.4.7.0
This is really two separate questions as there are major differences in how you would handle each case.
Answer 1
For the registration form you can write a module which contains two hook handler functions. These will be:
public function hookCreateAccountForm() {}
public function hookCreateAccount($params) {}
The first function allows you to add additional fields to the registration form (by default these are inserted at the end of the form authentication.tpl, although you could move them all as a single group elsewhere). It should simply return the additional form html you require.
The second function provides you with two parameters to handle the account creation process. This is executed after the standard fields have been validated and the new customer has been created. Unfortunately you cannot do validation on your additional fields using this (you would need to either use javascript or override AuthController to perform your own authentication in the preProcess() member function). In one of my own custom modules for a site I have the following, for example:
public function hookCreateAccount($params)
{
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$customer = $params['newCustomer'];
$address = new Address(Address::getFirstCustomerAddressId((int)$customer->id));
$membership_number = $params['_POST']['membership_number'];
....
....
}
$params['newCustomer'] is a standard Prestashop element in the array and contains the newly created customer object. Your fields will be in the $params['_POST'] array - in my case it was an input field called membership_number.
Answer 2
For the contact form it's a whole lot more complicated I'm afraid. The simplest method for the html is to just hard-code your additional fields in the template file contact-form.tpl.
To actually process the form you will need to create an override for the controller by ceating a file called ContactController.php in /<web-root>/<your-optional-ps-folder>/override/controller containing something like:
<?php
class ContactController extends ContactControllerCore {
function preProcess()
{
if (Tools::isSubmit('submitMessage'))
{
// The form has been submitted so your field validation code goes in here.
// Get the entered values for your fields using Tools::getValue('<field-name>')
// Flag errors by adding a message to $this->errors e.g.
$this->errors[] = Tools::displayError('I haven't even bothered to check!');
}
parent::preProcess();
if (Tools::isSubmit('submitMessage') && is_empty($this->errors))
{
// Success so now perform any addition required actions
// Note that the only indication of success is that $this->errors is empty
}
}
}
Another method would be to just copy the entire preProcess function from controllers\ContactController and just hack away at it until it does what you want....