xpages decimal separator EditBox - decimal

I have a very very simple source code:
<xp:inputText id="inputText3"
value="#{document1.A}"
defaultValue="5.5" type="number">
<xp:this.converter>
<xp:convertNumber type="number">
</xp:convertNumber>
</xp:this.converter>
</xp:inputText>
If I use a European Browser (that use the comma separator for decimal number) only the first time (when load the page) I see the correct information on the field.
If I refresh (partialrefresh for example) the InputBox...I see 55
With USA Browser all work correctly (where the pound is a decimal separator)
I have try play with converter without success...
Have you some suggest to fix this problem?
Tnx a lot

I have solve my problem. The really problem was HTML5 attribute type=number that force with dot my number...
SO that I have created a custom converter and now work correctly:
<xp:inputText value="#{document1.valore}" id="valore1"
type="number" immediate="false" defaultValue="5.5">
<xp:this.converter>
<xp:customConverter
getAsString="#{javascript:value.toString()}">
<xp:this.getAsObject><![CDATA[#{javascript:parseFloat(value.replace(/,/g,"\."))}]]></xp:this.getAsObject>
</xp:customConverter>
</xp:this.converter>
</xp:inputText>
So work if you insert , or . in the inputtext
P.S. Chrome have the problem with the decimal value that don't render the value into the inputbox

I'm not sure if this is correct, but it sounds like the server is sending 5.5 to the browser. However, during the partial refresh, the European browser identifies the "." as a thousand separator so sends the value back to the server as 55, which is then written back to the underlying datasource as 55 and passed back to the browser as 55.
You might be able to confirm that by checking the post data from the browser or adding a custom validator that just prints the submittedValue for the component. It would need to be a validator or converter, in order to run in the Process Validations phase, and so before the value is converted and written back to the field. Server-side 5.5 should be dealt with the same way regardless of the browser.

Related

How to add Today() in DojoDateTime in XPages

I would like to add today functions anywhere in this component which sets the field as Today.
is it possible to do?
COMPONENT CODE:
<xp:inputText id="EvrakUlasimTarih" value="#{document1.EvrakUlasimTarih}"
valueChangeListener="#{changeRequestBean.valueChangeListener}" dojoType="dijit/form/DateTextBox" styleClass="fs-12 datetimeStyle">
<xp:dateTimeHelper id="dateTimeHelper2"> </xp:dateTimeHelper>
<xp:this.converter>
<xp:convertDateTime type="date" dateStyle="short">
</xp:convertDateTime>
</xp:this.converter>
</xp:inputText>
The component is open source, so yes, it's possible. I'm not aware of anyone who's extended the control to do that though. I suspect you would need to extend the renderer and add a function to jump to today's date in the JavaScript library incorporated by the renderer, but I may be over-simplifying it.
Can you set the default value of the inputText to #Today()? May be this set the component to the current date

Only Allow TypeAhead Values in InputText Field

I'm trying to figure out how to limit a user to TypeAhead values in an InputText field. One thought I had is to run logic onblur that would check the value in the field against acceptable values. My inputText and typeAhead code is below:
<xp:inputText id="TypeAhead">
<xp:typeAhead mode="partial" minChars="2" ignoreCase="true">
<xp:this.valueList>
<![CDATA[#{javascript:db = new Array(#DbName()[0], 'names.nsf');
return #DbColumn(db, "($VIMPeople)", 1)}]]>
</xp:this.valueList>
</xp:typeAhead>
</xp:inputText>
Thanks in advance for any ideas.
Have you tried a dojo FilteringSelect? It's like a combination of a combo box and a type ahead edit box. ExtLib comes with an Xpages version of it.
In case you're not familiar with that you might want to take a look here:
https://dojotoolkit.org/reference-guide/1.10/dijit/form/FilteringSelect.html#dijit-form-filteringselect

Cannot get Repeat control to break out multi-value field

What I am trying to do should be very simple. I have a multi-value text field called activityLog. The field is set via a java method when various things happen. If I look at the backend data, it clearly is a multivalue field.
I went through the steps in Dave Leedy's Notes-in-9 #14, as well as tried to follow Tommy Valand's blog post here --> http://dontpanic82.blogspot.com/2011/03/repeat-controls-and-multivalue-fields.html. Neither seems to work for me. The result is that they list contents that are concatenated together in both cases.
The values ARE returned as a VECTOR. I can verify this by getting the size(), and by isolating specific elements using elementAt(). I was about to just make a for loop to get around this, but I want to know why it is failing. Repeats always seem to give me trouble. I was also want to leave straight forward code for me or future developers. There is probably something easy that I am missing.
<xp:repeat id="repeat1" var="rowData">
<xp:this.value><![CDATA[#{javascript:document1.getItemValue("activityLog")}]]></xp:this.value>
<xp:text escape="true" id="computedField14" value="#{javascript:rowData}">
</xp:text>
</xp:repeat>
UPDATE: The Repeat control is reading the Vector, but is NOT adding a new line automatically after each iteration. Trying to add a new line manually is not working, having tried JS "/n" & "/r" and #NewLine()
The use of <br/> or <xp:br /> suggested by Tim is an effective approach. But consider fixing the issue in the <xp:text/ > element instead.
The <xp:text />element creates a <span /> in the output HTML by default. Spans are, by default, displayed inline meaning that they do not have a line feed ahead of them. But you can add a CSS rule to the element which makes it a block element instead of inline. Add this CSS using a style tag: <xp:text style="display:block;" />or in a CSS class that include the rule {display: block}
A final way is to tell the the page to render a <div /> tag instead of a <span /> tag. DIVs are, by default, block elements. Do this with: <xp:text tagName="div"/>. (however, be careful because the default behavior of both DIVs and SPANs can be changed).
Browsers ignore whitespace except inside tags specifically intended to display whitespace. Add a break tag (<br />) or component (<xp:br />) inside the repeat, and the browser will display a new line for each iteration of the repeat.
There is a simple way of breaking out a multivalue fields, you only missed one thing. Accessing each row, I've added the rowColl variable indexVar="rowColl" and so you access it rowData[rowColl]
<xp:repeat id="repeat1" var="rowData" indexVar="rowColl">
<xp:this.value><![CDATA[#{javascript:document1.getItemValue("activityLog")}]]></xp:this.value>
<xp:text escape="true" id="computedField14" value="#{javascript:rowData[rowColl]}">
</xp:text>
</xp:repeat>

Dynamic binding within a repeat control

In a purchase order module, we need to ask certain questions depending on the source selection method, competition type and total cost of the PO. These questions are likely to change over time and in between different instances of the database.
So I have a view containing the questions, so that I can add questions dynamically to my XPage without needing to change the code. The answer to each question will be stored in a field. So, the document that contains the question has a field called FieldName that is used to supply the field name that will be used. Unfortunately, I am having no luck binding these dynamic fields to the document.
<xp:this.data>
<xp:dominoView var="competitionQuestionView"
viewName="CompetitionQuestions">
</xp:dominoView>
</xp:this.data>
<xp:repeat id="repeat2" rows="30" var="rowData" style="width:700px"
value="#{competitionQuestionView}">
<xp:label id="label1">
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("Question");}]]></xp:this.value>
</xp:label>
<xp:inputText id="inputText1">
<xp:this.rendered><![CDATA[#{javascript:rowData.getColumnValue("FieldType") == "Text Box"; }]]></xp:this.rendered>
<xp:this.value><![CDATA[#{javascript:poDoc[rowData.getColumnValue ("FieldName")];}]]></xp:this.value>
</xp:inputText>
</xp:repeat>
I've tried various ways to do this, including making a dynamicInputText custom control to pass in the field name, but without luck. The closest I got was when I used this:
<xp:this.value>
<![CDATA[#{javascript:tmp = rowData.getColumnValue ("FieldName");'#{poDoc.'+tmp+'}';}]]>
</xp:this.value>
That gave me something like #{poDoc.justification}, which was what I wanted to pass to the 'binding', but it ended up displaying as the text value.
I did try using $ to compute the value on load, but I am guessing that it didn't work because my (and the rowData) view is not available on load. That would eventually present a problem when I wanted to use partial refreshes due to updates on the criteria for which fields I want to display anyway.
Some of the answers to other questions looked promising, but no code was provided, so I couldn't figure it out.
Behind the scenes, all data sources use the methods getValue and setValue to (respectively) read and write data. In the case of a Domino document data source, the expression #{currentDocument.fieldName} gets translated at runtime to either currentDocument.getValue('fieldName') or currentDocument.setValue('fieldName', postedValue), depending on whether the current operation is a read or a write.
If you set the value attribute of an otherwise editable component to a SSJS value binding, then it can't do this auto-translation... so it just treats every operation as a read.
In other words, for read/write to work, it has to be a "prefixless" expression.
There are several ways to handle this, but the easiest is to use a data context to map a SSJS expression to a single variable. Data contexts can be attached to the view root or to a panel, so in your example, you'd want to wrap your repeat contents in a panel:
<xp:repeat id="repeat2" rows="30" var="rowData" style="width:700px"
value="#{competitionQuestionView}">
<xp:panel>
<xp:this.dataContexts>
<xp:dataContext var="fieldName">
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue ("FieldName");}]]></xp:this.value>
</xp:dataContext>
</xp:this.dataContexts>
<xp:label id="label1">
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("Question");}]]> </xp:this.value>
</xp:label>
<xp:inputText id="inputText1" value="#{poDoc[fieldName]}">
<xp:this.rendered><![CDATA[#{javascript:rowData.getColumnValue("FieldType") == "Text Box"; }]]></xp:this.rendered>
</xp:inputText>
</xp:panel>
</xp:repeat>
So for each member of the repeat, the variable fieldName becomes the column value for that row. Then in the value attribute of the input component, the array syntax is used (instead of the usual dot syntax) since we want to use a variable to specify the field name instead of hardcoding the name.
In theory, however, you should be able to skip the data context entirely, and just set the following to be the value expression for the field:
#{poDoc[rowData.FieldName]}
In the context of the default ("prefixless") EL resolver, rowData.FieldName should return precisely the same value that rowData.getColumnValue("FieldName") returns in the context of a SSJS expression.
Finally, I would recommend reading this Expression Language tutorial to become familiar with all of the things that you can do in core EL without resorting to SSJS.

Dynamic Table from Lotus Notes to XPages within a form

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.

Resources