Save button does not open xe:dialog box [duplicate] - xpages

This question already has an answer here:
Save button using SSJS does not open xe:dialog in web xpage but works on mobile xpage
(1 answer)
Closed 8 years ago.
It is pleasure to ask you directly as you are the one of the author of "Xpages Extension library: Step by Step Guide to the Next Generation of Xpage Component".
This is a link Save button using SSJS does not open xe:dialog in web xpage but works on mobile xpage to a posted question.
In the above post save button is making sure that field has value based on the value of another field. If that field is blank, then this field must have value.
I also tried field validation with computed required value based on another field but that is also not working. Here is a code:
var checkBox31:com.ibm.xsp.component.xp.XspInputCheckbox = getComponent("checkBox31");
if (checkBox31.getValue()== '' | checkBox31.getValue()== null){
return true;
}
{
return false;
}
Your help will be greatly appreciated.
Thanks in advance
Best regards,
Mohan Gangan

As posted in the duplicate question, the checkbox has a value of 'true' or 'false'.
var checkBox31:com.ibm.xsp.component.xp.XspInputCheckbox = getComponent("checkBox31");
if (checkBox31 != null && checkBox31.getValue()== 'false'){
return true;
}else{
return false;
}

Related

Drupal 8 - How to know if the checkbox belonging to a Checkbox Label is checked?

In Drupal 8, I am trying to add a class to a Checkbox Label only if the corresponding checkbox is checked. I am assuming I would have some kind of logic in form-element-label.html.twig to first ensure it is a checkbox label and then some how get at the checkbox to see if the attribute of 'checked' exists.
I can't get this to work and haven't been able to find a solution on the internet, so I am asking here. Apologies for I am a .NET developer and feel like something this simple should be easy to do but I am at a loss.
A preprocess function on form element perhaps.
function MYTHEME_preprocess_form_element(&$variables) {
if ($variables['type'] === 'checkbox' && $variables['element']['#checked']) {
$variables['label']['#attributes']['class'] = ['ckecbox-is-checked'];
}
}

Auto-collapse any item in PrimeFaces PanelMenu on page loading

I'm writing a Primefaces 5.1 portlet.
It consists in a unique page containing a panelMenu, and I need that it starts with any panel collapsed everytime a user change page (on page loading).
But, if I open a panel, then change page, it will start showing that panel still opened.
I wasn't able to find any option to achieve this goal (e.g. collapsed=true, ignoreCookie=true or something similar).
The only solution I found was the following Javascript code:
PrimeFaces.widgets.myPanelMenu.collapseRootSubmenu(PrimeFaces.widgets.myPanelMenu.headers);
The problem is that this code will collapse any opened panel (so on page loading user is able to see panel menu collapsing animation) but it seems it doesn't store this state in its cookie/localstorage... the result is that on any page loading user can see this animation.
I'm sure it doesn't save its state, because the only way to "solve" the problem is to manually re-open and re-collapse the panels... then, on following page change, these menus start closed (and there is no animation).
I also tried to use PrimeFaces.widgets.sideMenuPanel.saveState() after collapsing, but with no success.
Do you have any idea about?
Thank you...
I found a solution to the problem.
If you read my discussion with Kukeltje (comments on my question), you will find that latest Primefaces' versions will solve the problem.
Otherwise, if you want to avoid upgrade or modify sources, and you need a quick fix based on Javascript only please read the following part of the answer.
It directly works on the component's state using JavaScript.
First of all you need to have a variable reference to your component:
<p:panelMenu model="#{menuBackingBean.menuModel}" widgetVar="sidePanelMenu" />
Then you should add the following JS code on document ready:
var panelMenu = PrimeFaces.widgets.sidePanelMenu;
// 1. On page loading collapses possible opened panels
panelMenu.collapseRootSubmenu(panelMenu.headers);
// following line is commented because it never should be necessary is not necessary (unless unexpected situation I never verified)
//clearSidePanelMenuPreferences();
// 2. Call the "clear preferences" actions on click on two tpe of links: first level are the panel link (used to open/close the menu) and second level are the destination links
// We need to fork also on the first level links to be sure it works after user clicks there then exit from the page in another way
panelMenu.headers.children("a").click(function(){setTimeout(clearSidePanelMenuPreferences, 500)}); // setTimeout is necessary because this event should be fired after preferences are written
panelMenu.headers.siblings().find("a").click(function(){clearSidePanelMenuPreferences();});
The function called to clear preferences are the following:
function clearSidePanelMenuPreferences() {
var panelMenu = PrimeFaces.widgets.sidePanelMenu;
panelMenu.expandedNodes = []; // clear the opened panels lists
panelMenu.saveState(); // store this information
}
Hope it helps
Please check this block of code
PF('myPanelMenu').headers.each(
function(){
var header = jQuery(this);
PF('myPanelMenu').collapseRootSubmenu(header);
header.removeClass('ui-state-hover');
}
);
I prefer to do this in order to execute this method only once and keep the menu option selected.
$(document).ready(function() {
if(location.pathname == "/cotizador/" || location.pathname == "/cotizador/faces/login.xhtml"){
var panelMenu = PrimeFaces.widgets.sidePanelMenu;
// 1. On page loading collapses possible opened panels
panelMenu.collapseRootSubmenu(panelMenu.headers);
panelMenu.expandedNodes = []; // clear the opened panels lists
panelMenu.saveState();
}
});

