Repeat control with Custom Control and Datasource

Hello,I’am developing a web XPages application, and I trying to use a techinique of using multiple Datasources suggested by John Mackey (http://www.jmackey.net/groupwareinc/johnblog/johnblog.nsf/d6plinks/GROC-7FFLYJ).

I gotta a main document that have 0 or more dependent documents. So, I desined a XPage with a repeat control that shows the associated documents:

<xp:repeat id=“repeat1” rows=“30” var=“entryExecutante”>

The formula that Im using inside the repeat control is:

xp:this.value<![CDATA[#{javascript:var arrayExecutante=null;

var index=0;

if(sessionScope.acaoVCP==“novoExecutante”){

arrayExecutante=new Array();

//arrayExecutante[index++]=sessionScope.dadosNovoExecutante;

arrayExecutante[index++]={

	action: null,

	NoteID: null,

	CodigoGerencia: vcp.getValue("ca_vcpCodigoGerencia"),

	CodigoVCP: vcp.getValue("ca_Codigo"),

	Gerencia: vcp.getValue("ca_vcpGerencia"),

	CodigoAN: vcp.getValue("ca_vcpCodigoAN")

}

}

var dc = viDu001.getAllDocumentsByKey(“C~”+vcp.getValue(“ca_Codigo”)+“~fo_ExecutanteVCP~”, false);

if(dc.getCount()>0){

if(arrayExecutante==null) arrayExecutante=new Array();

for(var i=1; i<=dc.getCount(); i++)

	arrayExecutante[index++]={

		NoteID: dc.getNthDocument(i).getNoteID(),

		action: vcp.isEditable()?"editDocument":"openDocument",

		CodigoGerencia: vcp.getValue("ca_vcpCodigoGerencia"),

		CodigoVCP: vcp.getValue("ca_Codigo"),

		Gerencia: vcp.getValue("ca_vcpGerencia"),

		CodigoAN: vcp.getValue("ca_vcpCodigoAN")

	};

}

return arrayExecutante;}]]></xp:this.value>

Basically, this formula creates a array of objects that will initialize the custom control that contains the datasource of the associted doc.

At the beginning, I test if the user is creating a new document (sessionScope.acaoVCP==“novoExecutante”, this sessionScope variable is set through a button), if so, it sets the first position on the array with a object with action=null and NoteID=null, signaling that the datasource correspond a new document.

The button that shows that signals the repeat to put the empty custom control at the beggining follows:

<xp:button value=“Incluir Executante” id=“button5” styleClass=“customButton”>

<xp:this.rendered><![CDATA[#{javascript:vcp.isEditable() && sessionScope.acaoVCP!="novoExecutante"}]]>

</xp:this.rendered>

<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="true" refreshId="pnExecutantesForm">

	<xp:this.action>

		<xp:executeScript>

			<xp:this.script><![CDATA[#{javascript:sessionScope.acaoVCP="novoExecutante";}]]>

			</xp:this.script>

		</xp:executeScript>

	</xp:this.action>

</xp:eventHandler>

</xp:button>

Note that the event only tells the application to refresh partial, the “pnExecutantesForm” is the xp:panel that contains the button and the repeat control.

Inside the repeat, I put a custom control with a datasource to the associated document.

<xc:ccNovoExecutante

action="#{javascript:entryExecutante.action}" 

CodigoAN="#{javascript:entryExecutante.CodigoAN}" 

CodigoGerencia="#{javascript:entryExecutante.CodigoGerencia}" 

CodigoVCP="#{javascript:entryExecutante.CodigoVCP}" 

Gerencia="#{javascript:entryExecutante.Gerencia}" 

NoteID="#{javascript:entryExecutante.NoteID}">

</xc:ccNovoExecutante>

This custom control provides a few properties to allow me to control its behavior.

The custom control’s Datasource is defined by the compositeData.action and the compositeData.NoteID:

<xp:this.data>

	<xp:dominoDocument var="docNewExecutante"

		formName="fo_ExecutanteVCP" ignoreRequestParams="true"

		computeWithForm="onsave"

		documentId="#{javascript:return compositeData.NoteID}"

		action="#{javascript:compositeData.action}">

		

		<xp:this.postNewDocument>

			<xp:executeScript>

				<xp:this.script><![CDATA[#{javascript:requestScope.CodigoNovoExecutante=@Unique()

docNewExecutante.replaceItemValue(“ca_exvCodigoGerencia”, compositeData.CodigoGerencia);

docNewExecutante.replaceItemValue(“ca_exvCodigoVCP”, compositeData.CodigoVCP);

docNewExecutante.replaceItemValue(“ca_Codigo”, requestScope.CodigoNovoExecutante)}]]></xp:this.script>

			</xp:executeScript>

		</xp:this.postNewDocument>

	</xp:dominoDocument>

</xp:this.data>

The main objective here is, allow the user to view the associated docs through this custom control in the main page, and, when the user clicks the button to add a new associated doc, the application shows in the first position a empty form to input the information.

THE PROBLEM:

When I click the button, instead of show a empty form, it shows a form whith the values of the last line of the associated docs, and scramble all the associated docs that it had already show in a correct way.

The strange thing is, when I put only the part of the code that put the object that intialize the custom control to show a empty form, it works. But, when I mixed up, it gets scramble.

I dont know what am I doing wrong.

Can anyone have a clue to work this out?

Subject: Workaround…

For those who are interesting, I figured out how to solve this “bug”.I put the object, that put the custom control as a “newDocument”, in the end of the array.

		<xp:repeat id="repeat1" rows="30" var="entryExecutante"

											disableTheme="true">

											<li>



												<xc:ccNovoExecutante action="#{javascript:entryExecutante.action}"

													CodigoAN="#{javascript:entryExecutante.CodigoAN}"

													CodigoGerencia="#{javascript:entryExecutante.CodigoGerencia}"

													CodigoVCP="#{javascript:entryExecutante.CodigoVCP}"

													Gerencia="#{javascript:entryExecutante.Gerencia}" NoteID="#{javascript:entryExecutante.NoteID}">

												</xc:ccNovoExecutante>

											</li>

											<xp:this.value><![CDATA[#{javascript:var arrayExecutante=null;

var index=0;

var dc = viDu001.getAllDocumentsByKey(“C~”+vcp.getValue(“ca_Codigo”)+“~fo_ExecutanteVCP~”, false);

if(dc.getCount()>0){

if(arrayExecutante==null) arrayExecutante=new Array();

for(var i=1; i<=dc.getCount(); i++)

	arrayExecutante.push({

		NoteID: dc.getNthDocument(i).getNoteID(),

		action: (vcp.isEditable()?"editDocument":"openDocument")

		/*CodigoGerencia: dc.getNthDocument(i).getItemValueString("ca_exvCodigoGerencia"),

		CodigoVCP: dc.getNthDocument(i).getItemValueString("ca_exvCodigoVCP"),

		Gerencia: dc.getNthDocument(i).getItemValueString("ca_exvGerencia"),

		CodigoAN: dc.getNthDocument(i).getItemValueString("ca_exvCodigoAN")*/

	});

}

if(sessionScope.acaoVCP==“novoExecutante”){

// arrayExecutante=new Array();

arrayExecutante.push({

	action: null,

	NoteID: null,

	CodigoGerencia: vcp.getValue("ca_vcpCodigoGerencia"),

	CodigoVCP: vcp.getValue("ca_Codigo"),

	Gerencia: vcp.getValue("ca_vcpGerencia"),

	CodigoAN: vcp.getValue("ca_vcpCodigoAN")

});

}

return arrayExecutante;}]]></xp:this.value>

										</xp:repeat>