adding errors to FacesContext.getCurrentInstance().addMessage shows message but doesn't prevent from processing - jsf

I'm validating data selected in a dropdown - ice:selectOneMenu on a form. On the valueChangeListener. I have validation which adds an error message:
FacesContext.getCurrentInstance().addMessage(fieldId,
new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
The validation works on the Bean and the error message is displayed to the user but when the "Save" commandbutton is clicked, the page continues the confirm page when it's suppose to stay on the capture page until the correct value is selected in the dropdown.
Why does the page continue to confirm the page?

When validation fails, you have to throw an ValidatorException so that the input can be treated as invalid one. That's most likely the cause. Instead of
FacesContext.getCurrentInstance().addMessage(fieldId,
new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
do
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));

Related

NetSuite beforeload cancel action

I have a userevent beforeload that conditionally removes print buttons. If users are in the list view they are still able to print from that menu. So I was wondering if anyone knows of a way to either intercept the request and redirect or notify them, or even change which pdf template is used.
Here is my code snippet:
if (scriptContext.type === scriptContext.UserEventType.PRINT) {
if(status == 2){
log.debug({
title: 'Trying to Print Approved PO',
details: status
});
return true;
}
else{
log.debug({
title: 'Trying to Print UnApproved PO',
details: status
});
//code here to redirect users, notify them of issue or change to different pdf template
return false;
}
}
While not ideal, I just threw an error and didn't catch it.
throw 'This error is a result of trying to print a PO that has not been approved.';
You can add checkbox field on the UE beforeLoad event and set the value true/false if the user can/can't generate the pdf. Then control the new field on the freemarker AdvPDF and instead of print the content, you can show a message if the user can't generate the pdf.
var field = objForm.addField({
id: 'custpage_allow_access',
type: serverWidget.FieldType.CHECKBOX,
label: 'Allow access'
});
field.defaultValue = "F";
field.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});

What's the difference between endDialog() and endConversion() in Bot-Framework (node.js)?

I am confused with endDialog() and endConversion() when using bot-framework.
What's the difference between them?
If I don't invoke them, just using send()? What constraint will be?
When inside a dialog, you can invoke some other dialog. For e.g.
bot.dialog("/", [
function(session, data, next()){
session.send("Hi");
if(session.message.text === "hello"){
// starts a new dialog
session.beginDialog("helloDialog");
next();
} else {
next();
}
}, function(sesion, data){
session.send("end of root dialog");
}
]);
bot.dialog("helloDialog",[
function(session){
session.send("inside the hello dialog");
session.endDialog(); // explicitly ends the dialog
}
])
When user input is hello, output is
Hi
inside the hello dialog
end of root dialog
When user input is anything else, output is
Hi
end of root dialog
session.endDialog ends the current dialog, and resumes the parent dialog.
session.endConversation ends the conversation itself.
In Technical terms, when a dialog is called, the dialog moves into a stack called dialogStack. When another dialog is called from current dialog, that new dialog is placed at the top of dialogStack. When this new dialog completes its operation, this dialog is popped from the stack, and the last dialog resumes.
When session.endConversation is invoked, the dialog stack is emptied right away (this is a behavior am not fully sure though)

ADF af:inputText constantly getting focus after validation

After doing a programatic validation on a row in a table, the field that has the validation error keeps taking focus
FacesContext context = FacesContext.getCurrentInstance();
input.setValid(false);
context.validationFailed();
context.addMessage(input.getClientId(context),
new FacesMessage(FacesMessage.SEVERITY_WARN, "Message", null));
I have immediate set to true, but that doesn't work.
How can I fix this?
Thanks.
Try to drag and drop the table again or check if autosubmit=true

Close a dialog on clicking CANCEL button ignoring EN_KILLFOCUS

I have a CEdit field in my dialog where I have implemented EN_KILLFOCUS, so when the user enters invalid data a warning message is displayed when the focus moves away from this field and the focus returns to the CEdit field so that the user can enter proper data. If the user enters invalid data and clicks on the CANCEL button, then also a warning message is displayed which is undesirable because the user is anyway trying to cancel his actions. I have tried implementing PostQuitMessage when the user clicks on CANCEL button, but this closes the entire application. I want only my dialog to close when the user clicks CANCEL button. Is there any way that I can close the dialog instantly after I click on CANCEL button. This is the code that I tried.
void CMARPropWnd::OnParentNotify(UINT message, LPARAM lParam)
{
CCDialog::OnParentNotify(message, lParam);
// TODO: Add your message handler code here
CPoint ptButtonDown(LOWORD(lParam),HIWORD(lParam));
if ((message == WM_LBUTTONDOWN) && (ChildWindowFromPoint(ptButtonDown) == GetDlgItem(eMARPropWndCancelBtnId)))
{
PostQuitMessage(0);
}
}
Try
OnCancel();
instead of PostQuitMessage(0);
Note that OnCancel() is a virtual method of CDialog, so this is the "most correct", and will do any special code that may override the default CDialog behavior.

How to "chain" modal dialogs in YUI 2?

I have a modal dialog box presented in Yahoo UI. The user selects a value from dialog "A", and then I want to present another modal dialog box to collect some more data in dialog "B".
I have been using the YAHOO.widget.Dialog successfully. The problem seems to be that you can't initiate dialog window "B" from the handler function of dialog "A". So, how can you programmatically launch a second dialog window after the user hits the "OK" button on the first ?
(I had tried to create an additional Listener for a field that is updated in dialog "A" to trigger dialog "B" but this doesn't work either.)
Thanks..
Check out the documentation: http://developer.yahoo.com/yui/container/dialog/#events. The following code should do the trick:
var firstDialog = new YAHOO.widget.Dialog('firstDialog', { postmethod: "manual" });
firstDialog.manualSubmitEvent.subscribe(function (type, args) {
var nextDialog = new YAHOO.widget.Dialog('nextDialog', { });
/* more configuration stuff... */
nextDialog.render();
nextDialog.show();
});
firstDialog.render();
firstDialog.show();
This handles when the form is to be submitted, which I think what you mean by selects a value, but if not let me know and I can give some help on that situation.

Resources