In a querySaveDocument returns false how do I cause the Submit Action to return 'failed' - submit

I have a regular submit button on a page with this code:
<xp:button value="Submit" id="button3" rendered="#{javascript:compositeData.dsEditBar.isEditable()}" styleClass="label">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="false" save="true">
<xp:this.action><![CDATA[#{javascript:return 'success';
}]]></xp:this.action>
So it returns 'success' which I use in a Navigation Rule ,however, I have a querySaveDocument event that may return true or false. If it returns true return 'success' other wise return 'failed'. How do I capture the return from the QuerySave and pass that to the Navigation Rule?
Right now if the querySave fails it aborts the save and goes back to the view but I want to create a 'failure' Navigation Rule and display an error message in the same document.
Thanks

Related

swagger UI displays "ERROR" and complain about schemaValidationMessages

for me Swagger works absolutely fine but at the end of the web page "Error" button displays.
On click "Error" button it displays
{
"schemaValidationMessages": []
}
Could you suggest me how can I avoid "Error" button and make it to "Valid" button ?

webix: Validating edits from datatable on the server

I have the following scenario:
An datatable with some editable columns which validate for input on the client with the webix rules. There are columns though, that cannot be validated on the client, but on the server only (ie for unique id/code).
An approach would be to create a rule and validate with webix.ajax in synchronous mode that I would prefer to avoid this at all means.
I thought I could validate on 'save'. The server can return a status response with error or success. I can catch this with onAfterUpdate event of the datatable (correct me if there is a better way, but it works this way).
At this point, I would like to display a validation error on the datatable if the server script returns an error status and mark the row (and possibly the corresponding column/cell) with error.
I thought I could use the callEvent method on the datatable and fire a onValidationError event but I didn't manage to make that work.
save: {
url: "save.php",
autoupdate: true,
on:{
onAfterUpdate:function(response, id, details) {
if (response.status == 'error')
myDataTable.callEvent('onValidationError');
}
}
}
The documentation states that I can pass some parameters to the event from callEvent but I could not find any specification on the docs. The code above does not work (the event is not fired).
So the question is: How can I fire a onValidationError event for the datatable using callEvent?
or what would be another approach to use webix to show the error on the datatable with validation on the server side?
Thank you.
Instead of calleing onValidationError event you can use
//mark cell, call after error response
myDataTable.addCellCss(id, columnId, "webix_invalid");
//remove mark, call after success response
myDataTable.removeRowCss(id, "webix_invalid");
which will mark the cell as non-valid.
On a side note, if you want to trigger some event with parameters, you can use code like next. Just beware that triggering an event is not a good way to change the component's state ( it can be used to trigger your own event handler though )
myDataTable.callEvent("event name", [param1, param2, param3])
just

MVC Button Click performs action without redirecting

I have a table where users are allowed to "tick" or "cross" out a row. Ticking a row changes the status value to "Approved" and crossing it changes it to "Disapproved". I'm currently using the Edit scaffold to perform it. How do I do this without having the user being redirected to the view. I just want the user to click it and the page refreshes, with the status value being updated.
I'm not sure what code to post here either since I don't know how to write it. If any part of my program is required, please let me know. I'll include it here. Thank you :>
Add css classes to the 2 buttons "approve-btn" and "reject-btn".
Create javascript function to approve and reject and bind them to
the 2 classes
Create 2 backend functions
Make ajax calls from the JS functions to your backend functions passing the id of the row item
In the "success:" of the ajax call manage the change of the status to show "approved" or "rejected"
To make ajax call you can use the following example (although there are tons of example on google). Since you're modifying data you should use POST call and since it is a POST call, you should add a RequestVerificationToken to prevent CSRF attacks.
function Approve(id){
securityToken = $('[name=__RequestVerificationToken]').val();
$.ajax({
url: '/YourControllerName/Approve/' + itemId,
type: 'POST',
data: {
"__RequestVerificationToken": securityToken
},
success: function (data) {
if (data == 'success')
//use jQuery to show the approved message;
else
alert("something went wrong");
},
error: function (request, err) {
alert("something went wrong");
}
});
}
The Token should be created in the View adding this line:
#Html.AntiForgeryToken()

Activity stream testing

I'm building a activity stream feature in my app, all activities are created via controller methods.
When the controller method is successful the activity is recorder to activity table. Since my controller action is invoked via ajax, I tried posting directly from my rspec test.
I tried this :
Net::HTTP.post_form(URI.parse("http://localhost:5000#{inquiry_path}"), { :id=> #user.id, :type => 'Inquiry' })
This is what I see gets posted in my firebug, when making ajax call:
id:55
type:Inquiry
url:/user_inquiry
So I'm asserting whether the activity count has changed :
it "activity count should be changed" do
PublicActivity::Activity.count.should == 1
end
After I'm done with testing that count has changed, I wanted to see the user home page actually displaying the new notification.
But this test fails :
Failure/Error: PublicActivity::Activity.count.should == 1
expected: 1
got: 0 (using ==)
Just in case I put the puts statement in my controller, to check if the call actually reaches the controller :
puts "Hereeee"
I don't see the message getting printed so I guess the request never reaches the controller, why is that?
Am I doing something wrong here, how can I test this?
My test idea was ok except the part where the request didn't arrive to the controller, here is how I solved it (before and it):
page.driver.post("#{inquiry_path}?id=" + #user.id)
it "post request should return the right response code" do
page.driver.status_code.should eql 200
end
Now my requests are arriving to the controller.

Avoid multiple form submission

In JSF2, is there any way to handle the multiple form submit (user clicks submit button multiple times)? Now we are getting the below exception in server
java.lang.IllegalStateException: Response already committed
java.lang.IllegalStateException: Response already committed
javax.faces.FacesException: socket write error: Connection aborted by peer
That depends on how you're submitting the form. If you're using <f:ajax> or any other Ajax based tag to perform the submit by Ajax, then your best bet is to use jsf.ajax.addOnEvent() to add a function which disables the button when the Ajax request is about to be sent and re-enables it after the Ajax response is retrieved.
E.g. as follows, which you include after the JSF Ajax scripts are included, e.g. inside a <script> or <h:outputScript> referring a .js file in <h:head>.
jsf.ajax.addOnEvent(function(data) {
if (data.source.type != "submit") {
return; // Ignore anything else than input type="submit".
}
switch (data.status) {
case "begin":
data.source.disabled = true; // Disable input type="submit".
break;
case "complete":
data.source.disabled = false; // Re-enable input type="submit".
break;
}
});
If you're not using Ajax to perform the submit, then one of the ways is to throw in a setTimeout() function in onclick which disables the button a few ms after click.
Basically,
<h:commandButton
id="foo"
value="submit"
action="#{bean.submit}"
onclick="setTimeout('document.getElementById(\'' + this.id + '\').disabled=true;', 50);"
/>
The setTimeout() is mandatory, because when you disable it immediately, then the name=value pair of the button won't be sent along with the request which would cause JSF to be unable to identify the action to be executed. You can of course refactor it to some DOM ready or window onload function which applies this for all submit buttons (jQuery would be tremendously helpful in this).
You can add a disabled button on the page which does nothing and show it when the submit button is clicked.
<div id="disabled" style="display:none;">
<span class="disabled-button"/>
</div>
<div id="enabled" style="display:block;">
<span class="enabled-button">
<h:commandLink id="submit"/>
</span>
</div>
$('#submit').live("click", function() {
$('#enabled').hide();
$('#disabled').show();
});

Resources