Set message inside the add dialog in jqgrid if error occurs - error-handling

I am returning the following from my action (asp mvc) if error occurs upon adding the record to jqgrid
return new HttpStatusCodeResult(400, "item not found");
It's all great but the message displayed inside the add dialog is
"error Status: 'Workorder not found'. Error code: 400"
Is there any way to just show the "Item not found" message only?
It looks like the js never goes to afterSubmit routine in add options. Any way to gain the control and make sure that only the actual error message shows? Something like onError option would be great!

You can use errorTextFormat callback of form editing or jqGridAddEditErrorTextFormat event of jqGrid to control the format of the text from the error message. The first parameter of errorTextFormat callback (or the second parameter of jqGridAddEditErrorTextFormat) is jqXHR Object which is superset of XMLHttpRequest. The responseText property of the parameter is the text of the response body.
Moreover you should not use HttpStatusCodeResult for error description. Instead of that you should place the error description in the body of HTTP response. You can use WebFaultException for example to do this:
return throw new WebFaultException<string> (
"item not found",
HttpStatusCode.BadRequest); // 400
By the way the HTTP status code 404 (HttpStatusCode.NotFound) seems me more corresponds to the error "item not found".

Related

Geb If Else or try catch handling

I am new to Geb spoke testing and I have a test that ui send message and receive text or email, I have an api call that grabs the sent email/text, I need to use that response and continue in the UI testing. but that response is expired since the api is fast and its getting the previous sent message which (before my ui send that email/text) and the last sent makes the previous expired. so my question is I need to call that api again if the message is expired, I tried if else and waitFor methods but couldn't come up with solution, I use page objects and test specs and I cannot create that as a method since that is happening on one page and in one def class and which I cannot even do waitFor in my test class which results IllegalMonitorStateException
when: "I enter text code"
String text = response.getText()
testPage.enterCode << text
testpage.pager.clickNext() // here is happening the code expiration and couldn't get to the next page,
then: "I am in next page"
at nextPage // if am not on the next page I need to make a new api call to get the newest response
I tried
when: "I enter text code"
String text = response.getText()
testPage.enterCode << text
testpage.pager.clickNext()
def erroHappened = testPage.errorAlert.isdisplayed
then: "I am in next page"
!errorHappened && testPage.enterCode << response.getText()
How can I use the wait or try catch or if else to solve this issue, Thank you in advance

Dojo Dialog with confirmation button with a widget as content