Is there a way to automatically answer a dialog box using formula coding?

Is there a way to automatically answer a dialog box using formula coding? In IBM notes domino - I would like to have some formula code behind a button to automatically answer a dialog box. Is this possible?
Avoid the "would you like to save?" dialog box.
Save your document after you changed all fields in your button.
#Command([EditDocument]; 1);
FIELD Counter := Counter + 1;
#PostedCommand([FileSave]);
#PostedCommand([EditDocument]; 0);
you really have to REWRITE your question which is unclear!
The response with your new comment is:
add in your code : FIELD SAVEOPTIONS:="0" if you want to automatically close the doc WITHOUT saving (look for other options of SaveOptions)
If you have Lotus script code look at The third SaveOptions value, or How to suppress the "Do you want to save this document?" message box in Notes

XPages event code executing twice rather then once

Here’s what I want to do:
On an XPage I want to have an edit box control that calls some server-side code (Java bean or SSJS) when the user presses enter. The main use case for this is that this page will be run from an an iPad and a bluetooth barcode scanner is attached. This scanner emulates a keyboard. The user will tap into the edit box. They will then scan with the scanner and the barcode will be entered along with an “enter” key. The edit box needs to be immediately cleared for the next scan and the value of the scan needs to be processed. The processing will do various backend things to a java bean and then return a message to be displayed on the page. Basically one of these:
1. Item not found, 2. Item is available and assigned, 3. Item is already assigned but you can have it anyway 4. Item Unavailable
I have code for this and overall the core code is working fine. I’ve normally used the onchange event but since I had this problem I moved to the onkeypress event. That was as much an attempt to get it to run in IE. Again the goal is only for the iPad/Safari, but I’d love to get it working on desktop browsers as well. I’m currently testing only with Chome.
In the CSJS piece of the edit box I have this code:
var e = dojo.fixEvent(thisEvent);
if (e.keyCode == dojo.keys.ENTER) {
return true;
} else {
return false;
}
The thinking is that I only want to call the SSJS on Enter.
Here’s the SSJS code that clears the edit box, processes the value and then sets a couple viewScope variables.
// Get the value off the page and put it in to the key variable
var key:String = getComponent("scanBox").getValue();
// clear the scanbox so it's ready for the next scan.
getComponent("scanBox").setValue("");
//Managed Bean to hold the last scan value - since the scanbox is cleared we do want to show the value
Scan.setLastScan(key);
// Managed Bean to process the item.
AddToJob.processItem(key);
viewScope.put("vsShowAssignPanel", true);
viewScope.put("vsShowMessagePanel", false);
The SSJS code is set to partially update the main content of the page. I’m using bootstrap and am trying to refresh everything on the page except a top and bottom nav bar. The editbox itself IS in the partial refresh zone since I’m clearing the value after the scan.
Finally here’s the problem:
The SSJS code of the button is being run TWICE. Not all for some reason but maybe 90% of the time. I’m not clicking twice. The way I test is by using Chrome on my desktop and I paste a value into the field and press enter once on the keyboard.
If I’m trying to scan in and assign an Item with a barcode. It first runs fine. the it updates the objects and saves a field to the backend NotesDocument to mark it assigned. Just want I want. But the second run through hits and it’s deterring that the item is ALREADY assigned and giving me back the wrong message.
After a lot of trial and error I’m fairly certain that something in the JSF lifecycle is causing this to run twice. Why I have no idea. I have no idea how to get it once.
The only good workaround that I’ve found so far is in the “AddToJob.processItem” method. “AddToJob” is a managed bean in the viewScope. In there I store and keep the last barCode. Then I do a check to see of the value is the same. If so then I assume it’s on the second run and stop processing.
I’ve used this basic concept of calling code in the on change event of an edit control for years. But that was inside XPages Mobile Controls and sometimes things do behave a little differently in there. I’m trying to re-write this app to use Bootstrap rather then XPages Mobile controls.
Below is the full XML markup of the edit control if that helps.
<xp:inputText id="scanBox" styleClass="newTarget">
<xp:this.attrs>
<xp:attr name="placeholder" value="Tap to Scan..." />
<xp:attr name="autocorrect" value="off" />
</xp:this.attrs>
<xp:this.dojoAttributes>
<xp:dojoAttribute name="autocorrect" value="off" />
</xp:this.dojoAttributes>
<xp:eventHandler event="onkeypress" submit="true" refreshMode="partial" refreshId="mainPanel">
<xp:this.script><![CDATA[var e = dojo.fixEvent(thisEvent);
if (e.keyCode == dojo.keys.ENTER) {
return true;
} else {
return false;
}]]></xp:this.script>
<xp:this.action><![CDATA[#{javascript:// Get the value off the page and put it in to the key variable
var key:String = getComponent("scanBox").getValue();
// clear the scanbox so it's ready for the next scan.
getComponent("scanBox").setValue("");
//Managed Bean to hold the last scan value - since the scanbox is cleared we do want to show the value
Scan.setLastScan(key);
// Managed Bean to process the item.
AddToJob.processItem(key);
viewScope.put("vsShowAssignPanel", true);
viewScope.put("vsShowMessagePanel", false);}]]></xp:this.action>
</xp:eventHandler></xp:inputText>
ANY information is appreciated. Thank you very much!!!
The Enter key is a special one because pressing enter can also submit the form you are currently in. In this case you actually have two POST requests hitting the server, one for the partial request and then another when the form is submitted.
What you need to do it prevent the enter key from submitting the form using an event.preventDefaults() call. Here is the updated CSJS
var e = dojo.fixEvent(thisEvent);
if (e.keyCode == dojo.keys.ENTER) {
e.preventDefault();
return true;
} else {
return false;
}
Now the form won't get submitted but the partial refresh will fire correctly.
David,
Not really a specific XPages solution but I had to do this in the Notes client - where a barcode was scanned in - it was processed and then the field was cleared and the next one could then be scanned in. The operator was not at the client (its a bluetooth scanner).
My solution and I admit was a bit nasty was to use a NotesTimer - whereby the field contents were checked to see if it was empty or if it had the same value as previously. To make sure I didn't catch a partial scan I did the check twice and if the value did not change then I processed it.
So after all that - couldn't you use a Javascript timer and follow the same logic?
Please forgive me if I'm missing something here, but it seems to me you have set up an unnecessarily complex design.
Why is CSJS or SSJS even needed?
Meaning, have you tried just some simple markup and a bean to do the processing?
Example Markup:
<xp:panel
id="panelbarcode">
<xp:inputText
id="barcode1"
value="#{MyBean.barcode}">
<xp:eventHandler
event="onchange"
submit="true"
refreshMode="partial"
refreshId="panelbarcode" />
</xp:inputText>
</xp:panel>
Example Bean Code:
public class MyBean implements Serializable {
private static final long serialVersionUID = 8541L;
// Zero-Argument Constructor
public MyBean() {}
public String getBarcode() {
// give out a barcode here,
// or return "" for an empty barcode
return "";
}
public void setBarCode(String barcode) {
// process the scanned in barcode
}
}
(edited to get rid of stupid "onClick" event)

How to track opportunity closed as won outside the form,Like from a view

I open a webresource (HTML) when an opportunity is closed as won.
This is triggered only by clicking on the button in the opportunity form.
I use the following code to achieve the same:
function FrmOnSave(prmContext) {
var lclSaveMode;
if (prmContext != null && prmContext.getEventArgs() != null) {
lclSaveMode = prmContext.getEventArgs().getSaveMode();
if(lclSaveMode==5)
{
window.openStdWin(url,"myWindow");
}
However this does not get triggered when the opportunity is closed from the "Open Opportunity" view. Is there a way to achieve the same? Thank you all!
The best thing to do here, would be to hide the existing close button, add a new button which looks the same and does all the same things but also opens that window.
You can debug using IE (F12) to see which javascript function is being called on your case, or what is actually happening.
#James Wood answer is a good advice though, it is the safest way to achieve what you want.

Resources