I have a repeat control with a dominoview as datasource, which shows main documents.
To each entry in the repeat the user can make comments, which are saved with reference to the doc/entry. When the user saved a comment, I use the universalID of the doc as reference. I get this unID from a column value of the underlying dominoview.
We are struggling with changes in the underlying view (new docs are created, deleted from other users). The xpage is - of course - still showing the situation of the page load, but when you do sth in the repeat (add comments), the rowindex is referencing to the backend view, not to the shown data in the xpage.
Maybe an example helps to make it clear:
User A opens the xpage, reads it (...?), then decides to make a comment to entry/doc No 3. Meanwhile User B has created another main doc (so that in the backend view, the position of the entry for user A has moved to row 4. Now when user A saves his comment, it is referenced to the former row 2 document.
Is there a way to prevent this lookup?
thx for any help, Uwe
Don't use the index.
Use underlying repeat row's document instead.
Define a variable in repeat e.g. var="row" and get the document with row.getDocument().
This way you can be sure that the correct document gets changed.
<xp:repeat
id="repeat1"
rows="30"
value="#{view1}"
var="row">
...
<xp:button
value="change document"
id="button1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
var doc = row.getDocument();
doc.replaceItemValue("comment", "my comment");
doc.save();
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:repeat>
Related
UPDATED at bottom...
I have a custom control that contains an input field with typeAhead enabled:
<xp:inputText id="UTAN1" value="#{document1.UTAN}"
maxlength="5" styleClass="dbListFieldData" style="width:60px;font-size:13px;">
<xp:typeAhead mode="full" minChars="2">
<xp:this.valueList><![CDATA[#{javascript:var key = getComponent("UTAN1").getValue();
var path = new Array("","utans.nsf")
#Unique(#DbLookup(path,"(UTAN Lookup)",key,1,"[PARTIALMATCH]"));}]]></xp:this.valueList>
</xp:typeAhead>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="utanPanel1">
<xp:this.action>
<!-- DO SOME STUFF -->
</xp:this.action>
</xp:eventHandler>
</xp:inputText>
If I use the control inline on an xpage, typeAhead works fine.
However, if I insert the control in a dialog and call it to open:
<xp:link escape="true" id="link3" styleClass="dbListFieldData" >
<xp:eventHandler event="onclick" submit="false" id="eventHandler3">
<xp:this.script><![CDATA[XSP.openDialog('#{id:miniDialogUTAN1}');]]></xp:this.script>
</xp:eventHandler>
<xp:image id="image2" url="/edit2.png" style="height:16px;width:16px;" alt="Edit UTAN"></xp:image>
</xp:link>
The typeAhead seems to be partly crippled.
If the field is already empty, suggestions comes up fine.
If the field has an existing value, backspacing only shows the existing value as a suggestion.
Overwriting the value entirely gives no suggestions at all.
The only thing that will get the typeAhead working is to change the value and hit Enter. Basically, trigger an onChange. After that, ALL the typeAhead fields start working.
Any ideas on how to correct this behavior? FYI, I'm an xpages noob, so please go easy on me.
UPDATE 6/29/2021:
I'm still desperately in need of help with this. I've been playing around with Firebug and found something interesting.
In type-aheads on a normal Xpage form (where type-ahead works), entering each character calls a POST every time. However, when the type-ahead is in a dialog, typing in characters calls GETs. If I hit Enter or tab out of the field (triggering onChange), I get a single POST, and then clicking back into the field and typing, it starts using GETs again and it pulls valid suggestions as long as I don't backspace and type something different. Then the suggestions go away. This would be expected since GETs are cached and POSTs are not.
So what's going on with type-aheads in dialogs that makes them use GET, and how to I force it to use POST on every key press?
To people of the future...
After weeks of fretting over this and finally giving up I stumbled upon the solution by accident.
My dialog opens in read mode. I have both an Edit button and a Cancel button at top and bottom that were originally hard coded in both spots of the dialog custom control. Later I went to clean some stuff up and decided to create a single custom control for both sets of buttons. Once I did that, suddenly the type-aheads worked!
It turns out that when I copied and pasted the XML from the (supposedly) duplicate button panels to the new custom control, I had copied from the bottom button panel (which I rarely used while testing).
When I compared the XML for the top and bottom Edit Buttons, I found that the top one had the following attributes in the onClick:
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
while the bottom one had:
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="dialogOuterPanel1">
So, the full refresh broke my type-aheads and a partial refresh fixed them.
I have a repeat control with links to various XPages. I have validations set at the individual field level. I'm trying to find a way to disable all validations if a user navigates to a previous link (page). One idea I came across was using a phase listener. I tried passing a repeatIndex parameter to the phase listener to determine whether or not to disable validations (if repeatIndex < currentPageIndex then disable validations). However, it does not appear that the repeatIndex is being passed when the link is clicked:
<xp:repeat
id="Repeat"
indexVar="repeatIndex"
rows="30"
var="repeatData">
<xp:this.value><![CDATA[#{javascript:["Link 1", "Link 2"];}]]></xp:this.value>
<xp:link
escape="true"
text="#{javascript:repeatData}"
id="Link">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
</xp:eventHandler>
<xp:this.parameters>
<xp:parameter
name="repeatIndex">
<xp:this.value><![CDATA[#{javascript:repeatIndex;}]]></xp:this.value>
</xp:parameter>
</xp:this.parameters>
</xp:link>
</xp:repeat>
Is it possible to pass the repeatIndex to the phase listener somehow? Is there a better way to go about this? Thanks for any tips.
As far as the server-side is concerned, standard repeat controls only contain a single set of components. There is no index available outside the repeat, a row is set up and destroyed as it is iterated.
If your check for whether or not validation should be enabled depends on something available for the row, you can compute the disableValidators or immediate properties on the link's eventHandler. But bear in mind the calculation needs to happen server-side and pass the result to the browser when the page is rendered, so you won't be able to take into account any changes made since that part of the page was last passed to the browser.
If you want to access the repeat from outside, you can set repeatControls="true", which basically reproduces a set of components for each element of the repeat when the page's component tree (server-side map of the page) is loaded. You can then set the id property as "Link#{repeatData}", so you get Link0, Link1 etc. But because the sets of components are hard-coded, you won't be able to use pagers to change what data each row is bound to.
I have an application with one XPage. It has these custom controls(cc):
ccHeader
ccMenu
ccContent
ccFooter
Custom control ccContent has a combobox, with list of Views in sessionScope and dynamic view panel from extension library for XPages. This combobox has an event OnChange defined to partial update dynamic view.
What do I need?: Combobox with view list will be deleted and after that I need to assign this partial update function to five links, which are located on ccMenu custom control. So, i click on link in ccMenu, it returns some view name, assigns it to dynamic view and makes partial update.
How to get id of this dynamic view in ccMenu to call partial update?
Assuming what you mean is that you want to have a clean way to let the buttons know which area to partial-refresh when changed:
You could add a property to the ccMenu control along the lines of "viewRefreshId" and pass in the ID of the area to refresh, so you'd end up with a button like this:
<xp:button id="viewChanger1" value="View 1">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="${compositeData.viewRefreshId}">
<xp:this.action><![CDATA[#{javascript: viewScope.selectedView = 'View 1' }]]></xp:this.action>
</xp:eventHandler>
</xp:button>
Now, there's a question of whether you should try to pass in an ID from something contained within another CC from the main XPage, and I try to avoid that - it would PROBABLY work, but it's a bit messy. I tend to architect similar things so that the part to be refreshed is directly on the XPage (which is to say, I don't use "content" custom controls), so I end up with something like this:
<xc:viewSelector viewRefreshId="dynamicViewContainer"/>
<xp:div id="dynamicViewContainer">
<xe:dynamicView>
<xe:this.data>
<xp:dominoView var="view1" viewName="#{viewScope.selectedView}"/>
</xe:this.data>
</xe:dynamicView>
</xp:div>
The extra container div comes from experience that I had a while ago where refreshing the dynamic view directly caused rendering problems, but I don't know if that's still the case (or if I had run into some other problem).
I'm setting value of input field on click event of the check box. The editable field is used to validate group of check boxes. This code works in one xpage. When I tried to replicate this code in other xpage, it is not working.
Here is a working code:
<xp:checkBox
text="pH"
id="checkBox1"
value="#{document1.PH}"
checkedValue="pH">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="partial"
refreshId="routineSectionInput1"
execMode="partial">
<xp:this.action>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var
checkBox1:com.ibm.xsp.component.xp.XspInputCheckbox = getComponent("checkBox1");
var routineSectionInput1:com.ibm.xsp.component.xp.XspInputText = getComponent("routineSectionInput1");
if (checkBox1.getValue()=='pH'){
routineSectionInput1.setValue('Selected');
} else {
routineSectionInput1.setValue('');
}}]]></xp:this.script>
</xp:executeScript>
</xp:this.action>
</xp:eventHandler>
</xp:checkBox>
I used same field names and same code on another xpage and it is not working. What I'm doing wrong?
Best regards
When you work with component logic where binding is involved, don't go after the component, go after the data that defines their value. So your code would rather look like this:
<xp:checkBox text="pH" id="checkBox1"
value="#{document1.PH}" checkedValue="pH">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="partial"
refreshId="routineSectionInput1"
execMode="partial">
<xp:this.action>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var chkValue = document1.getItemValueString("PH");
viewScope.routineSection = (chkValue=="pH") ? "Selected" : "";
}]]></xp:this.script>
</xp:executeScript>
</xp:this.action>
</xp:eventHandler>
</xp:checkBox>
<xp:text id="routineSectionInput1" value="#{viewScope.routineSection}"></xp:text>
Hope that helps
If there are validation errors or components have data that is of the wrong data type (e.g. text that cannot be parsed as a number in a component bound to a Number field, so conversion errors), any SSJS will fail.
I'd recommend adding a print statement at the start of the SSJS to check whether it's firing. (If you're more confident with XPages, use a PhaseListener to check the correct phase is being triggered).
Also, it's worth adding an Display Errors control to catch any validation errors caught during the partial refresh, ensuring it's within the refresh area (otherwise the errors will not be displayed in the browser).
"Process data without validation" option may be of use here, it you want to skip validation. Note that conversion errors will still prevent SSJS running.
As Stephan says, use the datasource rather than the component, if possible. The datasource will have been updated before the SSJS fires.
Removed the checkboxes, compacted the database with -c and added back those checkboxes with the same code. It is working now.
I am taking an existing Lotus Notes database and converting to Xpages. There is one of those tables containing 3 multi-value fields, with New Line as the seperator and the "Add New", "Modify" and "Delete" buttons controlling how the data is entered and removed. The customer would like the XPage to look as similar to the Notes GUI as possible, and I was thinking I would use the dijit dialog box to do the add new line and figure out the delete and modify. But from what I can tell, the dialog box can only be used on client-side and the data input into the dialog box can't be brought down onto the Xpage. Is this true? I was thinking I would use an editable field within a repeat, but I also couldn't that working properly.
Basically, it the solution has to show the multi-value fields for past documents and also be able to allow users to edit those older document...plus work similar/exactly the way as in the past when creating new docs.
Thanks in advance for any help I can get on this as it seems a ton easier than I am probably making it out to be.
I just wanted to update after the solution below, which appears to be an excellent way to solve this problem. However, as an admitted XPages novice, I am really struggling with the application of this concept. This is what I have, and it obviously isn't working.
Logically, this sounds like a great solution. However, I am no xpages expert and I simply can't get this working properly even to get started. Anything at all that would make this easier for me to even get started would be a big help. I'm not one to usually look for "the answer"...I'm just having difficulty getting a handle on this Multi-value field table issue. Thanks again in advance...here's what I wrote that is coming up with a 500 error. "A" is the multi-value field name.
<xp:table>
<xp:tr>
<xp:td>
<xp:repeat id="repeat1" rows="30" var="rowdata">
<xp:this.value><![CDATA[#{javascript:document1.getItemValue("A")}]]></xp:this.value>
<xp:tr id="valueRow">
<xp:td>
<xp:text
value="#{javascript: return rowdata[i]}" />
</xp:td>
<xp:eventHandler event="onclick" submit="false"
refreshMode="partial" execMode="partial" execId="valueRow"
immediate="true">
<xp:this.action>
<![CDATA[#{javascript:document1.getItemValue("A")}]]>
</xp:this.action>
</xp:eventHandler>
</xp:tr>
</xp:repeat>
</xp:td>
</xp:tr>
</xp:table>
I would say do the following
Create a repeat control which will extract the data from the multi value fields and print them read only. The repeat control will generate a tr structure with a event handler bound to it on the onclick event. something like this:
2 In the onclick event change the style of the tr clientside (using dojo) so people know they selected that row and set the id / identifier of that row in a scoped var
3 Above the repeat control add controls like add, remove, update. The add and update will open a dialog box and will read the data from the selected row ( or none if its a add action). The delete control will remove the data from the multiline value fields, save the document and refres the repeat control.
This should work.