where is Session's attributes are saved - java

I'm trying to add an attribute to session, in a huge pre-realized project (web application project using Java and Tapestry framework), but I don't know where the attribute are saved, so that I can declare a new attribute for Session

in fact , I found out that attributes are added like variable into the session declaration, using just session.setAttribute("Attribute", name)
and then it will be saved, and you can access it using session.getAttribute(name)

Related

Remove dynamic attribute in hybris through backoffice

When the dynamic attribute is removed from the items.xmls, hybris reports an error because the attribute handler Spring bean don't exist. This error usually prevents saving models of the Hybris type which owned the attribute. Even after the bean declaration and attribute are removed, hybris still complains about the existance of the reference to a bean.
How to remove DynamicAttributeHandler from the DB through backoffice in Hybris?
The cleanest way to do this is to go to backoffice -> Types -> search for your type -> Properties and then remove the property and save.
You have to remove your custom attribute from the Attributedescriptors table.
Use a direct SQL statement :
DELETE FROM attributedescriptors WHERE (QualifierInternal ='attributename')

database hits occur or not when access foriegn key columns in struts2 tag

I have used struts2 tags for getting action class property values in jsp page.I have a table called employee.In that employee table, address is the foriegn key.I get a employee details in lazy fetcthing and load the values using list.
List<Employee> empList=cr.list();
when i get the address from struts2 tags in jsp page using the below tag.
<s:property value="address.getDoorno()"/>
i know in struts2 the action class properties are stored on the valuestack.
my doubt is the valuestack stores the proxy object or original object and if stores the proxy object database hit occurs or not,and if original object when value stack converts the proxy object to original object?
Any help will be greatly appreciated!!
As you have configured lazy loading struts 2 will store proxy object. Either you enable eager loading or initialize the address object within session itself

#Version Spring dont work with ObjectForm

I use #Version in one Java class and all Java classes extends of this. okey.
I also use objectForm. I use this because it is assumed that is more secure (I hide all <form:hidden path="XX"/> from JSP), but when I open two tabs in my browser, if I modify and safe the object in the two tabs, Spring does not check that the version is lower than that of the database and save it. If I not use object form, Spring alert me that the version is lower. Yes, objectForm is obligatory.
The idea is: I send ObjectForm at JSP. I modify the object from jsp and then, I return object form to controller. This, convert the objectForm to object and save the object.
Any idea?
Some pictures:
The #Version annotation only works in Hibernate entity classes, that are directly saved into the database.
If you do the following the #Version will be validated, throwing an exception if an object with an invalid version is attempted to be saved in the database:
read an entity from the database annotated with #Version
copy entity data to a view layer object (including the version)
modify it on the view layer
on save button pressed, copy the form data including the version to a new entity object
to save the new data, call entityManager.merge()
the merge will trigger a database selection. if the version in the database is higher than the merged object you will get a StaleObjectException

Creating custom user attributes in Active Directory using JNDI

I am attempting to create a custom attribute that can be assigned to an existing Active Directory user in my domain. I am not fully aware of how to achieve this. It is my understanding that once the attribute has been created, I can assign it to the user via:
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("attributeName", "attributeValue"))
ctx.modifyAttributes(userDN, mods)
Any information is appreciated.
Not sure what you want to do.
But Active-Directory is a Directory, so it use a SCHEMA to define which attributes can be used in an object. This means that you can modify (add, delete, replace) the value of an attribut that exists (in the SCHEMA) for a given class, but can'nt add a custom attribut to a class without modifying the SCHEMA.

Submitting / binding partial objects with spring mvc

The Spring MVC binding mechanism is powerful, but I'm now confronted with a trivial issue that I wonder how to resolve:
User JPA entity, that is used for the binding and validation as well (i.e. throughout all layers)
"Edit profile" page, that is not supposed to change the password or some other entity properties
Two ways that I can think of:
Using the same object
use #InitBinder to configure a list of disallowed properties
obtain the target user (by id)
then use a reflection utility (BeanUtils) to copy the submitted object to the target object, but ignore null values - i.e. fields that are not submitted
Introduce a new object that has the needed subset of fields, and use BeanUtils.copyProperties(..) to merge it to the entity.
Alternatives?
I've found that as soon as your web model starts to diverge from your business layer in function, it's best to use a view layer object (a model object) to collect, or display the data
the entity:
public class com.myapp.domain.UserEntity {
}
the model object:
public class com.myapp.somesite.web.SomeSiteUserModel {
public static SomeSiteUserModel from(UserEntity userEntity) {
... initialize model ...
}
public UserEntity getModelObject() {
... get entity back ...
}
}
now all view based operations can hand off processing to the internal model object if that makes sense, otherwise it can customize them itself. Of course the problem with this is you have to re-write all the getters and setters you want for the entity (an issue that I've had to deal with, that is annoying) unfortunately that is a bit of a Java language issue
I just checked up with two of the last Spring projects I have worked on and in both places the following approach is taken:
In the JSP page for the form the change password field has a name that does not match the name of the password field in the User bean, so that it doesn't get mapped to the bean. Then in the onSubmit method there is a separate check whether a new password has been submitted, and if it has been, the change is reflected explicitly.
Поздрави,
Vassil
You can read the object from the database first and bind then the request. You can find an example at FuWeSta-Sample.
It uses a helper-bean which must be initialized by Spring.

Categories