Can someone help me learn how to use the javascript connections code? - xpages

I am trying to access data from Connections. I need to use some of the javascript api code: https://greenhouse.lotus.com/sbt/SBTPlayground.nsf/JavaScriptSnippets.xsp#snippet=Social_Files_Get_My_Files
But I do not know how to build the app using xPages. I tried a new xPage and pasted the code into a script block but I get compile errors.
Can someone show me how to use the Javascript samples from the playground?

Paul's suggestion to use the openntf ticket tracking was brilliant! Here is the code that ultimately worked. Thank you again Paul!
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:dataView id="myFilesDataView" var="file" rows="110"
columnTitles="true" styleClass="filesDataView">
<xe:this.extraColumns>
<xe:viewExtraColumn columnTitle="Filetype">
</xe:viewExtraColumn>
<xe:viewExtraColumn columnTitle="Size">
</xe:viewExtraColumn>
</xe:this.extraColumns>
<xe:this.summaryColumn>
<xe:viewSummaryColumn columnTitle="Filename">
</xe:viewSummaryColumn>
</xe:this.summaryColumn>
<xp:this.value>
<![CDATA[#{javascript:
try{
var filesService = new com.ibm.sbt.services.client.connections.files.FileService( "connectionsSSO" );
// ps:100 is page size of 100 files
var myFiles = filesService.getMyFiles({ps:100});
viewScope.myFilesAvailable = true;
return myFiles;
}catch(exception){
println("getFiles value error: " + exception);
viewScope.myFilesAvailable = false;
return null;
}}]]>
</xp:this.value>
<xp:this.facets>
<xp:panel xp:key="noRows" id="emptyMyFilesPanel">
<xp:div styleClass="lotusWidgetBody">
<xp:text>
<xp:this.value>
<![CDATA[#{javascript:
return (viewScope.myFilesAvailable ? "No files found." : "Files unavailable.");
}]]>
</xp:this.value>
</xp:text>
</xp:div>
</xp:panel>
<xp:panel id="summaryPanel" xp:key="summary" style="white-space:nowrap;">
<xp:link escape="true" id="link7" target="_blank"
text="#{javascript:return file.getTitle();}" styleClass="dataViewLink">
<xp:this.value><![CDATA[#{javascript:return file.getContentUrl();}]]>
</xp:this.value>
</xp:link>
</xp:panel>
<xp:panel id="typePanel" xp:key="extra0"
style="width: 20%;white-space:nowrap;">
<xp:text>
<xp:this.value><![CDATA[#{javascript:return file.getType();}]]></xp:this.value>
</xp:text>
</xp:panel>
<xp:panel id="sizePanel" xp:key="extra1"
style="width: 15%;white-space:nowrap;">
<xp:text>
<xp:this.value><![CDATA[#{javascript:
var size = file.getSize();
var kilobyte = 1024;
var megabyte = kilobyte *1024;
if(size < kilobyte) {
return (size + " B");
}else if(size < megabyte) {
return (Math.round(size/kilobyte) + " KB");
}else {
return (Math.round(size/megabyte) + " MB");
}}]]>
</xp:this.value>
</xp:text>
</xp:panel>
</xp:this.facets>
</xe:dataView>
</xp:view>

Related

Access to data for JDBC query in ViewPanel on XPage via OpenNTF driver

We have an XPage which is using a named JDBC connection via the OpenNTF extension library.
This is successfully retrieving data and placing it inside a View Panel, I've selected to display a Check Box next to first field in the Row, and need to access the returned value for that field in that row (or an array for multiples of the selected rows).
So far have tried these methods:
var Docs2=getComponent("viewPanelDocs");
//var db2 = Docs2.getAttributes();
//var doc2Array=Docs2.getSelectedIds();
//var test = getComponent("something");
var p=Docs2.getParent()
var pp=something.getColumnValue("extName")
var Rows = Docs2.getChildCount().valueOf();
var doc2Array= new Array();
var SelectedDocs2 = new Array();
for(i=0; i < Rows; i++) {
// Works, no output: var Selected2Docs=Docs2.getAttributes();
// FAILS: var Selected2Docs=Docs2_xspGetRendererData();
// WORKS, no output: var Selected2Docs=Docs2._xspGetRendererData();
// WORKS, gets local ID of viewPanel: var Selected2Docs=Docs2.getId();
// Works: javax.faces.component.UIComponentBase$AttributesMap#0: var Selected2Docs=Docs2.getAttributes();
// FAILS, doesn't like string: var Selected2Docs=Docs2.getAttributes("ExternalUNCLink");
// WOrks, no output: var Selected2Docs=Docs2.getAttributes().get("ExternalUNCLink");
// Fails, something, something: var Selected2Docs=Docs2.getAttributes().values("ExternalUNCLink");
var Selected2Docs=Docs2.toString().valueOf();
doc2Array.push(Selected2Docs);
}
getComponent("Docs2").value=Rows + ": " + #Implode(doc2Array, ",");
//viewScope.put("Documents", #Implode(docArray, ","));
Any clues how to access the returned value of ExternalUNCLink?
Caveat: I'm not a Domino developer, so excuse me if some of the terminology is incorrect.
[EDIT]
We have a JDBC driver, which lives in the Packages -> Web Content -> WEB-INF -> jdbc folder with a test name and four criterea in an XML style format, thus:
<jdbc>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<url>jdbc:jtds:sqlserver://malbec/aps_dsql</url>
<user>user</user>
<password>pass</password>
</jdbc>
Then on the page we have an SQL query in the afterPageLoad event:
var TmpSql="select * from TABLE"
viewScope.put("SQLQuery", TmpSql );
getComponent("strSQLQuery").value=TmpSql;
After that, you put the viewScope variable "SQLQuery" into the value field for sqlQuery on a JDBCQuery view, using the connectionName variable of the name of the JDBC driver shown above. It returns the data, but we can't seem to access it.
[/EDIT]
[EDIT2]
(with apologies for the dogs breakfast ...)
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.afterPageLoad><![CDATA[#{javascript:var TmpSql="select A.extName,A.extUNC,A.extObjInstID,LEFT(A.extUNC,5) as Category, B.cltMailName From cdblink A inner join cdbClientMaster B on A.extobjinstid=B.objInstID where extobjectid=1 and extobjinstid in (1536,1871,632)"
viewScope.put("strSQLQuery", TmpSql);
getComponent("strSQLQuery").value=TmpSql;
getComponent('viewPanelDocs').getData().refresh();
}]]></xp:this.afterPageLoad>
<xc:testjdbcrowdataaccess></xc:testjdbcrowdataaccess>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
// --var vp=getComponent("viewPanelDocs");
// --
// --//var test=vp._xspGetRendererData().getParent();
// --//var test=vp._xspGetStateId().valueOf();
// --//var test= vp.getChildren().lastIndexOf();
// --var test= vp.getChildren().size();
// --var test=vp.getChildCount();
// --var test=vp._xspGetStateId().valueOf();
// --//var test=vp._xspGetReadOnlyObj().hashCode();
// --//var test=vp.getAttributes().get();
// --var test=vp.getFamily().valueOf();
// --var test=vp.getParent();
// --
// --getComponent("Test").value=test.toString();
//var database=mssql_test.jdbc;
//
//var viewPanel=getComponent("viewPanelDocs");// get the componet of viewPanel
//var docIDArray=viewPanel.getSelectedIds(); //get the array of document ids
//for(i=0; i < docIDArray.length; i++){
// var docId=docIDArray[i];
// var doc=database.getDocumentByID(docId);
// .. your code to deal with the selected document
// getComponent("Test").value=doc.toString();
//}
var test = getComponent("viewPanelDocs").value;
#ErrorMessage("ID: "+test);}]]></xp:this.action>
</xp:eventHandler></xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br><xp:table id="DEBUG" style="width:100%">
<xp:tr>
<xp:td>inputText2</xp:td>
<xp:td>
<xp:inputText id="inputText2" value="#{viewScope.searchDOCID}" style="width:100%">
<xp:eventHandler event="onfocus" submit="true" refreshMode="complete" id="eventHandler2">
<xp:this.action>
<![CDATA[#{javascript:
var viewPanel:com.ibm.xsp.component.xp.XspViewPanel = getComponent('viewPanel2');
var dominoView:com.ibm.xsp.model.domino.DominoViewData = viewPanel.getData();
var filterValue = getComponent('inputText2').getValue();
if (filterValue == 'NA') {
filterValue = '';}
viewScope.clear()
dominoView.setKeys(filterValue);}]]>
</xp:this.action>
</xp:eventHandler>
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>inputText3 (displayvar)</xp:td>
<xp:td>
<xp:inputText id="inputText3" value="#{viewScope.documentDOCID}" style="width:100%">
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>Test</xp:td>
<xp:td>
<xp:inputText id="Test" style="width:100%" value="#{viewScope.test}">
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>inputText1</xp:td>
<xp:td>
<xp:inputText id="inputText1" style="width:100%"></xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>inputText4</xp:td>
<xp:td>
<xp:inputText id="inputText4" style="width:100%"></xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>SQLQuery</xp:td>
<xp:td>
<xp:inputText id="strSQLQuery" style="width:100%" defaultValue="strSQLQuery">
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>SQLQueryCat</xp:td>
<xp:td>
<xp:inputText id="strSQLQueryCat" style="width:100%">
</xp:inputText></xp:td>
</xp:tr>
<xp:tr>
<xp:td>Doc1</xp:td>
<xp:td>
<xp:inputText id="Docs" style="width:100%">
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="width:15%">Doc2</xp:td>
<xp:td>
<xp:inputText id="Docs2" style="width:100%"></xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>scopeVariable.Documents</xp:td>
<xp:td>
<xp:inputText id="svDocuments" style="width:100%"></xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>scopeVariable.Recipients</xp:td>
<xp:td>
<xp:inputText id="svRecipients" style="width:100%"></xp:inputText>
</xp:td>
</xp:tr>
</xp:table></xp:view>
[/EDIT2]
When you have a ViewPanel that is linked to a Notes View, the selected documents can be found using the getSelectedIds() method on the viewPanel object. You then can loop through the values to get the documents and their full URLs:
var viewPanel=getComponent("viewPanel1");get the componet of viewPanel
var docIDArray=viewPanel.getSelectedIds(); get the array of document ids
for(i=0; i < docIDArray.length; i++){
var docId=docIDArray[i];
var doc=database.getDocumentByID(docId);
// .. your code to deal with the selected document
}
Might work for your JDBC use case too.
It looks like the answer to my question is a three part one - firstly we use the Domino side of things to get the boxes which are checked, thus:
var Docs2=getComponent("viewPanelDocs");
var APKArray=Docs2.getSelectedIds();
//getComponent("svDocuments").value=#Implode(APKArray,",");
Then we use the OpenNTF "Model" Java code to get an array of the documents inside the SQL selection:
// get the Array from the SQL selection
var namesArray=[];
var PathArray=[];
var locationArray = [];
var FinalNames=[];
var FinalLocations=[];
var Model:com.ibm.xsp.component.xp.XspViewColumn = getComponent("xxxviewColumn3");
var modelData=Model.getDataModel();
var Rows = Model.getChildCount().valueOf();
namesArray.push(Rows);
for(i=0; i < modelData.getRowCount(); i++) {
modelData.setRowIndex(i);
var x=modelData.getRowIndex();
var y=modelData.getRowData().getColumnValue("ExternalName").toString();
var z=modelData.getRowData().getColumnValue("ExternalUNCLink").toString();
namesArray.push(x);
locationArray.push(y);
PathArray.push(z);
}
//getComponent("Docs2").value=namesArray
Then we use the index from the Domino side, to reference the names on the SQL side, and put that into a new array:
// put the selected docs in the selected array
for(i=0; i < APKArray.length; i++) {
var z = APKArray[i].valueOf();
FinalNames.push(PathArray[z].valueOf() + "\\" + locationArray[z].valueOf())
//FinalLocations.push(locationArray[z].valueOf())
}
getComponent("Docs2").value=#Implode(FinalNames,",");
The Path + Names ends up in the Docs2 edit box. It's pretty messy, but works (I hope this doesn't ruin my caveat!!)

