Automatically open document when only one document is listed in repeat control - xpages

I have a repeat control for a domino view which displays the results from a search field.
As you type more characters into the search field the number of items in the list is reduced. If/When the the list only contains a single item I would like to open item automatically, without having to click the link.
Any ideas are appreciated.
Edit: after some very interesting responses, here are some screenshots
I have 3 elements on the page, a searchbar, a repeat control and a form:
When I start typing in the search bar, the repeat is refreshed with every keystroke:
the list is reduced, typing the next character ...
again the list is reduced, only 2 left, typing again....
Only one left, now it would be time to open the document in the form ..... without clicking the link.
I've tried several events on the page, but it seems that I could not find the one that will allow me to "select" the document and display the data in the form.
It seems that it's not as simple as I thought

Since you want to open the link automatically I don't know if I would try to base it on the getRowCount() of the repeat itself. You don't want to even get that far right? you just want to go to the single document.
I would put a function in beforePageLoad event maybe. Not totally sure which event but I'd try that first. Use SSJS and do a lookup that would basically return a collection of what the repeat would show. If the collection count = 1 then get your destination from that entry and do your redirection from there.
That what I would try at least. Interesting scenario!

Now that I see the screenshots this might be easier then you think and I have already implemented something similar on an internal application that I have built. It does rely on the fact that each entry in the list is 100% unique.
First of all you will need to bind the search field to a scoped variable and the onchange/onkeypress event will need to perform a partial refresh of a panel that contains both the list and the document portion of the page.
For the list the link on each item should set the value of the same scoped variable used in the search box and clicking the link should be set to run a partial refresh of the document area.
For the document area you will need two panels, the first panel will only display if there is no matching document and the second panel will only display if there is a matching document, you can do this in the rendered section by writing some ssjs that grabs a handle to the db/view and does a dblookup and returns either true or false if the document exists depending on panel your dealing with.
With this setup, when somebody clicks a link or fills out the searchbox the scoped variable will contain a value, the document panels will then check to see if this is a unique value in the view in the db and update themselves to either display the 'no document' panel or the 'document' panel accordingly.

You could add a evaluation script to the entry of your repeat control which checks the size of your repeat control using the method getRowCount() from the component. If this is 1 you could execute a context.redirectToPage("yourpage.xsp?id=yourid",true) this forces the current page to send a redirect request back to the browser and therefore redirects you to the correct page.
All you need to know is which xpage you need to open and which parameters you should use. But these could be retrieved from the content you are iterating over.

Related

How to create a NotesRichtext item that is computed for display?

I know this is a common problem, and I tried a few solutions already, but the problem I have right now with my current code is that even though the attachments show in the computed for display field, I get the error "Note Item not Found" when I try to open them.
The form is built with two fields, in a programmable table that displays the editable one or the computed for display one.
The trick I found with Google's help was to delete the computed for display item in the queryopen event, so Notes regenerates the cfd item when opening the document. Visually, this works, as I see the text and attachments, but the attachments can't be opened.
Here is the code that removes the item in the QueryOpen of the form:
...
Set item = doc.GetFirstItem("dspDescription")
If Not item Is Nothing Then Call item.Remove()
...
Has anyone successfully achieved that functionality? Is there another way of doing this? I already tried with subforms, and because of the way the application is built, I need to be able to switch from editable to read only on the flick of a radio button, so subforms are out of the question as they can't be displayed dynamically.
Why don't you simple put the richtext item in a controlled access section and make that section editable / not editable with a computed for display formula. Select "always expand" and hide the section title, so that nobody can collapse it, et voila.
Regarding your comment: With this properties:
for this section in designer:
You get this result:
You see: No twisty, no "visible" section

Cognos 10 Report Studio: On Page Prompts & Performance

