Im making an Xpages application which needs to have server-side validation.
In my form, when a field is cleared and the form submitted - if there is another field which causes the validation to fail - it will be repopulated with the last successfully saved value in the document.
This is not what should happen. The field should stay blank until the page is either refreshed, or the user enters another value.
Does anyone have any idea about what is causing this to happen?
Thanks,
Paul
This depends on your execId and refreshId.
For what happens during partial refresh, read these blog posts, particularly part three http://www.intec.co.uk/tag/partial-refresh/.
If validation (or conversion) fails server-side, the server-side map of the XPage is not updated because the data is not deemed complete enough for server-side processing.
So the partial refresh skips to Render Response, which posts back what HTML should be displayed to the page. That includes values in fields - you're replacing HTML, so it has to.
If you're save button is refreshing the form area, you'll be replacing the HTML there, so overwriting the values entered by the user with the last valid values.
The recommended approach will depend on your page architecture and what you're saving. One is to move validation to the save() function, by which time the values will have been updated in the DominoDocument (the front-end wrapper for the Document on the server). Another is to only refresh the validation area and, if validation was successful, call context.reloadPage() or context.redirectToPage() to effectively skip the partial refresh.
Thanks for the help. As far as I can tell, it was simply due to the way the default converter included with xpages handles the object and/or string. Writing a java custom converter sorted everything out.
Related
There is a sales order record in edit mode.I use window.location.reload() to refresh current page in cilent script after edit some fields value.Then all the data are restored.If I want to reload current page without losing any form data,how to do it?
you can get values which are changed using field change function. Then before reloading function load the record and set the values which are changed and then save the record object.
Actually, we have to understand the functionality and flow of the script first.
Before submitting the record, the data is at the client side ONLY. And to persist the data, you need to save/commit the data in to the Netsuite database.
As soon as the refresh button is hit, it fetches the data from the Netsuite database (which makes sense) and populate the data on to the page.
I hope it clears.
All the best.
I have a simple user registration form which needs to check if the email address already exists - it initially works when I hit the Submit button eg if I enter an existing mail address I get the error, but if I then modify the address to a non-existent one it takes one or two more submits before passing validation. So it seems there is some caching going on somewhere.
I have an isExistingUser function in an SSJS library which simply looks up to the $Users view in the Directory and returns a boolean. Then the XPage source is as follows:
<xp:validateExpression>
<xp:this.message><![CDATA[This user already exists!]]></xp:this.message>
<xp:this.expression><![CDATA[#{javascript:var em = getComponent("inputEM").getValue();return isExistingUser(em)}]]>
</xp:this.expression>
</xp:validateExpression>
How do I force this to work correctly on every submit ie clear any previous values from memory/cache? Many thanks
Use getComponent(“inputEM”).getSubmittedValue() - or even better: use the data source to get the contents of inputEM such as document.getValue(“inputEM”)
I have an xPage that is behaving very oddly. (if xPages get corrupt, I think this one might be) Tell me what you think:
I have editable fields with onChange events that take the value of the field (a company name) and looks into the database to see if the company already exists. If it does not, a field called "isNew" is set to "y". BUT the next time a Full Update is performed, from another field or button, my "isNew" field (or all of them) are erased! Why on earth would a full update erase a totally different field?
Do I need to just recreate this xPage?
============================================================================
Ok, here's the onChange event on the editable field that sets the flag:
var c = currentDocument.getItemValueString("company");
var id = #DbLookup("","AD",tc,11); // this view column gets the doc ID
if (id==null || id==""){
#SetField("isNew","y")
}
This field is being set properly - I use a computed field to display it. But the next full update (button, field, whatever) will erase the "isNew" field.
I think your problem is caused by the data sources you have on your page and how you save them.
Maybe you have data sources that gets binded from the url that should not be.
Are you using data sources within a repeat or view panel? If so, make sure you are only saving the correct data source
JSF (and thus XPages) works best when keeping MVC in mind. So you never manipulate a component, but keep that component bound to a model, like a data source or a scope. This way code doesn't get into each other's way.
A refresh of a page computes the whole tree, not just the updated field, so you need to design your calls carefully.
Work directly with your data source so do this instead of #SetField():
currentDocument.setValue("isNew", "y")
In my JSF based web application I have large number of UI input fields on the forms. I try to save the data in to managed beans(and propagate to the database) by submitting the form via ajax calls while the user is still entering the data on the form. When I have validation errors on the page the ajax submit fails to save data to the backend. The usual validation error is required validation on the input fields. This is an annoying issue for me since if the validation of 50th input field fails the data entered in the first field is also not saved.
In all of UI forms we do have a summary page where we show the user entered data before allowing to submit the form. What I would like to know if it is possible to delay the form data validations until the user goes to the summary page. On summary page I want to either display the validation errors or display the read only version of the data. Did anybody encountered this situation or have a solution to this kind of problem?
Using Lotus Notes designer I have created a form and added a field on that form that does a #DBColumn look up. The form then is viewed through the web browser and everything worked great.
I proceed to add another document to the database using that form, now the original documents still render in the browser fine but the new document doesn't return anything to the field.
I tried removing the #DBColumn look up and just displaying text but nothing I just get 0.
The weird thing is if I rename the field to something diferent everything works perfectly but then if I rename the field back, broken, no calculation.
Does anyone know why this is? It has happened to me with various fields through out my application. I originally thought maybe it was a reserved word thing but I now know that is not the case. I usually just rename the field and move on but there has to be an explanation. Is it a caching thing or what?
Thanks for the info!
You haven't mentioned the type of your fields Is it 'computed for display'? If you have computed for display fields in a form, and the documents already contain data stored in an item with the same name, then the computed formula is bypassed and the item value is displayed as-is.
Fields not calculating could be a caching issue. Try opening the form, edit mode, F9 to recalculate all fields.
If this does not help, close the form, press Ctrl+Shift+F9 to forcefully refresh all views in the DB (could take some time). Reopen your form, edit mode, F9. If the value shows up, try using the "nocache" parameter on your #DBColumn.
Depending on your application design, there could be a number of reasons for the problem. Perhaps the view used for lookup is not set to autorefresh or the server does not refresh often enough because of high load issues.