Why does this code write out TWO documents?

Have a database where I only want one document for a certain category. So when the user goes to this Xpage I want to test to see if there is already a doc, and if so grab that one, if not, then create and save one.
I wrote some SSJS in the datasource to do this, but the first time I run it it creates two docs. I put a print in the code and it executes this part twice. Why does it do that?
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.beforePageLoad><![CDATA[#{javascript:sessionScope.selectedPage = "page001"}]]></xp:this.beforePageLoad>
<xp:this.resources>
<xp:script src="/xpValidationDocument.jss" clientSide="false" />
<xp:styleSheet href="/custom.css" />
</xp:this.resources>
<xp:this.data>
<xp:dominoDocument var="document1" action="editDocument">
<xp:this.documentId><![CDATA[#{javascript:sessionScope.selectedPage = "page001";
var v:NotesView = database.getView(sessionScope.selectedPage)
var doc:NotesDocuent = v.getFirstDocument()
if (doc == null)
{doc = database.createDocument();
doc.appendItemValue("form","document");
doc.appendItemValue("key",sessionScope.selectedPage);
doc.appendItemValue("crtUsr",session.getCommonUserName());
doc.appendItemValue("crtDte",session.evaluate('#Today'))
doc.save();
print ("here");
return doc.getUniversalID();}
else
{
print ("here2");
return doc.getUniversalID()}}]]></xp:this.documentId>
</xp:dominoDocument>
</xp:this.data>
<xp:panel style="width:900.00px" id="pnlForm">
<xe:widgetContainer id="widgetContainerHeader"
style="width:100%">
<xp:panel id="plContainer">
<xe:formTable id="frLocationMaster"
disableErrorSummary="true" disableRowError="true"
style="lotusForm2" styleClass="scllotusui30dojo">
<xp:this.facets />
<xe:formRow id="formRow5" labelPosition="none"
style="padding-bottom:10.0px">
<xp:table style="width:99%" border="0"
cellpadding="0" role="presentation" cellspacing="0"
id="table2">
<xp:tr>
<xp:td
style="width:80.00px;min-width:120px">
<xp:label id="label2" for="formRow1"
value="Notes" />
</xp:td>
<xp:td style="width:px">
<xp:inputRichText
id="inputRichText1" value="#{document1.Body}">
<xp:this.attrs>
<xp:attr name="toolbar">
<xp:this.value><![CDATA[
[
["Format", "Font", "FontSize"],
["Bold", "Italic", "Underline", "Strike", "-", "TextColor", "BGColor", "-", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock", "NumberedList", "-", "BulletedList"],
["Indent", "Outdent"],
["Subscript", "Superscript"],
["RemoveFormat", "-", "MenuPaste", "-", "Undo", "Redo", "Find", "LotusSpellChecker", "-", "Image", "Table", "Link", "Flash", "-", "PageBreak", "HorizontalRule", "SpecialChar", "Blockquote", "Smiley", "ShowBlocks"],
["Maximize", "Source"]
]
]]></xp:this.value>
</xp:attr>
</xp:this.attrs>
<xp:this.dojoAttributes>
<xp:dojoAttribute
name="enterMode" value="2" />
</xp:this.dojoAttributes>
</xp:inputRichText>
</xp:td>
</xp:tr>
</xp:table>
</xe:formRow>
</xe:formTable>
</xp:panel>
</xe:widgetContainer>
</xp:panel>
</xp:view>
After you have created the document det the UNID or the NoteID in a viewScope variable and at the top of you code check if the scope variable is null if not use that one.
the reason for this is that the datasource is recalculated several times while loading the page.
So the code would be something like this
sessionScope.selectedPage = "page001";
if(viewScope.thisUNID==null){
var v:NotesView = database.getView(sessionScope.selectedPage)
var doc:NotesDocuent = v.getFirstDocument()
if (doc == null)
{doc = database.createDocument();
doc.appendItemValue("form","document");
doc.appendItemValue("key",sessionScope.selectedPage);
doc.appendItemValue("crtUsr",session.getCommonUserName());
doc.appendItemValue("crtDte",session.evaluate('#Today'))
doc.save();
print ("here");
viewScope.thisUNID=doc.getUniversalID()
return viewScope.thisUNID;}
else
{
print ("here2");
viewScope.thisUNID=doc.getUniversalID()
return viewScope.thisUNID}
}else{
return viewScope.ThisUNID
}
I see a couple of problems on a quick review.
As Per says, documentId may need to be page load binding, not runtime - the datasource had to be loaded in before render response, and runtime binding may not run early enough.
But the bigger problem is your documentId code is not going to have any effect, because you are not setting ignoreRequestParams="true". Consequently the documentId will be picked up from the URL parameters and, if there's nothing there, it will create a new document each time.

Xpages display attachment in dialog box from another document

I am opening a dialog box in an Xpage. In the dialog box I am displaying some fields from 3 other documents, and allowing the user to save some notes. All of this works, except I want to display attachments if there are any. I entered a file download control and for the data source pointed to the target document and did a
tmpDoc.getAttachment("attachments")
to get the attachments. But nothing shows up.
Here is the code from the one row in the table in the dialog box.
The other fields work fine, and I know I am getting the tmpDoc, but how do I display the attachment so the user can view it?
<xp:td>
<xp:fileDownload
rows="30"
id="fileDownload1"
displayLastModified="false">
<xp:this.value><![CDATA[#{javascript:
var prtUNID:String = document.getItemValueString("PCTaskParentID");
var tmpView:NotesView = database.getView("(dbAllPCTasksByTaskID)");
var tmpDoc:NotesDocument = tmpView.getDocumentByKey(prtUNID);
tmpDoc.getAttachment("attachments")
}]]></xp:this.value>
</xp:fileDownload>
</xp:td>
I am having more issues with this. Now it does not really work at all.
Here is what I am trying to accomplish.
I have a form PC Build. It is all the tasks that must be done to build a PC in my company. There is a list of Master Tasks called PC Tasks. When a new PC Build is saved, the PC Tasks get copied to rspPCTask forms attached to the PC Build.
As a user works om building a computer they can open up the PC Build and see the individual tasks. I want them to be able to click on a task and pull up the notes and attachments from the master task, while entering notes for the individual task.
Below is a screen shot. In the second field I am grabbing something with javascript. In the first field I am binding the field to the data source, but it is always blank. I cannot figure out why.
I have put in all my code below. Any assistance would be greatly appreciated!!!
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom"
dojoForm="true"
dojoParseOnLoad="true"
dojoTheme="true">
<xp:this.data>
<xp:dominoDocument
var="document1"
action="openDocument"
computeWithForm="onsave"
formName="PCBuild">
<xp:this.postNewDocument>
<xp:actionGroup>
<xp:setValue
binding="#{document1.ID}"
value="#{javascript:session.evaluate('#Unique')}" />
<xp:setValue
binding="#{document1.crtDte}"
value="#{javascript:session.evaluate('#Today')}" />
<xp:setValue
binding="#{document1.crtUsr}"
value="#{javascript:session.getCommonUserName()}" />
</xp:actionGroup>
</xp:this.postNewDocument>
</xp:dominoDocument>
</xp:this.data>
<xp:this.resources>
<xp:styleSheet
href="/custom.css" />
<xp:script
src="/xpValidationPCBuild.jss"
clientSide="false" />
<xp:script
src="/xpUtilities.jss"
clientSide="false"></xp:script>
<xp:styleSheet
href="/.ibmxspres/dojoroot/dojox/grid/resources/tundraGrid.css">
</xp:styleSheet>
<xp:styleSheet
href="/.ibmxspres/dojoroot/dojox/grid/resources/tundraEnhancedGrid.css">
</xp:styleSheet>
<xp:dojoModule
name="dojox.grid.EnhancedGrid"></xp:dojoModule>
</xp:this.resources>
<xp:this.beforePageLoad><![CDATA[#{javascript:viewScope.ID = document1.getItemValueString("ID")}]]></xp:this.beforePageLoad>
<xp:this.afterPageLoad><![CDATA[#{javascript:viewScope.put("rows","25")}]]></xp:this.afterPageLoad>
<xp:panel
style="width:900.00px">
<xp:panel>
<xp:text
escape="true"
id="dspDocUNID"
style="display:none">
<xp:this.value><![CDATA[#{javascript:if (#IsNewDoc())
{
return "0"
}
else
{
var doc:NotesDocument = document1.getDocument();
var sUNID = doc.getUniversalID();
return sUNID
}}]]></xp:this.value>
</xp:text>
<xp:scriptBlock
id="scriptBlock1">
<xp:this.value><![CDATA[// Conditionally return an image tag to display an icon in a cell
function displayIcon (value) {
var image = '';
switch (value.toLowerCase()) {
case "open":
image = '<img alt="" src="blueUncheckedCheckBox15.png" />';
break;
case "closed":
image = '<img alt="" src="blueCheckedCheckBox15.png" />';
break;
default:
image = '<img alt="" src="greenChk50.png" />';
break;
}
return image;
}]]></xp:this.value>
</xp:scriptBlock>
</xp:panel>
<xe:widgetContainer
id="widgetContainerHeader">
<xp:panel
style="padding-top:8.0px;padding-bottom:8.0px">
<xp:button
id="button1"
value="Edit"
style="font-weight:bold;font-size:10pt"
rendered="#{javascript:!(document1.isEditable())}">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action>
<xp:changeDocumentMode
mode="edit" />
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button
value="Save"
id="button3"
style="font-weight:bold;font-size:10pt"
rendered="#{javascript:(document1.isEditable())}">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="partial"
refreshId="plContainer">
<xp:this.action>
<xp:actionGroup
condition="#{javascript:validateForm()}">
<xp:saveDocument
var="document1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript://Get handle on current doc and see if it is a new doc
var thisDoc:NotesDocument = document1.getDocument();
var tg = thisDoc.getItemValueString("tasksGenerated");
if (tg != "Y") {
//Set flag to Y and save document
thisDoc.replaceItemValue("tasksGenerated","Y")
thisDoc.save(true)
var rspDoc:NotesDocument;
//Loop through all PC Task Docs
var pcTasksView:NotesView = database.getView("(dbAllPCTasks)");
var pcTaskDoc:NotesDocument = pcTasksView.getFirstDocument();
var tmpDoc:NotesDocument;
while (pcTaskDoc != null)
{
//Make new doc and add as response to this doc
rspDoc = database.createDocument();
rspDoc.replaceItemValue("Form","rspPCTask");
rspDoc.replaceItemValue("category",pcTaskDoc.getItemValueString("category"));
rspDoc.replaceItemValue("title",pcTaskDoc.getItemValueString("title"));
rspDoc.replaceItemValue("status","Open");
rspDoc.replaceItemValue("PCBuildParentID",thisDoc.getItemValueString("ID"));
rspDoc.replaceItemValue("PCTaskParentID",pcTaskDoc.getItemValueString("ID"));
rspDoc.replaceItemValue("PCTaskParentUNID",pcTaskDoc.getUniversalID());
rspDoc.replaceItemValue("order",pcTaskDoc.getItemValueInteger("order"));
rspDoc.save();
tmpDoc = pcTasksView.getNextDocument(pcTaskDoc);
pcTaskDoc.recycle();
pcTaskDoc = tmpDoc;
}
}}]]></xp:this.script>
</xp:executeScript>
<xp:openPage
name="$$PreviousPage"></xp:openPage>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button
id="button2"
style="font-weight:bold;font-size:10pt"
value="Close">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="norefresh">
<xp:this.action>
<xp:openPage
name="$$PreviousPage"
target="openDocument" />
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:text
escape="true"
id="computedField3"
style="font-size:14pt;color:rgb(79,79,79);padding-left:px;padding-bottom:px;margin-bottom:px;padding-right:25.0px">
<xp:this.value><![CDATA[#{javascript:document1.getItemValueString("crtDte")}]]></xp:this.value>
</xp:text>
</xp:panel>
</xe:widgetContainer>
<xp:panel
id="plContainer">
<xp:panel>
<xe:widgetContainer
id="widgetContainerData">
<xe:formTable
id="frLocationMaster"
disableErrorSummary="true"
disableRowError="true">
<xp:this.facets>
</xp:this.facets>
<xe:formRow
id="formRow5"
labelPosition="none"
style="padding-bottom:10.0px">
<xp:table
style="width:99%"
border="0"
cellpadding="0"
role="presentation"
cellspacing="0"
id="table4">
<xp:tr>
<xp:td
style="width:80.0px;min-width:120px">
<xp:text
id="cfTitle"
xp:key="header"
style="font-size:14pt;color:rgb(79,79,79);padding-left:px;padding-bottom:px;margin-bottom:px">
<xp:this.value><![CDATA[#{javascript:"PC Build"}]]></xp:this.value>
</xp:text>
</xp:td>
<xp:td
style="width:250.0px">
</xp:td>
<xp:td
style="text-align:right">
<xp:text
escape="true"
id="computedField1"
style="font-size:14pt;color:rgb(79,79,79);padding-left:25.0px;padding-bottom:px;margin-bottom:px">
<xp:this.value><![CDATA[#{javascript:document1.getItemValueString("crtUsr") + " on "}]]></xp:this.value>
<xp:this.rendered><![CDATA[#{javascript:if (#IsNewDoc() == 1) {
return false
} else {
return true;
}}]]></xp:this.rendered>
</xp:text>
<xp:text
escape="true"
id="computedField2"
style="font-size:14pt;color:rgb(79,79,79);padding-left:px;padding-bottom:px;margin-bottom:px;padding-right:px"
value="#{document1.CrtDte}">
<xp:this.converter>
<xp:convertDateTime
type="both"
timeStyle="short" />
</xp:this.converter>
<xp:this.rendered><![CDATA[#{javascript:if (#IsNewDoc() == 1) {
return false
} else {
return true;
}}]]></xp:this.rendered>
</xp:text>
</xp:td>
</xp:tr>
</xp:table>
</xe:formRow>
<xe:formRow
id="formRow1"
labelPosition="none">
<xp:table
style="width:99%"
border="0"
cellpadding="0"
role="presentation"
cellspacing="0"
id="table3">
<xp:tr>
<xp:td
style="width:10%;min-width:120px;">
<xp:label
id="label4"
for="formRow1"
value="Employee Name" />
</xp:td>
<xp:td
style="width:100px">
<xp:inputText
value="#{document1.employeeName}"
id="employeeName1">
<xp:typeAhead
mode="full"
minChars="1"
valueListSeparator=","
ignoreCase="true"
id="typeAhead1">
<xp:this.valueList><![CDATA[#{javascript:var dbname = new Array(#Subset(#DbName(), 1),"names.nsf");
return #DbColumn(dbname,"($PeopleByName)",1);}]]></xp:this.valueList>
</xp:typeAhead>
</xp:inputText>
</xp:td>
<xp:td
style="width:20px">
<xe:valuePicker
id="valuePicker1"
for="employeeName1"
pickerIcon="/picker.png"
dialogTitle="Choose Employee">
<xe:this.dataProvider>
<xe:simpleValuePicker>
<xe:this.valueList><![CDATA[#{javascript:var db:NotesDatabase = session.getDatabase(database.getServer(),"names.nsf");
var viewHandle:NotesView = db.getView("($PeopleByName)");
return viewHandle.getColumnValues(0)
}]]></xe:this.valueList>
</xe:simpleValuePicker>
</xe:this.dataProvider>
</xe:valuePicker>
</xp:td>
<xp:td>
<xp:message
id="message1"
for="employeeName1" />
</xp:td>
</xp:tr>
</xp:table>
</xe:formRow>
<xe:formRow
id="formRow2"
labelPosition="none">
<xp:table
style="width:99%"
border="0"
cellpadding="0"
role="presentation"
cellspacing="0"
id="table1">
<xp:tr>
<xp:td
style="width:10%;min-width:120px;">
<xp:label
id="label1"
for="formRow1"
value="Computer Name" />
</xp:td>
<xp:td
style="width:100px">
<xp:inputText
value="#{document1.computerName}"
id="computerName1">
</xp:inputText>
</xp:td>
<xp:td
style="width:20px">
</xp:td>
<xp:td>
<xp:message
id="message2"
for="computerName1" />
</xp:td>
</xp:tr>
</xp:table>
</xe:formRow>
<xe:formRow
id="formRow3"
labelPosition="none"
rendered="false">
</xe:formRow>
<xe:formRow
id="formRow4"
labelPosition="none"
rendered="false">
</xe:formRow>
</xe:formTable>
</xe:widgetContainer>
</xp:panel>
</xp:panel>
<xp:panel>
<xe:widgetContainer
id="widgetContainer1">
<xp:panel>
<xp:viewPanel
rows="30"
id="viewPanel1"
var="thisEntry">
<xp:this.facets>
<xp:pager
partialRefresh="true"
layout="Previous Group Next"
xp:key="headerPager"
id="pager1">
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view1"
viewName="(dbAllRpPCTasks)">
<xp:this.keys><![CDATA[#{javascript:document1.getItemValueString("ID")}]]></xp:this.keys>
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
columnName="title"
id="viewColumn5"
displayAs="link">
<xp:viewColumnHeader
value="Title"
id="viewColumnHeader5">
</xp:viewColumnHeader>
<xp:eventHandler
event="onclick"
submit="false"
refreshMode="partial"
refreshId="panelDig">
<xp:this.action><![CDATA[#{javascript:viewScope.UNID = thisEntry.getDocument().getUniversalID();
viewScope.parUNID = thisEntry.getDocument().getItemValueString("PCTaskParentUNID");
getComponent('dialog1').show()}]]></xp:this.action>
</xp:eventHandler>
</xp:viewColumn>
</xp:viewPanel>
<xp:panel
id="panelDig">
<xp:this.data>
<xp:dominoDocument
var="document2"
formName="PCTask"
action="editDocument"
documentId="#{javascript:viewScope.parUNID}">
</xp:dominoDocument>
<xp:dominoDocument
var="document3"
formName="rspPCTask"
action="editDocument"
documentId="#{javascript:viewScope.parUNID}">
</xp:dominoDocument>
</xp:this.data>
<xe:dialog
id="dialog1"
style="width:700px;height:600px"
refreshOnShow="true">
<xp:table>
<xp:tr>
<xp:td>
<xp:label
value="Master Title"
id="label2" />
</xp:td>
<xp:td>
<xp:text
escape="true"
id="computedField4"
value="#{document2.title}">
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:label
value="Master Task Notes"
id="label3" />
</xp:td>
<xp:td>
<xp:text
escape="true"
id="computedField5">
<xp:this.value><![CDATA[#{javascript:var tmpDoc:NotesDocument = database.getDocumentByUNID(viewScope.parUNID)
tmpDoc.getItemValueString("notes")}]]></xp:this.value>
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:label
value="Master Attachments"
id="label5" />
</xp:td>
<xp:td></xp:td>
</xp:tr>
<xp:tr>
<xp:td></xp:td>
<xp:td></xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:label
id="label7"
value="Notes" />
</xp:td>
<xp:td>
<xp:inputTextarea
id="inputTextarea1"
style="width:98.0%;height:100px"
value="#{document3.notes}">
</xp:inputTextarea>
</xp:td>
</xp:tr>
</xp:table>
</xe:dialog>
</xp:panel>
</xp:panel>
</xe:widgetContainer>
</xp:panel>
</xp:panel>
<xp:eventHandler
event="onClientLoad"
submit="true"
refreshMode="norefresh">
<xp:this.script><![CDATA[try {
dojo.byId("#{id:employeeName1}").focus();
} catch (e) { }]]></xp:this.script>
</xp:eventHandler>
</xp:view>
To show all rich text field's attachments of "another" document in a fileDowndload control:
add a panel around your fileDownload control,
add a dominoDocument data source to the panel
set attribute documentId to "another" document's UNID
set fileDownload's value to document's rich text field
(in your case the rich text field is called "attachments")
<xp:td>
<xp:panel>
<xp:this.data>
<xp:dominoDocument
var="documentPCTaskParent"
action="openDocument">
<xp:this.documentId><![CDATA[#{javascript:
document.getItemValueString("PCTaskParentID")
}]]></xp:this.documentId>
</xp:dominoDocument>
</xp:this.data>
<xp:fileDownload
rows="30"
id="fileDownload1"
displayLastModified="false"
value="#{documentPCTaskParent.attachments}">
</xp:fileDownload>
</xp:panel>
</xp:td>
BTW tmpDoc.getAttachment("attachments") you used doesn't return all attachments of rich text field "attachments" but would look for an attachment with the file name "attachments" somewhere in document.
I would avoid the file download control if possible. What you likely want to do is just build html links or images to the actual files themselves. So it's mostly a matter of figuring out the correct URL to get to it. Typically these are old school "non XPages" URL's... the classic domino stuff.
Everything I know about doing this I learned form this post: http://www.wissel.net/blog/d6plinks/SHWL-86QKNM
Short answer: you can add tmpDoc as a true document data source (using

XPages - View doesn't update when a partial refresh occured

I have a page bound to a doc data source. At the top of the page is a panel where the fields for the doc is set. In the bottom of the page is a view of the docs.
Let's say the fields are [A] and [B], and [B]'s value depends on [A], which partial refreshes [B] on some value change. When I just set [A] that doesn't trigger the partial refresh then press submit/save, the doc is saved and the page updates fully and the doc appears in the view below.
BUT if I set [A] such that [B] refreshes then press submit/save, the doc is saved BUT the doc doesn't appear in the view. I need to reload the page by pressing ENTER in the URL bar to update the view. Tried to do a research on this but to no avail.
What do you think I can do to update the view on the last scenario?
Here is the simplified code:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom"
style="font-size:11pt;font-weight:bold">
<xp:this.beforePageLoad>
<![CDATA[#{javascript:var currLocation=context.getUrl();
var webDBPath=#LeftBack(currLocation,"/");
sessionScope.jQuery=webDBPath+"/jquery.min.js";
sessionScope.jQueryUI=webDBPath+"/jquery-ui.min.js";
sessionScope.jQueryBlockUI=webDBPath+"/jquery.blockUI.js"}]]>
</xp:this.beforePageLoad>
<xp:this.data>
<xp:dominoDocument var="attachmentDoc" formName="Attachment"></xp:dominoDocument>
</xp:this.data>
<xp:this.resources>
<xp:script src="#{javascript:sessionScope.jQuery}"
clientSide="true">
</xp:script>
<xp:script src="#{javascript:sessionScope.jQueryUI}"
clientSide="true">
</xp:script>
<xp:script src="#{javascript:sessionScope.jQueryBlockUI}"
clientSide="true">
</xp:script>
<xp:script src="/home.js" clientSide="true"></xp:script>
<xp:styleSheet href="/style.css"></xp:styleSheet>
<xp:styleSheet href="/jquery-ui.css"></xp:styleSheet>
<xp:script src="/utils.jss" clientSide="false"></xp:script>
</xp:this.resources>
<xp:span style="font-weight:bold;font-size:11pt"></xp:span>
<xp:span style="font-size:14pt"></xp:span>
<xp:span style="font-weight:bold;font-size:11pt"></xp:span>
<xp:inputText id="reUploadAttachmentID" style="display: none;"
styleClass="reUploadAttachmentID"></xp:inputText>
<xp:br style="font-size:11pt"></xp:br>
<xp:panel style="margin-left:auto;margin-right:auto;width:940.0px"
id="mainPanel">
<xp:span style="font-size:14pt"></xp:span>
<xp:span style="font-size:14pt"></xp:span>
<xp:br style="font-weight:bold"></xp:br>
<xp:br></xp:br>
<xp:inputText id="errorMessage" value="#{requestScope.errorMessage}"
styleClass="errorMessage"></xp:inputText>
<xp:span style="font-weight:bold"></xp:span>
<xp:span style="font-weight:bold">
<xp:span style="font-weight:bold"></xp:span>
</xp:span>
<xp:br></xp:br>
<xp:panel styleClass="upload-details-panel">
<xp:span>Upload:</xp:span>
<xp:fileUpload id="fileUpload1" value="#{attachmentDoc.Attachment}"></xp:fileUpload>
</xp:panel>
<xp:panel styleClass="upload-details-panel">
<span>Type:</span>
<xp:comboBox id="cbUploadType" value="#{attachmentDoc.File_Type}"
styleClass="cbUploadType">
<xp:selectItem itemLabel="Attachment"></xp:selectItem>
<xp:selectItem itemLabel="eCR Master File"></xp:selectItem>
<xp:selectItem itemLabel="Financial Analysis"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="panelUploadDetails">
</xp:eventHandler>
</xp:comboBox>
</xp:panel>
<xp:panel id="panelUploadDetails">
<xp:panel styleClass="upload-details-panel">
<xp:this.rendered><![CDATA[#{javascript:var uploadType = getComponent("cbUploadType").getValue();
if(uploadType == "Attachment" || uploadType == null){
return false;
}
return true;}]]></xp:this.rendered>
<span>Division:</span>
<xp:comboBox id="comboBox1" value="#{attachmentDoc.File_Database}"
styleClass="cbUploadDatabase">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var options = ["---"];
return options.concat(#Unique(#DbColumn("", "eCR Database Settings", 1)));}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial"
refreshId='#{javascript:var uploadType = getComponent("cbUploadType").getValue();
if(uploadType == "Financial Analysis"){
return "panelFAType";
}
return "panelExtra";
}'>
</xp:eventHandler>
</xp:comboBox>
</xp:panel>
<xp:panel id="panelExtra">
<!--
this is just used to redirect partial refresh of Division
Selection for non-FA
-->
</xp:panel>
<xp:panel styleClass="upload-details-panel" id="panelFAType">
<xp:this.rendered><![CDATA[#{javascript:var uploadType = getComponent("cbUploadType").getValue();
if(uploadType == "Financial Analysis"){
return true;
}
return false;}]]></xp:this.rendered>
<span>Financial Analysis Type:</span>
<xp:comboBox id="comboBoxFAType" value="#{attachmentDoc.FAType}">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var division = getComponent("comboBox1").getValue();
if(division != null){
return getFATypeOptions(getComponent("comboBox1").getValue());
}
return "---";}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
</xp:panel>
</xp:panel>
<xp:panel styleClass="upload-details-panel">
<span></span>
<xp:button id="btnUpload" value="Upload" styleClass="btnUpload"
style="height:26.0px">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="false" save="true">
<xp:this.action><![CDATA[#{javascript:
var fileData:com.ibm.xsp.http.UploadedFile = facesContext.getExternalContext().getRequest().getParameterMap().get(getClientId('fileUpload1'));
var db:NotesDatabase = session.getCurrentDatabase();
var agent = database.getAgent("Import Data to Document");
//var attDoc:NotesDocument = attachmentDoc.getDocument();
//var doc:NotesDocument = db.createDocument();
var doc:NotesDocument = attachmentDoc.getDocument();
var settingsDoc:NotesDocument = db.getProfileDocument("eCRFilesDBConfiguration", "");
var repositoryPath:String;
if (fileData != null) {
//doc.replaceItemValue('Form', 'Attachment');
doc.computeWithForm(true, false);
var clientFileName:String = fileData.getClientFileName();
var newFile:java.io.File = new java.io.File(fileData.getServerFileName());
var filePath:string = doc.getItemValueString("File_Path");
doc.replaceItemValue('File_Name', clientFileName);
// get file extension
var extension:string = '';
var newFileName:string = '';
var i:int;
i = clientFileName.lastIndexOf('.');
if (i > 0) {
extension = clientFileName.substring(i+1);
}
doc.replaceItemValue('File_Extension', extension);
newFileName = doc.getUniversalID() + '.' + extension;
//var savedFile:java.io.File = new java.io.File('C:\\' + newFileName);
//var savedFile:java.io.File = new java.io.File('C:\\' + clientFileName);
repositoryPath = settingsDoc.getItemValueString("FileRepositoryPath")
var savedFile:java.io.File = new java.io.File(repositoryPath + newFileName);
newFile.renameTo(savedFile);
doc.replaceItemValue("File_Size", savedFile.length())
doc.replaceItemValue("Processed_eCR_Template", "");
// Save the new file
if (savedFile.exists()) {
// this is used to retain the icon/appearance of the attachment
// in the document
//doc.replaceItemValue('Attachment', attDoc.getItemValue('Attachment'));
doc.save();
} else {
//requestScope.errorMessage = 'Server file not found';
print('Server file not found');
}
} else {
requestScope.errorMessage = 'No File found';
print('No File found');
}
// this code prevents resubmit of the uploaded file when the user refreshes
// the page
// var curURL = window.location.href;
// var NSFURL = curURL.toLowerCase().split( '.nsf')[0] + '.nsf';
// window.location.href = NSFURL}]]></xp:this.action>
<xp:this.script><![CDATA[//validate fields before submission
var uploadType = document.getElementById("#{id:cbUploadType}").value;
if(uploadType == "Attachment"){
return true;
}else{
var division = document.getElementById("#{id:comboBox1}").value;
if(division == "---"){
alert("Please specify the division.");
return false;
}
if(uploadType == "eCR Master File"){
return true;
}else if(uploadType == "Financial Analysis"){
var faType = document.getElementById("#{id:comboBoxFAType}").value;
if(faType == "---"){
alert("Please specify the Financial Analysis Type.");
return false;
}else{
return true;
}
}
}
//if upload type not rcognized
alert("Upload Type not recognized. Please contact you administrator.");
return false;
]]></xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:panel>
<xp:panel id="panelUploadedFiles">
<xp:viewPanel rows="30" id="viewPanel1" viewStyle="width:100%">
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next"
xp:key="headerPager" id="pager1">
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1" viewName="Attachments For Web"
keys="#{javascript:#UserName()}" categoryFilter="File_Owner">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="File_Name" id="viewColumn2">
<xp:viewColumnHeader value="File Name"
id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="Date_Uploaded" id="viewColumn3">
<xp:viewColumnHeader value="Date Uploaded"
id="viewColumnHeader3">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="Last_Attached" id="viewColumn4">
<xp:viewColumnHeader value="Last Attached"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel>
</xp:panel>
</xp:panel>
<xp:br></xp:br>
</xp:view>
The elements that triggers the partial refresh are comboboxes (onchange). The save button is the "Upload" button. The panel panelUploadedFiles contains the view.
You need to post sample code, as there is no way to diagnose your issue from your initial question.
I would recommend to take the "XPages MasterClass" training. It is roughly about four hours. It will show you how to use the XPages Toolbox, which you can use to debug these kinds of issues.

How can I set focus to Edit Box inside repeat control?

I would like to set focus + place cursor to an Edit Box (the last one) within a repreat control. The repeat is inside a panel (panelRep). I then have a button outside the panel.
This is the client side code for the button which almost works.. Focus is set (blue border around field), but cursor is not placed in field.
User must still click the field to be able to write input.
Example without focus:
Example with focus:
Client side code for button which sets focus to last Edit Box in which id contains the string inputKode:
try {
var el = dojo.query('div[id*="inputKode"]');
var node = el[el.length-1];
setTimeout(function() { node.focus(); }, 500);
//node.focus();
} catch (e) { }
Code for panelRep:
<xp:panel id="panelRep">
<xp:repeat id="repeat1" rows="12" var="row" indexVar="idx"
value="#{view1}" repeatControls="false">
<xp:panel id="panelLinje">
<xp:this.data>
<xp:dominoDocument formName="frmPBudKodeVerdi"
var="dsdoc" action="editDocument" computeWithForm="both"
documentId="#{javascript:row.getUniversalID();}">
</xp:dominoDocument>
</xp:this.data>
<xp:table style="width:800.0px">
<xp:tr>
<xp:td style="width:100px">
<xp:inputText id="inputKode"
value="#{dsdoc.KodeNr}" style="width:62px">
<xp:this.attrs>
<xp:attr name="tabindex"
value="#{javascript:return idx + '1';}">
</xp:attr>
</xp:this.attrs>
<xp:typeAhead mode="partial"
minChars="1" var="lukey" valueMarkup="true" id="typeAhead1">
<xp:this.valueList><![CDATA[#{javascript://var type = compositeData.type;
return TypeAheadKode2(sessionScope.type,lukey);
}]]></xp:this.valueList>
</xp:typeAhead>
<xp:eventHandler event="onchange"
submit="true" refreshMode="partial" refreshId="panelLinje">
<xp:this.action><![CDATA[#{javascript:onChangeKode();}]]></xp:this.action>
</xp:eventHandler>
</xp:inputText>
</xp:td>
<xp:td style="width:450px">
<xp:inputText id="inputNavn"
value="#{dsdoc.KodeNavn}" style="width:440px"
readonly="true">
</xp:inputText>
</xp:td>
<xp:td style="width:60px">
<xp:inputText id="inputNorm"
style="width:45px" value="#{dsdoc.NormPrProd}"
rendered="#{javascript:viewScope.visNorm}" readonly="true">
<xp:this.attrs>
<xp:attr name="tabindex"
value="#{javascript:return idx + '2';}">
</xp:attr>
</xp:this.attrs>
<xp:this.converter>
<xp:convertNumber
type="number">
</xp:convertNumber>
</xp:this.converter>
</xp:inputText>
</xp:td>
<xp:td style="width:50px">
<xp:inputText id="inputAntall"
style="width:45px" value="#{dsdoc.NormAntall}"
rendered="#{javascript:viewScope.visNorm}">
<xp:this.converter>
<xp:convertNumber
type="number">
</xp:convertNumber>
</xp:this.converter>
<xp:eventHandler
event="onchange"
submit="true"
refreshMode="partial"
refreshId="inputTimer">
<xp:this.action><![CDATA[#{javascript:onChangeAntall()}]]></xp:this.action>
</xp:eventHandler>
<xp:this.attrs>
<xp:attr name="tabindex"
value="#{javascript:return idx + '3';}">
</xp:attr>
</xp:this.attrs>
</xp:inputText>
</xp:td>
<xp:td
style="width:50px;text-align:right">
<xp:inputText id="inputTimer"
value="#{dsdoc.Timer}" style="width:45px;text-align:right">
<xp:this.converter>
<xp:convertNumber
type="number">
</xp:convertNumber>
</xp:this.converter>
<xp:this.attrs>
<xp:attr name="tabindex"
value="#{javascript:return idx + '4';}">
</xp:attr>
</xp:this.attrs>
</xp:inputText>
</xp:td>
<xp:td>
</xp:td>
</xp:tr>
</xp:table>
<xp:eventHandler event="onClientLoad" submit="true"
refreshMode="norefresh">
</xp:eventHandler>
</xp:panel>
</xp:repeat>
</xp:panel>
Update 22.09.2012:
#MarkyRoden - Thanks for pointing me in the right direction.
After refining the dojo.query selector, I ended up with 1 line of code.
var el = dojo.query('div[id*="inputKode"] .dijitInputField > input').at(-1)[0].focus();
Original post:
I found out that the element being set focus on was not an INPUT element.
Element id started with widget_
E.g widget_view:_id1:_id2:_id3:repeat1:8:inputKode if there are 8 rows in the repeat
I then discovered that the nodeType of the element was DIV
By viewing the element.innerHTML, I discovered that it had multiple children.
I tried to use element.querySelector or element.querySelectorAll, but I couldn't get them to work for the element, so I ended up looping through element.childNodes.
Not very pretty, but it does the work for now..
I'm sure it can be done much nicer by adding elements to the dojo.query selector, or by using jquery. Have to look into that later..
Well, here's the code I put in the onClientLoad event for my CC:
var el = dojo.query('div[id*="inputKode"]');
var node = el[el.length-1];
node.focus();
var activeElementId = document.activeElement.id;
var activeElement = dojo.byId( activeElementId );
var kids = activeElement.childNodes;
for(var i=0; i < kids.length; i++)
{
if(kids[i].className == 'dijitReset dijitInputField dijitInputContainer')
{
var elementDiv = kids[i];
var elementDivKids = elementDiv.childNodes;
for(var j=0; j < elementDivKids.length; j++)
{
var elementInput = elementDivKids[j];
elementInput.focus();
}
}
}
regards,
Petter

Resources