I have a report page which displays a crosstab. This is filtered by 5 paramaters. These paramaters are submitted by the user through on page checkbox prompts.
The requirement is to return the data with all values in all paramaters selected on the first run. If I leave default selections blank this behaviour is achieved but all the checkboxes are unchecked which gives misleading feedback to the user.
As an alternative I've manually specified all the values in default selections. However, this has a performance impact.
Does anyone have any alternative suggestions?
I've been looking for a way to specifically link a reprompt button to a value list so only those paramaters are resubmitted (rather than the whole page) but haven't found anything yet.
Thanks in advance - even if the answer is 'no and this is a bad way to go about it'!
One option is to use JavaScript to check all of the checkboxes after the page is rendered with no filtering applied. To do this all filters have to be set to optional. The page is rendered with all data and unchecked checkboxes. The JavaScript fires and checks all checkboxes so that the state of the prompts matches the state of the data. This happens so fast the user likely won't know the boxes weren't checked initially. A reprompt button will, when clicked, enforce whatever choices the user makes after that.
Since version 10.2, Cognos has provided a fairly simple JavaScript API to allow for render-time manipulation of prompt controls. Hopefully, you are working with 10.2 or later otherwise the code provided will not work. Here is a bit of JavaScript code that will loop through all prompts and select all values within them:
var report = cognos.Report.getReport("_THIS_");
var prompts = report.prompt.getControls();
if (typeof firstrun == "undefined") {
var values;
for (var i=0;i<prompts.length;i++) {
values = prompts[i].getValues(true);
prompts[i].addValues(values);
}
var firstrun = false;
}
Notes:
All value prompts behave the same way regarding the 10.2+ JavaScript Prompt API. It doesn't matter whether you choose a drop-down, list, checkbox or radio button interface. The way we code for all of these variations is the same. The provided code would work just as well with a list as it would with checkboxes.
Make sure that you wrap your code in script tags and that the HTML Item object you place on your page to hold the code appears below all prompt controls. If it is placed elsewhere it will not be able to find the prompt controls as they will not have been rendered when the code executes.
The code assumes that the only prompts on the page are the checkboxes you want checked. If there are other prompts on the page then you will have to target individual prompts using the getControlByName() function provided in the API rather than looping through all prompts. More information on the Cognos JavaScript Prompt API can be found here.
The key bits of code here are the getValues() and addValues() Cognos JavaScript Prompt API functions. getValues(true) returns a JSON-formatted object representing all values, selected or not, from a value prompt. addValues(values) takes a JSON-formatted object representing the values to be selected and selects them. Thus, it's a matter of grabbing all values and then passing them in to be selected.
The reason for the if block is that we only want this code to run once at first page render. When the user first runs the report we want all checkboxes checked but after that we want the checkboxes to retain state. If we didn't use the if block the user's choices would be overwritten after a reprompt. For more information on this technique check out this tutorial on my blog: JavaScript: Running Code Only Once.
Addendum
If you don't want any filters to be applied when all boxes are checked in a section even after subsequent reprompts you can do so by tweaking your filter.
Assume that we are checking against a model based item [Item1]. We have a current filter of: [Item1] in ?parameter1?. We also have four checkboxes with values of 'Choice1','Choice2','Choice3', and 'Choice4'.
The following modified filter will only apply the checkboxes to the filter when all four aren't checked:
(
'Choice1' in ?parameter1?
AND
'Choice2' in ?parameter1?
AND
'Choice3' in ?parameter1?
AND
'Choice4' in ?parameter1?
)
OR
[Item1] in ?parameter1?
If all four checkboxes are checked then the first part of the OR is satisfied and all rows will be returned. It should be fast too because most languages, including iterations of SQL, will not test the second component of an OR if the first component is satisfied.

xpages embedded view or view panel