Im trying to implement generic dojo confirmation dialog. I found great resource in stackoverflow on how to do it in link: Dojo Dialog with confirmation button
The sample which is mentioned in the above link works absolutely fine as in http://jsfiddle.net/phusick/wkydY/ .
Now that i wanted to extend this to support more complicated widget containing dojo data type and dojo attach points inside this dialog. I try to achieve this by setting the message of the dialog.
i.e.
message: "<div data-dojo-attach-point='myAttachPoint'><button data-dojo-type='dijit/form/Button' type='button'>Click me</button></div>";
(see this code at here : http://jsfiddle.net/wkydY/304/)
When I do that and clicking on MessageBox.Confirm' button doesnt bring up the dialog box as it would in the original version. What exactly am i doing wrong or missing a step in here?
(edited : based on comment)
You have a syntax error here
var confirmDialog = new ConfirmDialog({
title: "My Title",
message: "<div data-dojo-attach-point='myAttachPoint'><button data-dojo-type='dijit/form/Button' type='button'>Click me</button></div>";
});
as there should not be a semicolon in an object definition, i.e. after message: '...';
Also, as you are using non-AMD Dojo, you should put type="dijit.form.Button" into the message.
So the correct version of the lines above is:
var confirmDialog = new ConfirmDialog({
title: "My Title",
message: "<div data-dojo-attach-point='myAttachPoint'><button data-dojo-type='dijit.form.Button' type='button'>Click me</button></div>"
});
See it in action: http://jsfiddle.net/phusick/wkydY/305/

selenium : how to handle error messages that get displayed when we dont give credentails

I am new to selenium, and when testing a web application I want to check when credentials are wrong the message in alert which gets displayed and the error message that is displayed on the page after accepting the alert are same or not please can anybody help me how can I do this
I have handled alert using
web.swichto.alert().accept
but I want to compare the message that alert displays and the error message that is displayed in that page like
Error: Invalid User ID/Password Or Network Is Down!
and message in alert box like
Invalid username/password
thanks in advance
you can store text present in the alert into a variable as follows,
String msg_in_alert=driver.switchTo().alert().getText();
then you can use assert to compare,
Assert.assertEquals(driver.findElement(By.cssSelector("selector_of_error_element")).getText().compareTo(msg_in_alert), true);
"true" specifies that the text should match..
If text does not match,it will result in step failure...
WebElement element = _driver.findElement(By.xpath("//span[#class='ng-binding error-class ng-hide']"));
element.getText();
if(element.equals("Recall and Volume data does not exist for calculation. Please upload the data.")){
System.out.println("true");
}else{
System.out.println("false");
}
WebElement mandmessActionName = driver.findElement(By.xpath("//*[#id='container']/div/form/div[1]/div/fieldset/div[1]/div/span[1]"));
String mandmessActionName1 = mandmessActionName.getText();
if (mandmessActionName1.equals("Action Name is required."))
{
System.out.println("true");
}
else
{
System.out.println("false");
}

XPages - why are Dojo Filtering Select controls obligatory? Can they be customised?

I am using some Dojo Filtering Select controls on my XPage. Despite having set the required property to false, when I attempt to save the XPage document, I see the message "This value is required" in the Dojo Filtering Select control. I would like to know
1/ is it possible to make a Dojo Filtering Select control NOT obligatory?
2/ Is it possible to customize the error message which appears when the control is obligatory?
1) You get the message "This value is required" at client side validation. So, in addition to property required="false" which is responsible for server side validation only you have to set a dojoAttribute "required" to "false". Then you don't get the message anymore.
<xe:djFilteringSelect
id="djFilteringSelect1"
value="#{...}"
required="false">
<xe:this.dojoAttributes>
<xp:dojoAttribute
name="required"
value="false">
</xp:dojoAttribute>
</xe:this.dojoAttributes>
</xe:djFilteringSelect>
2) The same way you can set the dojoAttribute "missingMessage" to the string you like in case your control stays obligatory.
you can customized these parameters (They are in the parent ValidationTextBox of FilteringSelect):
// required: Boolean
// User is required to enter data into this field.
required: false,
// promptMessage: String
// If defined, display this hint string immediately on focus to the textbox, if empty.
// Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
// Think of this like a tooltip that tells the user what to do, not an error message
// that tells the user what they've done wrong.
//
// Message disappears when user starts typing.
promptMessage: "",
// invalidMessage: String
// The message to display if value is invalid.
// The translated string value is read from the message file by default.
// Set to "" to use the promptMessage instead.
invalidMessage: "$_unset_$",
// missingMessage: String
// The message to display if value is empty and the field is required.
// The translated string value is read from the message file by default.
// Set to "" to use the invalidMessage instead.
missingMessage: "$_unset_$",
// message: String
// Currently error/prompt message.
// When using the default tooltip implementation, this will only be
// displayed when the field is focused.
message: "",
If you set required to false, it should not prompt message, can you post you code.

Apache wicket validation

I have custom validation added to my page, and this validation is called from business logic layer, after I click "Save" button on UI, which is AjaxSubmitLink.
On my page I have apache wicket DateTimeField, but it's validation doesn't work correctly: error message doesn't appear in FeedbackPanel, which is added on page and my custom validation is shown there correctly.
So for example I fill hours field with "321" and I will have error in console:
WARN org.apache.wicket.protocol.http.WebSession -
Component-targetted feedback message was left unrendered. This could
be because you are missing a FeedbackPanel on the page. Message:
[FeedbackMessage message = "Translation for key [hours.RangeValidator]
is not found for language [en]!", reporter = hours, level = ERROR]
Maybe someone had similar problems and have solution for this?
Thanks!
Because you do an Ajax-Request you have to add the feedback-panel to your AjaxRequestTarget (so it will update itself on every request).
You have to override the onError method though:
add(new AjaxSubmitLink() {
#Override
protected void onError(final AjaxRequestTarget target, final Form form) {
target.addComponent(yourFeedbackPanel);
}
}