After i configured Full Text Search add-on, when I tried to open a founded item I encountered the next error: IllegalStateException: Cannot get unfetched attribute [quAmount] from detached object .entity.Transaction-540af3ca-a206-9853-a217-1aeb8ca00ac4 [detached].
Below the (pointed) code if(getEditedEntity().getQuAmount():
@LoadDataBeforeShow
public class TransactionEdit extends StandardEditor<Transaction> {
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
if(getEditedEntity().getQuAmount()!=null){
//logic
}
}
If I open the same transaction Edit screen from Application Menu works fine. quAmount is an attribute of Transaction. sys_fts_queue table from database is empty.
The problem is that when BeforeShowEvent is received, the data is not loaded yet. Calling the method getEditedEntity() returns you an instance of Transaction passed to the editor screen when it was created. When you open the founded item in the FTS search results screen, an instance of Transaction loaded with the _minimal view is passed and this view does not include the quAmount attribute. That’s why you get the error.
If you want to work with the edited entity in the BeforeShowEvent, you should first load it:
public class TransactionEdit extends StandardEditor<Transaction> {
@Inject
private InstanceLoader<Transaction> transactionDl;
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
transactionDl.load(); // load the data
if(getEditedEntity().getQuAmount()!=null){
//logic
}
}
Also, be sure to remove the @LoadDataBeforeShow annotation in order to prevent reloading the data after the BeforeShowEvent.
Hi Gleb,
I don’t want really to work with BeforeShowEvent but is the only workaround to get an (Editor) attribute in order to avoid NullPointerException.
If I use transactionDc.getItem() or getEditedEntity under onInit I have this kind of exception. I understood that in order to avoid this, prior I must set the item, but I don’t know how to do it. - some kind of transactionDc.setItem (//????).
Nevertheless if is so, why getEditedEntity is working if is placed under a listener?
@LoadDataBeforeShow - is the default setting, in this page I have another events (onInitEntity, onInit) and I’m not sure that is the right solution to delete it(I’m afraid to break something).
So this is the explanation why when I open the Transaction editor screen I don’t have this error. Because it used different view. How could I know that FTS search use _minimal view instead of let say _local view.
I replaced onBeforeShow with onAfterShow and everithing is fine now.
I suppose that under onAfterShow event, data is already load it.
Basically, the item is set to the data container automatically once it is loaded by the corresponding data loader. You can find out more about the screen’s Data Components in the documentation. The screen data is loaded automatically before showing the screen (after BeforeShowEvent) if the screen controller is annotated with @LoadDataBeforeShow. Here you can find out more information on this.
Entities can be loaded with the different Views, which describe a set of attributes to be loaded from the database. When some attribute is not included in the view, which was used when loading the entity, you’ll get an error like this: IllegalStateException: Cannot get unfetched attribute...
The thing is, when you have not loaded the entity with the certain view by yourself, you rely on the code that opened your screen and set the entity instance loaded with some unknown view (in your case, FTS used _minimal view). So, you should always load the instance with the desired view to ensure that all needed attributes are loaded.
Because the ItemChangeEvent is received when data (edited entity) is loaded and set to the data container.
You can try out our learning resources and found examples in the sample projects. Also, don’t hesitate to ask questions on the forum if you found something unclear in the documentation.
Thank you very much for your detailed answer!
Now is crystal clear.
Only 2 issues related to full text search add-on:
If the FTS add-on is added to the application, and the fts.enabled property is enabled, then each time when an indexable entity is being saved to the database its identifier gets added to the indexing queue – SYS_FTS_QUEUE table.
I ve checked my PostgreSQL database and sys_fts_queue is empty. Why? Is it normal?
Let say I have recorded a string: T005. If I search after 005 the filter founds nothing. If I look after T005 the item is found it. Why? Is it normal behavior?
First, ids are added to SYS_FTS_QUEUE table and after indexing they are deleted from this table. So you are likely checking the table when entities have already bean processed.
To search a substring in any part of a word, you should start your search term with * (in your case: *005 ). Here you can find more information on searching.