I know it is a very simple question , but I'm trying to see the difference between a view panel ( that I drag from the Container Controls ) and an embedded view.
How can I add an embedded view on my xpages?
Or the 2 items are one and the same.
The reason why I'm asking this question: I have a view panel on my xpage ( I thought it is like an embedded view in clasic lotus notes programming ) where I have listing some docs. The first column is categorized based on the UNID document.
I noticed if I compose again another document, this view contains all the previous docs., and all the UNID categorized. The view panel isn't empty.
In lotus notes programming:
If I have a main form and a computed text field with #Text(#DocumentUniqueId) and some button for composing another form ( of course, when clicking the button I saved the main form to obtain the UNID ), and this form has the same text field name as the previous - I'm passing the UNID to this second form. If the main form contains an embedded view listing all documents saved from the second form I will use the first column categorized and hidden with the name of the field from the second form ( which will contain the UNID ). If I save and close the 1st main, and then I'll compose another main form, the embedded view is not listing the previous documents already saved.
Well, this view is already created.
I did drag and drop this view in myxpage. I have a button inside myxpage that shows a dialog. Here a datasource is declared, the dialog containing some fields. In the main xpage ( where is defined another datasource ) there is a computed field which takes the UNID of the document. Before I click the dialog I save the first datasource, to pass the value UNID to other field inside the dialog.
I save the datasource from the dialog & close the dialog, and then the view panel ( which is the view from the lotus notes classic presented above ) lists the doc. If I close the main xpage ( save it if is a new one ) and then open another main document, the view isn't empty, it contains the previous document lists. ( I tried also to hide it, if the xspDoc is new. But when I try adding other docs. from the dialog, the view panel lists also the previous documents from the previous doc., even if the UNIDs are distinct )
Thanks in advance.
To explain this best, it's good to consider what a view and an embedded view in Notes Client is. A view determines the look and feel, like a View Panel and by default will show all documents found by the selection criteria. So in this case the documents available correspond to a dominoView datasource bound to the underlying view with no additional criteria defined.
An embedded view still uses the view to determine the look and feel, but will not display the first column (that's effectively a property of the embedded view "control" in Notes Client). In the View Panel you choose which columns display, so you would need to code that yourself on the View Panel, where you choose which columns to display. The embedded view also has a property to define the single category. But the View Panel and other repeating containers (like Data Table and repeat control) don't restrict the data available, that's done by the datasource - a dominoView or e.g. a ViewEntryCollection for anything other than the View Panel. So in that you set the filter.
However, a new document does not have a UNID, so it cannot restrict what is displayed. Instead, I think a good approach is to set the visibility so the View Panel is only displayed if it's not a new document. You can use loaded, if you fully reload the page after save, or else rendered.
First off, this is not a stupid question.
I am assuming you are using a self implemented parent response system and have a view sorted by the parent UNID. Under the data source of the view panel, find the the "filter by category name" option. there compute the UNID value, or category value you are searching for.
Steps:
insure that the background view is categorized (ascending order is best to insure that this works, though I doubt it is needed)
drag (my favourite is the dynamicViewPanel) a view control onto the xpage.
Under Properties/Data there is a place to calculate the value of the category to show. If you want an exact match, check the exact match check box.
If you mistype the category value or the value is not there, then no documents will be shown.
if you put in an empty value all documents are shown (at least in the tests that I can remember)
if documents are returned, the categorized column is automatically hidden.
EDIT
If you are reading the value from a field, you can use the code:
xspDoc.getItemValueString("fld");
If you are searching based on the UNID, again, hide the viewPanel if the document is new. If the value is not yet set, also hide the panel.
If you have two custom controls, even if a custom control is embedded in the second, you cannot easily have one custom control access the values of the datasource in another. I am sure there are ways to trick this into working, but in this case, use a viewScope variable to access the values and possibly an onLoad, onChange or onSave event to update the viewScope variable. Make sure to verify that the result is not null or empty by either printing it out to the server log or another field.
Final Edit after question edit/expansion
These are the steps that I would take to do what you described.
You have your parent document XPage. Insert all fields for this Xpage.
Drag a dynamicViewPanel onto the XPage. If parentDoc is New, then hide.(this could be a custom control in theory, but if you are having trouble, try it without for the sake of trouble shooting.
Set dynamicViewPanel datasource to ignoreReqeustParams.
Calculate the datasource and setting the "Filter by category name" filter. When computing this, for the sake of ease and troubleshooting, print this value out to the server, or other logging mechanism. You can delete it later.
Verify that the correct UNID/Value is being inserted into the document you create in the dialog.
If you are using a scoped variable to hold the filter value, be sure you are using viewScope and not appliationScope or sessionScope.
if you are using a custom control and standard parameters (not scopedVars), verify that the compositeData variable is being updated with a log or server print.
Consider setting Dialog Properties/AllProperties/basics/refreshOnShow to true
Play with the partial refresh option for the dialogOpen action, test a full vs partial refresh.
Remember to set the ignoreRequestParams for the document you are creating in the dialog to true
Consider making the new document data source created in the Dialog to request scope.
And of course consider and test all datasources being defined on the XPage on not some here, some there.
Verify that you are taking the value of the UNID from the main document and not the new dialog document by mistake!
Those are all of the tips I can think of right now, pretty much in the order I'd try them in. If that does not help, then I suspect there is a piece of this puzzle that you are not including in the question. Remember, try to keep things as simple as you can. You can over think things, make things harder than they need be.

View data being cached/failing to refresh

I have a tabbed panel containing different sections of a form. In one section, users are given the ability to add a child document to the currently open document. In a second section, they are given a listbox, where the options are dynamically generated (via #DbLookup) by looking at a view of all the child documents, filtered by the current document's ID. This functionality all works correctly, however, there is a problem with the dynamic listbox options.
When a user adds a new child document, then switches to the next tab, the listbox is not updated with this new document. If they save/re-edit the main document or refresh the page, it makes no different, the user must load another XPage before going back to the original in order for the listbox to update. I have tried to resolve this by doing full updates of the page, using session.evaluate and "NoCache" in the #DBLookup call, or calling database.getView("My view").refresh(), but without luck.
There is also a similar problem where I have a repeat control which uses a view of child documents (again filtered by main document ID) as a datasource. When a user adds a child document using a button, it partially refreshes the repeat - but doesn't show the new child document until the page is refreshed again (or you leave the page and return).
Is there something crucial I am missing with regards to the JSF lifecycle/the way that view data is cached?
As first measure I would add another formula item to the listbox which simply returns the current time (#Now() should work). That way you can check if the listbox options are refreshed on the update in the first place.
If the options are refreshed fine it's indeed clear that the #DbLookup does some caching, although I'm not aware of any default caching logic.
At least for a test I would change the code to use a NotesView object instead of the #DbLookup, something like this:
var nview = database.getView("someview");
var nc = nview.getAllEntriesByKey(currentDocument.getDocument().getUniversalID(), true);
var a = [];
var ve = nc.getFirstEntry();
while (ve) {
a.push(ve.getColumnValues().elementAt(0)); // value of first column
ve = nc.getNextEntry(ve);
}
return a;
(I wrote the code from memory, there may be syntax errors).
Since the code only works with view entries it should be equally fast than the #DbLookup. And you could even do a nview.refresh() if needed.

The buttons in a repeat don't hide/show after refreshing the panel the repeat is in?

I have a repeat that has buttons embedded in it. The repeat is in a panel. When the user clicks a button the button should hide/show (I partial refresh the panel). The repeat is tied to a Domino view and I see the other values that I from that view get updated in the repeat, so, it does not seem like a view index issue (I refresh the view index in my code.)
If I use context.reloadPage() in my button onclick code then the buttons will hide/show like they should, but, that seems like I am using a sledge hammer! Any suggestions on how to get the buttons to recompute the visible property when the panel that holds the repeat is rendered? Another strange thing is that the visible property gets computed three times whenever I refresh the panel that holds the repeat.
thanks, Howard
I think your looking for
getComponent("<id>").setRendered(true / false);
Hi For Repeat control's entry is used to make our head hard. Because handling the entry by SSJS, we can get the value and set the value. But rendering part, id of the repeating component are same for all. So if we try to give reder as false. It hides all of our repeating component.
Try to use the following., [Put this in button onclick, and see the value of below]
var entryValue= getComponent("repeat1").getChildren().get(0).getValue()
getComponent("inputText1").setValue(entryValue)
But in client side we can easily handle. Because the id of the DOM object is unique for all repeating component.
var id1="view:_id1:repeat2:"+'2'+":button1"
document.getElementById(id1).style.display="none"
This will hide the third entry of your repeat control component.
Please see the post, You may get better idea
Found a solution. My original solution was getting values from the repeat rows (using the collection object, which was a viewentrycollection and using getColumnValues) to compute the rendered property for the buttons.
Instead, I created a viewScope variable (a Vector) that holds the state of the buttons (which set of buttons to show). This gets populated in the beforePageLoad event of the page.
The button onclick code updates this viewScope variable after performing its processing. All works very nice now. I guess it was something in the JSF lifecycle that kept the buttons from being properly updated. Using the viewScope variable works fine.
With addition to what Ramkumar said, you can use the index variable in the repeat control to identify each and every occurrences inside the repeat control. You will get more idea, if you inspect with element from firefox[You might need firebug]. Usually the field mentioned inside a repeat control itself can be considered as an array

Resources