Xpage dynamic Id for data update or validation(CSJS) - xpages

Before describing the problem, I would like to add that I have looked for this problem on google and have found many solutions but none related to XPAGES. Since, Xpage have a unique method to generate the field id I am facing this problem. I have also posted the same question here on IBM forum and awaiting the reply there(http://www-10.lotus.com/ldd/ndseforum.nsf/xpTopicThread.xsp?documentId=EDEBB14BDF2E804F85257BE8001E4F76):
Problem:
I am trying to pass dynamic id to the default function getElementById with no success. To explain it clearly, I have a front end validation for specific fields. This fields are stored n database. So, I have a for loop running for all the fields. The problem here is that XPages generates the Id dynamically and hence for the same form if there is a hierarchical tabbed panel then the Id also included the tabbed panel Id in it.
Here is the code view of the problem:
The standard method to retrieve the value(CSJS) is:
document.getElementById("#{id:inputText1}").value;
However, if I try to pass in a dynamic id. It doesn't work. I have tried "n" number of approaches I found on Google but none regarding this problem. One solution I tried here was:
var x = "inputText1";
document.getElementById("#{id:"+x+"}").value;
Any help would really be appreciated. Really eager to hear some good suggestion.

The "#{id:inputText1}" part is computed at the server before the page is served so it's too late to set the ID in client side JS.
To set the ID in SSJS you can do this:
document.getElementById("#{javascript:var x='inputText1'; getClientId(x)}").value;
With getClientId you can also build a CSJS array of IDs in in SSJS. Then you can loop that array in CSJS. You would build the array this way:
var strIDs = ${javascript:'["a","b","c"]'};

Related

Customize search results and facets in Liferay 7.1

this is my first question, thanks in advance.
I am trying to customize the liferay results portlet and facets, with custom results. I need to filter the results once the search is launched, and remove the results that do not have layoutId :
with->
layoutIds = journalContentSearchLocalService.getLayoutIds(groupId,false,articleIdResult);
I´m doing this in a jsp fragment, but i think that it´s not correct.
I have been searching and i think the correct way is to modify the java class with the action, for example with acction coomand hook, is this correct?
Please, can you explain me the correct way to modify this functionalities?
Regards!!
ok. it looks you want result of journalarticle having display page is set. in that case, you need to look for JournalarticleModelPreFiltercontributor component extension or journalarticlepostprocessor if you are using legacy search api. when article gets indexed layoutuuid field is also indexed for each article. that field will have value if display page is set for specific web content or article.
So, you can use any of the above mentioned way to add check that this field should not be empty as search term. which will filter your result in request itself. instead adding overhead on result as later filtering in jsp.

Adding Values using select2 which are not found in the database?

I am trying to search a way to add new categories in the present categories for my article using the select2 but as we know it only returns those which are already saved in the database.I want to do something so that those categories which are not there could get created automatically during the Runtime As figure shows no result found is displayed rather a new category should be created. Can anyone suggest a way to do it?

Retrieving column values in filtered xpages view

I have a view defined on an xpage. I also have several filters (based on the columns) that the user can select and combine to filter the results in the view. I generate a query string based on this that I construct in dominoView.search (doing a complete refresh). What I would like to do is get the results of the search so that I can then update some counts displayed elsewhere on the page. I'm having a hard time figuring out where I can perform this logic, though. I'm trying to use view.getAllEntries() and then iterating over the collection. Sometimes it seems like it works, but other times I seem to be getting the unfiltered view. Someone suggested I explicitly call view.FTSearch inside one of the events (beforePageLoad?) and immediately after do my getAllEntries call, saving the results in viewScope, but I get an "Error while browses Notes view" runtime error when I try to do that. Any pointers? TIA!
EDIT: After studying the xpages lifecycle a bit (which is still a little confusing), I think I can fine-tune my question. This is my first stackoverflow question, so I hope this is okay to do and productive....
As I described, I have a dominoView defined on my xpage. A repeat iterates over the rows of the view, displaying certain fields from the documents. If I define a query in the search property, then the repeat correctly displays the reduced set of documents rather than the complete set. (The query is computed in the search property via SSJS from some variables defined in the viewScope in a combobox's eventHandler.) However, if I try to access the current entries in the view inside of the repeat's rendered section (with SSJS) using myView.getAllEntries (where myView is what's defined as the "value" of the repeat), I am still getting all of the documents, even if a query has been done. It seems like at that point, the view variable has already had its search applied (since the repeat works), so why the differing results? Is there another way to access the view's rows? To complicate this further, this is just a simple experiment that might clarify the problem; as I indicated earlier, I don't actually want to access the view data within the repeat, I want to access it in the rendered or value sections of some comboboxes defined before the repeat in the xpage file.
I hope that makes more sense now....
EDIT #2: I forgot to add that if I manually call FTSearch (or FTSearchSorted) before calling myView.getAllEntries, then I think I can make this work. It just seems unnecessary to have to do that in addition to the view's built-in search.
From what I get you want to iterate over the entries in a view that before has been filtered, i.e. whose resulting entry collection is smaller than the the view itself.
What I don't get (yet) is what you want to do with the result, or what you're axpecting to get from the iteration over your filtered view (you're mentioning some counts to be displayed somewhere else).
Probably a good way is to use the view's .getAllEntriesByKey method which returns a NotesViewEntryCollection object which then can be used for your iteration.
Don't forget to recycle the resulting NotesViewEntry objects; reason for this has been explained several times here at stackoverflow.

ExtLib, iNotes List View: how can I access data selected in the view from the outside?

Using Firebug I found that the iNotes List View object has a function called "getSelectedData()" delivering something like an array of selected view entries (each one consisting of the item specific row data, like the "ext" element described here by Paul Withers). Thus, using one of List View's internal events (like "onContextMenu"), I can retrive selected data and put them somewhere else. Which is just great!
But, as I'm never content with what I have, now I'm looking for a way to address the List View's object from the outside (e.g. using a button) to access a selected data collection in a similar or even the same way. But no matter what I try, I can't seem to get to the proper object from outside of the List View itself. Using
dojo.byId("#{id:listView1}")
is giving me an object but without any of those specific methods that I need. Neither Google, nor openNtf or the ExtLib book itself has any info on that.
Any hint?
Greets,
Lothar
I guess I solved it. I've been close yesterday, but using dojo.byId instead of dijit.byId prevented it from working:
var grid = dijit.byId("#{id:listView1}");
var sel = grid.getSelectedData();
Result is a named array of row data where each row entry contains all the relevant view entry data for that row.
Works like a charm!
- Lothar

Dynamic field binding inside a repeat control

I have a strange thing, I'm using dynamic field binding in a custom control.
The field binding is created like this.
XPage (Datasource "document" is placed here)
Custom Control (String passed in)
(to get errors if there are any)
Repeat (CompositeData is passed to a bean that returns the strings for Rows,columns)
Repeat (repeat 1 variable used for Columns)
Custom Control (fieldname is passed in)
field binding is done like this
#{document[compositeData.fieldName]}
The problem is that when I save the XPage I get an error in the messages control
Document has been saved by another user - Save created a new document as a response to that modified document.
And all fields are cleared.
Any ideas how to debug this or is there something I'm missing?
The "Document has been saved by another user" error is only tip of the iceberg - there are some really strange problems with reapeats that repeats fields that are bound and repeatControls property is set to false. The decoding part of xpages lifecycle cannot handle it properly - the controls will be losing data. You should use repeatControls set to true as Martin suggests.
"Repeat control variable doesn't exists" is probably caused by the property that removes repeats set to true. You can solve this by either changing it to false or by adding additional data context that will keep repeated value.
And finally for this to have add/remove functionality You can use Dynamic Content Control and show(null) hack to rebuild the repeat content.
To manage this complexity better I would advise You to stop using document data source and start creating some managed beans.
If You will follow my suggestions I guarantee that You will get the functionality You are looking for as I have few apps that works great and have this kind of complex data editors in them.
I don't know if it'll help you, but I pass both the document datasource and the field name as parameters to a DynamicField control, and use it like this:
compositeData.dataSource[compositeData.fieldName]
The type of the datasource is com.ibm.xsp.model.DataSource, it's listed as dataInterface under Data Sources.
Do you have repeatControls="true" set for the repeat control?
It sounds like you've got the datasource defined multiple times on the XPage (plus custom controls). Either that or the save button has save="true" but the code saves the document back-end, or code in multiple places saves the same document. I've used the same method of passing the datasource down to the custom control, but that may just be because that was what I saw on a blog.

Resources