I am trying to generate a hierarchical list of categories and sub-categories on an X-Page. So far I have attempted two methods:
The first, which works, is based on code by Jesse Gallagher in this blog post and that outputs the list in exactly the order I want it using an xe:outline control. However, I want be able to add extra functions and styling to each entry (e.g. edit and delete links) but can't work out how to render custom controls within the outline control.
The second method is trying to leverage nested repeats and custom controls to generate the list but for the life of me I can't quite get this work and I don't know if it's because it just won't work or I'm just missing something fundamental. The basic code for the XPage is:
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.data>
<xp:dominoView var="Categories" viewName="vLUTopCat"></xp:dominoView>
</xp:this.data>
<xc:ccUI navigationPath="Admin/Main" pageName="Admin">
<xp:this.facets>
<xp:panel xp:key="facetMiddle">
<h2>Categories</h2>
<ul id="adminCatList">
<xp:repeat id="parentCat" rows="30" value="#{Categories}" var="DocCat" indexVar="catIdx" disableOutputTag="true">
<xc:ccCategoryList>
<xc:this.catID><![CDATA[#{javascript:DocCat.getColumnValue("docID")}]]></xc:this.catID>
<xc:this.catName><![CDATA[#{javascript:DocCat.getColumnValue("categoryName")}]]></xc:this.catName>
</xc:ccCategoryList>
</xp:repeat>
</ul>
</xp:panel>
</xp:this.facets>
</xc:ccUI>
and the code for the custom control (ccCategoryList) is:
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:text escape="true" id="computedField1"
value="#{compositeData.catName}" tagName="li" />
<xp:repeat id="rptSubCat" rows="30" var="subCat"
disableOutputTag="true">
<xp:this.facets>
<xp:text disableTheme="true" xp:key="header"
escape="false">
<xp:this.value><![CDATA[<ul>]]></xp:this.value>
</xp:text>
<xp:text disableTheme="true" xp:key="footer"
escape="false">
<xp:this.value><![CDATA[</ul>]]></xp:this.value>
</xp:text>
</xp:this.facets>
<xp:this.value><![CDATA[#{javascript:var tview = database.getView("vLUSubCat");
var v = compositeData.catID;
var vc:NotesViewEntryCollection = null;
if (v != null) {
vc = tview.getAllEntriesByKey(v);
}
vc}]]></xp:this.value>
<xc:ccCategoryList>
<xc:this.catID><![CDATA[#{javascript:subCat.getColumnValues()[3]}]]></xc:this.catID>
<xc:this.catName><![CDATA[#{javascript:subCat.getColumnValues()[1]}]]></xc:this.catName>
</xc:ccCategoryList>
</xp:repeat>
</xp:view>
So my related questions are:
Is there anyway to output a custom control in an xe:outline control using a bean node?
Can I use repeats and custom controls to recursively output data from views like I can using a bean node?
Is there a better alternative method I'm overlooking (e.g. using a Java Collection in a bean and a repeat control?)
Thanks
1) There is a way to add your own CustomNode to the Outline For that look into extending:
com.ibm.xsp.extlib.tree.ITreeNode;
com.ibm.xsp.extlib.tree.complex.ComplexLeafTreeNode;
com.ibm.xsp.extlib.tree.impl.TreeNodeWrapper;
2) sorry i have never tryed to build a recursive xpage element as a custom Control, but i would not recoment it.
3) You could just use the <xe:forumView> or the <xp:viewPanel> both have nice possibilites to determine if the viewEntry/row is a Category or not. And offers you the possebility to add everything you want like links, buttons or other controls to a row.
or another way to get what you need is to build you Outline/TreeView with the DojoTreeView:
Link1
Link2
Related
I need to create 3 fields in one row every time a new objective is needed. objective1, midYear1, endYear1. Then if I add an objective, objective2, midYear2, endYear2 and so on. Everything seems to work, first time, but second time it creates loads of fields. I assume its the way I'm nesting / not nesting/using my repeats correctly as my viewScope variables are all correct, so it's just displaying of the fields that I'm confusing myself with. I just need each of the 3 fields in one column each, then new row and repeat.....Code below, however am also open to suggestions if anyone has a better approach..... Thanks
<xp:this.data>
<xp:dominoDocument
var="document1"
formName="objective">
</xp:dominoDocument>
</xp:this.data>
<xp:repeat id="repeat1" rows="100" value="#{viewScope.fields}"
var="fieldName">
<xp:repeat id="repeat2" rows="100" value="#{viewScope.fields2}"
var="fieldName2">
<xp:repeat id="repeat3" rows="100" value="#{viewScope.fields3}"
var="fieldName3">
<div class="row">
<div class="col-xs-4">
<xp:label value="#{fieldName}" for="inputText1">
</xp:label>
<xp:inputText id="inputText1">
<xp:this.value><![CDATA[#{document1[fieldName]}]]></xp:this.value>
</xp:inputText>
</div>
<div class="col-xs-4">
<xp:label value="#{fieldName2}" for="inputText2">
</xp:label>
<xp:inputText id="inputText2">
<xp:this.value><![CDATA[#{document1[fieldName2]}]]></xp:this.value>
</xp:inputText>
</div>
<div class="col-xs-4">
<xp:label value="#{fieldName3}" for="inputText3">
</xp:label>
<xp:inputText id="inputText3">
<xp:this.value><![CDATA[#{document1[fieldName3]}]]></xp:this.value>
</xp:inputText>
</div>
</div>
</xp:repeat>
</xp:repeat>
</xp:repeat>
<xp:button
value="Add Objective"
id="button1">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial"
refreshId="repeat1">
<xp:this.action><![CDATA[#{javascript:
if (!viewScope.fields) {
viewScope.fields = [];
viewScope.fields2 = [];
viewScope.fields3 = [];
var count:integer = 1;
}
viewScope.fields.push("Objective" + (viewScope.fields.length + 1));
viewScope.fields2.push("MidYear" + (viewScope.fields2.length + 1));
viewScope.fields3.push("EndYear" + (viewScope.fields3.length + 1));
count = count+1;
}]]></xp:this.action>
</xp:eventHandler>
The problem is that by nesting, for each entry in coumn 1, you're creating n instances of column 2. Then for each entry in column, you're creating n instances of column 3. If you want this approach, you're best off creating a single viewScope variable, where each element has the fieldnames for each objective (as an object or array), then just using a single repeat using that single viewScope variable.
Building this for Notes Client / traditional Domino web was historically a huge pain because the restriction was you could not edit multiple documents (easily) in the same UI, because the Form was both the schema for storage and the design for the UI.
XPages means that's no longer a restriction. The XPage is the UI, (dominoDocument / bean) data sources are the schema for storage.
As a result, my preferred approach is to break the structure for storage up into more granular elements. So each Objective would be its own document, with fixed bindings to "objective", "midYear", "endYear".
There are then a variety of approaches for creating a new entry. One is a single fixed row at the top with a dominoDocument datasource with scope="request" ignoreRequestParams="true". Save can then add the NoteID / UNID to a repeat that then retrieves the values from the relevant document(s) to display / edit.
A more advanced approach would be to have a viewScope variable with an additional option (at beginning or end), then compute the dominoDocument datasource that's within the repeat to either retrieve the relevant document (i.e. action="openDocument") or create a new one (i.e. action="newDocument").
I am trying to get a partial refresh to ONLY refresh the chunk of the page that I need to refresh. I understand that if I do a normal partial refresh the entire JSF lifecycle gets called. I understand that a way around this is to set "Set partial execution mode" and to select the ID I want to refresh.
However I can't get it to work.
Below I have put in a very simple example. When I put a value in the execID then I do not see the refreshed form row. When I don't put the execID in I DO see the values of the form rows, but I believe I am not doing a partial refresh.
I am not understanding something. Any help would be very much appreiciated.
<?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:formRow id="flyApplication" labelPosition="inherit"
label="Application(s)">
<xp:checkBoxGroup id="field1" layout="lineDirection"
styleClass="twoColumnCheckBoxGroup">
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="pnlModules" execMode="partial" execId="pnlModules">
<xp:this.action><![CDATA[#{javascript:var v = getComponent("field1").getValue();
print (v);}]]></xp:this.action>
</xp:eventHandler>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:["Yes","No"]}]]></xp:this.value>
</xp:selectItems>
</xp:checkBoxGroup>
</xe:formRow>
<xp:panel id="pnlModules">
<xe:formRow id="fr2" labelPosition="inherit"
label="Module(s)">
<xe:this.rendered><![CDATA[#{javascript:var v = getComponent("field1").getValue();
if (v == "Yes")
{return true}
else
{return false}}]]></xe:this.rendered>ddd<xp:checkBoxGroup id="field2" layout="lineDirection"
styleClass="fourColumnCheckBoxGroup">
<xp:this.value><![CDATA[#{javascript:"a"}]]></xp:this.value>
<xp:selectItem itemLabel="Values" itemValue="Values"></xp:selectItem>
</xp:checkBoxGroup>
</xe:formRow>
</xp:panel>
</xp:view>
Partial Execution requires that the control that triggers the event be inside the panel that is getting partially executed.
Keep in mind that partial refresh and partial execution are two different things but can be used together if you keep in mind what I said above.
I created a simple repeat control, having inside it 2 simple inputTexts. Outside this repeat control, there is an editable inputText3 ( binded to dataSource ). I'm using it to make some calculations inside the repeat control. The calculations are displayed correctly. I have 2 buttons, for newLine and delete/hideLine. For the moment, those 2 fields inside the repeat control are not binded to the datasource.
i have a button which save the doc., and list it inside a viewPanel, having the first column inputText3, clickable. I noticed that if I open the document ( in edit or read mode ) this editable field value is correctly displayed, but the fields inside the repeat control are all null, even if I add some values before using the save method.
I try also to create 2 fields inside the form ( / datasource ) and binding this inputTexts to them, but again the repeat control fields are empty.
<xp:repeat id="repeat1" var="varRepeat" indexVar="index">
<xp:this.value><![CDATA[#{javascript:parseInt(sessionScope.dField)
}]]></xp:this.value>
...
<xp:inputText id="inputText1"></xp:inputText>
<xp:inputText id="inputText2"></xp:inputText>
The editable field outside the repeat:
<xp:inputText id="number" value="#{docrepeat.valtotala}"
defaultValue="100">
</xp:inputText>
.
<xp:this.data>
<xp:dominoDocument var="docrepeat" formName="docrepeat"></xp:dominoDocument>
</xp:this.data>
I'm definitely missing something here, hope to reach to a functional solution.
Should I bind the 2 inputText using the var property of the repeat?
Or how can I achieve this?
repeat control code:
<xp:repeat id="repeat1" var="test" indexVar="index" rows="8">
<xp:this.value><![CDATA[#{javascript:parseInt(sessionScope.DField)
}]]></xp:this.value>
<xp:panel>
<xp:table >
<xp:tr>
<xp:td>
<xp:inputText id="inputText1">
<xp:eventHandler event="onchange"
submit="false">
<xp:this.script><![CDATA[try
{
var idx="view:_id1:inputText3";
var index=document.getElementById(idx).value;
var number="view:_id1:number";
var val=document.getElementById(number).value;
var sum = val;
for(var i=0;i<index;i++) {
var input1="view:_id1:repeat1:"+i+":inputText1"
var nr1=document.getElementById(input1).value;
sum-=nr1;
document.getElementById("view:_id1:repeat1:"+i+":inputText2").value = sum;
}
// calculating some %
document.getElementById("view:_id1:test").value = parseInt((sum*100)/val);
}
catch(e)
{
alert("not working");
}]]></xp:this.script>
</xp:eventHandler>
</xp:inputText>
<xp:inputText id="inputText2"></xp:inputText>
</xp:td>
</xp:tr>
</xp:table>
</xp:panel>
</xp:repeat>
My little scenario was described here: Xpages how to obtain/create this calculations module
I think your datasource inside the repeat is a view. You need to add a datasource of object data inside the repeat. The way to do this is to create a panel inside the repeat and give that panel a datasource as follows.
<xp:repeat id="repeat1" rows="30" value="#{view1}"
var="rowData">
<xp:panel>
<xp:dominoDocument var="objectData1"
formName="Item"
documentId="#{javascript:return rowData.getNoteID();}"
ignoreRequestParams="true" action="openDocument">
</xp:dominoDocument>
!!!put your stuff in the panel!!!
</xp:panel>
</xp:repeat>
So what is going on is the repeat grabs the datasource which is a view. So it will iterate through all of the entries in the view. But the view datasource does not know what to do with documents. So you create the objectData which will grab the noteID of that specific document and make that available to the repeat as a document(referenced by noteID). Making it available as a document will allow it to save values. You probably won't be able to use the value picker but just type in the field names and it will work.
Not sure I am completely understanding your problem. But you also need to save the datasource. So you could either put a save button in the panel to save that specific document or make the save button save all data sources. I prefer being able to save each document separately as it allows for applications that multiple can edit at the same time.
I've setup a repeater and am reading the value from the multivalue field using GetItemValueArray. This returns the array and If I use a listbox it displays. I want to cross reference some other data with it though so I need to use a repeater. But I'm not sure how to have the repeater use an index that increments for each row. The code below "return rowdata[i]" doesn't recognize i.
<xp:repeat id="repeat1" var="rowdata" rows="30">
<xp:this.value>
<![CDATA[#{javascript:var myArray:Array = myDataSource.getItemValueArray("MyMultiValueFld")}]]>
</xp:this.value>
<xp:label id="lbl">
<xp:this.value><![CDATA[#{javascript:return rowdata[i];}]]></xp:this.value>
</xp:label>
</xp:repeat>
rowdata is not a reference to the myArray value as a whole, but the iterated entry in myArray. In other words... you already have what you need.
<xp:label value="#{rowdata}" />
Maybe you can simplify your code by naming using just the "rowdata" as value for your text item. You then should only change the repeat source to
myDataSource.getItemValue("myValueFld")
as this returns always an array of data. It's just depending on the datatype that this item stores, so you might have to convert in the text control.
Hi there your code has another issue, you do not have any return statement in this line:
<xp:this.value>
<![CDATA[#{javascript:var myArray:Array = myDataSource.getItemValueArray("MyMultiValueFld")}]>
</xp:this.value>
so the code does not return your myArray it only Returns the name of it as a string wich gets repeatet one time. Use this a valueBinding:
value="#{myDataSource.MyMultiValueFld}"
or add a return:
<xp:this.value>
<![CDATA[#{javascript:var myArray:Array = myDataSource.getItemValueArray("MyMultiValueFld");
return myArray;}]>
</xp:this.value>
Then you should be able to use Chris Tooheys Answer:
<xp:label value="#{rowdata}"/>
Use the indexVar property of the repeat control to setup a var containing the index.
Got it. The final piece of code is that I did have to create an indexVar="I" in my repeat1 tag but then I also had to change my label to a computed field. The final piece of code looks like:
<xp:table>
<xp:repeat id="repeat1" var="rowdata" rows="30" indexVar="i" first="0">
<xp:this.value><![CDATA[#{javascript:myDataSource.getItemValueArray("myMultivalueFld");}]]>
</xp:this.value>
<xp:tr><xp:td>
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:var repeat1:com.ibm.xsp.component.xp.XspDataIterator = getComponent("repeat1");
repeat1.getValue()[i];}]]></xp:this.value>
</xp:text>
</xp:td>
</xp:tr>
</xp:repeat>
</xp:table>
don't think I could have gotten it without the tidbit on the indexVar. Thanks
You can trim that code further. If all you need is the values, you don't need the indexvar and you don't need to reference the repeat as an XspDataIterator. Just use the rowdata as a variable.
<xp:table>
<xp:repeat id="repeat1" var="rowdata" rows="30">
<xp:this.value><![CDATA[#{javascript:myDataSource.getItemValueArray("myMultivalueFld");}]]>
</xp:this.value>
<xp:tr><xp:td>
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:rowdata;}]]></xp:this.value>
</xp:text>
</xp:td>
</xp:tr>
</xp:repeat>
Each value in the multi-value field is a "row" as referenced by rowdata. Similarly, if the data source were a view, each row would reference a document object. Don't dispose of the framework available to you by accessing the repeat as a component from inside the component itself.
I am building a custom control using the accordion control included with the Xpages Extension Library. I am attempting to bind to the AccordianPane id and I receive the error:
The value of the property id cannot be a run time binding
The error is referring to this line of code:
<xe:djAccordionPane
title="#{javascript:sectiontitles.getColumnValue('Section')}" id="#{javascript:sectiontitles.getColumnValue('Section')}"
parseOnLoad="false">
I saw Paul Withers post here:
http://www.intec.co.uk/combining-and-an-alternative-approach/
Which makes me think this is possible and that I am just not quite there. Where do I use $ instead of # ?
Here is the code I am using:
<?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.data>
<xp:dominoView var="view1" viewName="MenuLinks"></xp:dominoView>
<xp:dominoView var="view2" viewName="MenuLinksSections"></xp:dominoView>
</xp:this.data>
<xp:panel
style="float:left;padding-left:20.0px;padding-right:20.0px; padding-top:20.0px">
<xe:djAccordionContainer id="djBorderContainer1"
style="width:200px; height:540px" styleClass="soria">
<xe:this.selectedTab><![CDATA[#{javascript:var selectedTab = context.getUrlParameter("tab");
if (selectedTab == "") {
""
} else {
selectedTab
}
}]]></xe:this.selectedTab>
<xp:repeat id="repeat1" rows="30" var="sectiontitles"
value="#{view2}" disableOutputTag="true">
<xe:djAccordionPane
title="#{javascript:sectiontitles.getColumnValue('Section')}" **id="#{javascript:sectiontitles.getColumnValue('Section')}"**
parseOnLoad="false">
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:var id = "#{id:djAccordionPane}";
id}]]></xp:this.value>
</xp:text>
<xp:text escape="true" id="computedField2"></xp:text>
<xp:repeat id="repeat2" rows="30" var="menulinks"
disableTheme="true">
<xp:this.value><![CDATA[#{javascript:var tview = database.getView("MenuLinks");
var v = sectiontitles.getColumnValue("unid");
var vc:NotesViewEntryCollection = null;
if (v != null) {
vc = tview.getAllEntriesByKey(v);
}
vc
}]]></xp:this.value>
<xp:text escape="false">
<xp:this.value><![CDATA[#{javascript:menulinks.getColumnValues()[3]}]]></xp:this.value>
</xp:text>
</xp:repeat>
</xe:djAccordionPane>
</xp:repeat>
</xe:djAccordionContainer>
</xp:panel>
</xp:view>
Any help is appreciated.
Thanks,
Elijah Lapson
It's almost certainly the id property that cannot be a runtime binding. That's because the ID is used by the server to create a map of the elements on the XPage. So it cannot be calculated dynamically using the #.
You won't be able to use $ within the repeat unless repeatContents property is set to true. The $ means it will try to calculate the ID at page load, but the number of elements in the repeat will not have been calculated yet. They'll be calculated dynamically. So you'll need repeatContents="true" on the repeat, so the repeat control's contents are calculated at page load. The repeatControls property can have knock-on implications to things like paging, but it doesn't sound like that's going to be a problem for you.
However, why are you trying to compute the ID? Is it so you can use the ID somewhere in CSJS to get a handle on each individual element? If so, an alternative may be to add a normal HTML element like a div within the djAccordionPane and compute the ID of that. You will not have runtime binding issues with that. Alternatively compute the styleClass property instead. Then you can use dojo.query to select the elements based on the class property. You should be able to use dojo.query(.#{javascript:sectiontitles.getColumnValue('Section')}) to get a handle on the element with the class that matches sectiontitles.getColumnValue('Section')