search-container-row by multiple PK value of the keyProperty - liferay

I have a portlet that has multi PK fields in the service.xml.
I have change some classes and JSPs to set and get the PKs values and save and load the records, but I cant view the registered records on the view.jsp page because I cant set the value of the keyProperty attribute of the search-container-row.
My portlet with AppB name has the AppBPK class that has the AppBPK(long ID1, long ID2) constructor.
How can I set the keyProperty attribute to view the records?

Related

Django Initialise NOT value of Bool Field From Model in ModelAdmin Form

I have a boolean field in a legacy database and want to render it in a checkbox as the NOT value of the db field value. For example,
false would be rendered as an checked checkbox
true would be rendered as an unchecked checkbox
class MyModel(models.Model):
"""Model with a boolean field for existing data in db"""
flag = models.BooleanField()
How can I use a Django ModelAdmin form so that the field is loaded with the NOT value of the model on form load?
Alternatively, how do I create my own checkbox widget to render the NOT value from the underlying model?

Why is the BranchId filtered in the data view SQL statement

I create a custom DAC, which contains a BranchID field. The client's requirements for this field, is to insert the value 0, as default. The field is defined as a KeyField, but no PXDefault attribute is defined. I use PXRowPersisting event handler, in order to set the value in cases of 0. I use a ListView screen, in order to return the records. But no records are returned. I noticed in the SQL trace, that a filter is applied to BranchID field:
AND ([MyCustomTable].BranchID IS NULL OR [MyCustomTable].BranchID IN (16, 17, 20))
Why is this filter added?
For any table, that contains BranchID or UsrBranchID column, the framework automatically includes the BranchID condition into Where clauses. No matter what attributes are applied on a DAC field, if partucular DAC is bound to the table containing BranchID or UsrBranchID column, the BranchID condition will be added into all Where clauses generated for this table.
For your specific scenario, a possible solution would be to rename BranchID column to something different than BranchID or UsrBranchID. If you will ever need to force application of the Branch-based access restriction to your custom DAC, just add the MatchWithBranch<MyDAC.myBranchID> operator into a BQL query.

Creating an aggreagte with one entity and value objects

I am struggling with the concepts of entities and value objects.
I have read about the differences between entities and value objects but I am not able to transfer the knowledge to my example.
I would like to create an aggreagte "retailer"
The retailer has the attributes "id", "name", "adress" (Street, ZIP, Country) and
GPS coordinates (Latitude, Longitude)
My "aggregate root" is the entitiy "retailer".
What is the value object here and what is the attribute of the entitiy?
Is the adress an attribute of entity "retailer" or is "adress" a value object?
Is "GPS" a value object by its own or attributes of value object "adress"?
What is a usefull way to organize this? I added an example how it is organized in my project. What is the value adding the adress to a value object rather adding it as attributes to entitiy "retailer"?
aggregate retailer
What is the value object here and what is the attribute of the entitiy? Is the adress an attribute of entity "retailer" or is "adress" a value object? Is "GPS" a value object by its own or attributes of value object "adress"?
It is both an attribute and a value object: an attribute is from the object oriented point of view; a value object from the DDD point of view: data with behavior, immutable.
GPS should be a value object containing latitude and longitude primitive values.
What is the value adding the adress to a value object rather adding it as attributes to entitiy "retailer"?
The advantage is that a value object encapsulates all its data and behavior, removing responsibilities from it's parent entity. Also, it expresses more intuitively the fact that its properties have a meaning only together (latitude and longitude should be set always together).

Is it possible to use custom JSF converter for UISelectOne, depending on value of Bean property or UIInputText value?

I need to get help with a problem.
I have an application, which displays data from database.
In database I am using one column for identifying an object with changes in time (version of object).
I mean that rows have different IDs, but same OBJECT_ID.
They are also differentiated by validity DATE columns (VALID_FROM and VALID_TO), so i can find the proper version of object in selected time.
When page is shown to user, he sets DATE for displaying data.
There is form on page, with Select Boxes (their items are object from database).
I need to show only items, that satisfy the validity condition.
Everything is OK before form handling.
I am using custom converter, that converts String value (ID of row in database table) to Object of my model, but I need two values for row to find. (ID and DATE from user form).
Converter method getAsObject gets only one VALUE parameter (ID from Select Box).
How to get second parametr to work?
Can i find it from Bean or from JSF input object?
If there is some way that includes using <f:attribute/>, is there way to set <f:attribute/> by Java code in Bean? (Form is generated by bean method).
I am sorry for my English, i try my best :o)
P.S.: Date parameter is important in sqlMap because of JOIN used. I search by ID, but other tables are joined by OBJECT_ID (version) => and i need to get one row only
Thanks for answers and have a nice day
Worsik
Edit:
Select Boxes are generated by this code:
uiInput = new HtmlSelectOneMenu();
UISelectItems items = new UISelectItems();
items.setValueExpression("value", createValueExpression(
"#{myBean.referencedList." + item.getName() + "}",
List.class));
uiInput.getChildren().add(items);
Converter method looks like this:
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
if (value.equals("")) {
return null;
}
Class entityType = component.getValueExpression("value").getType(
FacesContext.getCurrentInstance().getELContext());
// TODO: need to get date value from form
Date day = new Date();
return myService(context).findEntityById(entityType, Long.valueOf(value), day);
}
entityType is Class of model for object from database
myService calls Dao object and sqlMap is called
select * from object_table as t1
JOIN other_table as t2 ON t1.object_fk = t2.object_id // (or version_id)
where t1.id = #id:INTEGER#
and t2.valid_from <= #day:DATE#
and t2.valid_to >= #day:DATE#
I figured out how to do this by <f:attribute/> by code in converter:
Date day = (Date) component.getAttributes().get("dateForSearch");
and in bean method after generating SelectBox with code:
uiInput.getAttributes().put("dateForSearch", getSelectedDate());
and in pages without dynamic generating of forms i used:
<SelectOneMenu>
...
<f:attribute name="dateForSearch" value="#{myBean.selectedDate}" />
</SelectOneMenu>
I hope that this will not be only self answered question and will help somebody else

SPList.GetItems defaultView returning different fields than are actually present in the DefaultView of the list

I am binding the SPList Items to the GridView by getting a DataTable, but I am getting entirely different fields in the DataTable from the fields which are present in the DefaultView of the SPList.
Not the field names changed (internal names/ title) , but the fields itself are different ones than are present in the list's default view.
I am using the following code:
GridView gd = new GridView();
gd.DataSource = list.GetItems(list.DefaultView).GetDataTable();
This is most likely due to the list.DefaultView either not being populated or correct. Try setting the value before you call get items. i.e..
SPView defView = list.DefaultView;
gd.DataSource = list.GetItems(list.DefaultView).GetDataTable();

Resources