Multiple submit buttons, javascript - java

I have a servlet with a form and two buttons. One is a Submit button, the other is a Delete button. The default action is Updater.do, but when I click the Delete button, I have a function to change the action to Deleter.do. This works fine. The problem I have now is that when I put in a confirm dialog, if the user clicks "OK", then it does go on to Deleter.do, as I wanted. However, when they click "Cancel", instead of just staying on the page, it appears to go to "Updater.do". How would I remedy this? I tried deleting the default action and having both Submit and Delete call changeAction, but that didn't work. Here is the javascript chgAction.
function chgAction(action_name) {
if (action_name=="Delete") {
var answer = confirm("Are you sure you want to delete this Person? This action cannot be undone.")
if (answer) { document.forms[0].action = \"Deleter.do\"; }
}
}

Try adding a return false to the "cancel" part:
function chgAction(action_name) {
if (action_name=="Delete") {
var answer = confirm("Are you sure you want to delete this Person? This action cannot be undone.")
if (answer) {
document.forms[0].action = \"Deleter.do\";
}
else {
return false; //ADDED
}
}
}

If both submit and delete are submit buttons, just give them different names. The name of whichever button is clicked will be sent with the request so the server can sort it out.
When calling the confirm dialog, you must return false from the listener or the form will still submit:
<form onsubmit="return chgAction(...);"
and chgAction must return false as suggested by Nivas.

Related

ZK Combobox disable closing

I'm struggling with ZK Framework Combobox UI rendering. I have a combobox with 2 logical lists (1 is a short version of 2, with "Show more" option, and 2 is a list with all entries and no "Show more" option). I've done some list swapping logic tracked by onClick event of "Show more" option. And when I click this option combobox closes and than I need to re-open it to see the full list. So my question is do anyone know a way how to keep combobox opened when I click this specific option (and furthermore, dynamically populate model by another list)? Maybe there are any other best practices of how to do the task more efficiently? Thanks everyone for help
I have a thought about combobox that enables multiple choice — it doesn't close when some option is clicked, but I haven't found any related information. Maybe you could make your suggestions about it
The behavior you want "clicking 'show more' and keep the popup open" is not supported by default.
So you have to override its js widget's doClick_(), please read
https://www.zkoss.org/wiki/ZK_Client-side_Reference/General_Control/Widget_Customization
here is an example.
<zscript><![CDATA[
ListModelList fullModel = new ListModelList(Locale.getAvailableLocales());
ListModelList model1 = new ListModelList(fullModel.subList(0, 2));
model1.add("show more");
]]></zscript>
<combobox id="box" model="${model1}" readonly="true" onSelect="loadAll()"/>
<script src="comboitem-doclick.js"/>
<zscript><![CDATA[
public void loadAll(){
if (model1.getSelection().iterator().next().equals("show more")){
box.setModel(fullModel);
box.setValue("");
}
}
]]></zscript>
/**
* Purpose: when a user selects a specific item, keep the popup open.
* Based on version: 9.6.3
*/
zk.afterLoad('zul.inp', function() {
var exWidget = {};
zk.override(zul.inp.Comboitem.prototype, exWidget, {
doClick_: function doClick_(evt) {
if (!this._disabled) {
var cb = this.parent;
cb._select(this, {
sendOnSelect: true,
sendOnChange: true
});
this._updateHoverImage();
if (this.getLabel() != 'show more'){
cb.close({
sendOnOpen: true,
focus: true
}); // Fixed the onFocus event is triggered too late in IE.
}
cb._shallClose = true;
if (zul.inp.InputCtrl.isPreservedFocus(this)) zk(cb.getInputNode()).focus();
evt.stop();
}
},
});
});

Wicket onsubmit information dialog

I am trying to have wicket display an information dialog after a save button is clicked which invokes an onsubmit that has no access to AjaxRequestTarget target. Here is code snippet
if (trainingmode() && !recordDecision.equalsIgnoreCase("Primary")) {
if (trainingEvalService.compareDecisions(recordDecision, recordSet.getRecordSetId())) {
System.out.println("Validity matchesMaserati: " + trainingEvalService.getTrainingEval().getActual_validity_decision_comment());
// Dialog associated with save button
dialog = new MessageDialog("dialog", "Notice", "Decision Matches " + trainingEvalService.getTrainingEval().getActual_validity_decision_comment() , DialogButtons.OK_CANCEL, DialogIcon.WARN) {
public void onClose(AjaxRequestTarget target, DialogButton button) {
}
};
dialog.open(target) // breaks here without reference to AjaxTarget
} else {
}
}
How can I get a reference to the current AjaxRequestTarget?
Two ways :
If you are doing the form submit through a link, then you can add a SimpleAttributeModifire to it.
Example :
yourLink.add(new SimpleAttributeModifier("onclick","alert('information')"));
This ll display a javascript info, on which you can show the information.
Note :
If you are not submitting from link, then you can do that by putting the submit code in the onSubmit() of a SubmitLink.
You can also use ModalWidow for this, but for that you ll need Ajax submit.
You can use AjaxSubmitLink for that.
You can find ModalWindow code from here:
http://www.wicket-library.com/wicket-examples-6.0.x/ajax/modal-window;jsessionid=2E08EC28B0C0A1AD3F8399628F048003?0

Pass information from popup to main window on Oracle ADF

I have a popup that show a table with data, I am able to select a row, and by pressing a OK button I can retrieve the idNo of the selected row in the table.
What I want to do is to pass this idNo to the window that is calling the popup and update a outputText that is on this window.
Can some one help me?
Code for the button:
newBean Class for the button:
public String b1_action() {
// Add event code here...
System.out.println("Select One Button has been Clicked");
// Get bindings associated with the current scope, then access the one that we have assigned to our table - e.g. OpenSupportItemsIterator
DCBindingContainer bindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcItteratorBindings =
bindings.findIteratorBinding("NameView1_1Iterator");
// Get an object representing the table and what may be selected within it
ViewObject voTableData = dcItteratorBindings.getViewObject();
// Get selected row
Row rowSelected = voTableData.getCurrentRow();
// Display attriebute of row in console output - would generally be bound to a UI component like a Label and or used to call another proces
System.out.println(rowSelected.getAttribute("IdNo"));
setOutputText("" + rowSelected.getAttribute("IdNo") + "");
closePopup("p1");
return null;
}
I want that my function: setOutputText() which is not implemented yet to be able to update my outputText on the main Window.
Thanks
Best Regards
Put the "IdNo" in view or page flow scope depending on how you want to keep the value.
//view scope
AdfFacesContext.getCurrentInstance().getViewScope().put("IdNo", value);
//or page flow scope
AdfFacesContext.getCurrentInstance().getPageFlowScope.put("IdNo", value);
In the window bean, write a listener for the popup dialog:
public void dialogCloseListener(DialogEvent dialogEvent) {
if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.ok)) {
String idNo = AdfFacesContext.getCurrentInstance().getViewScope().get("IdNo");
//now you have the idNo, do whatever you want
}
}
You can also use the returnListener inside the button or link that is invoking the popup like in this article

How to handle extended permissions dialog

I used restfb to check extended permissions of user. I click allow permission dialog will not pop it up again next time. However I clicking "Don't Allow" on the permission dialogue box will bring it back up every time when this page is accessed. I don't want. I want when Clicking "Don't Allow" will stop the dialog forever. please suggest me a way
Here is my code:
Java source:
public boolean getCheckExtPerm() throws FacebookJsonMappingException, FacebookException {
Integer emailPerm = getFbClient().execute("users.hasAppPermission", getFbSigSessionKey(),
Integer.class,Parameter.with("ext_perm", "email"));
return emailPerm == null ? false : emailPerm.equals(new Integer(1));
}
View source:
<script type="text/javascript">
var checkExtPerm = <s:property value="checkExtPerm" />;
if (checkExtPerm == false) {
Facebook.showPermissionDialog('email', function (perms) {
//if (perms == "email" ) {}
});
}
</script>
I don't think this is possible.
And for the better - what happens if the user clicks "don't allow" by mistake? Next time he should be able to allow access.
You can do this in your own application, by not triggering the dialog at all if the user has denied access.

Validate JList Before Selection Occur

Currently, I have a JList listen to list selection listener.
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {
// When the user release the mouse button and completes the selection,
// getValueIsAdjusting() becomes false
if (evt.getValueIsAdjusting()) {
/*
In certain situation, I may want to prevent user from selecting other
than current selection. How can I do so?
*/
}
}
In certain situation, I may want to prevent user from selecting other than current selection. How can I do so?
It seems too late when I receive ListSelectionEvent. But, if I want to do it before ListSelectionEvent happen, I do not know that user is trying to select other.
Here is one of the senario.
The JList is contains list of project name.
So, whenever user select new list item, we need to turn the View, from current project, and display new project.
However, current project may be unsaved yet.
Hence, if current project unsaved yet, we will ask for user confirmation, "Save Project?" (Yes, No, Cancel)
When user select cancel, this means he want to cancel his "select to another project" action. He want to stick with current JList selection.
We will pop up the confirmation dialog box in jList1ValueChanged event handle.
But when we try to stick with current JList selection, it is already too late.
I've implemented this as follows for the same workflow use-case. While it works sufficiently for me, I do wish there was a simpler and more elegant approach where the selection event could be vetoed before proceeding. If I have time to investigate and figure that out I'll repost, but it might rank as a case where the return on investment isn't worth it (i.e. customizing Swing classes, handling lower level mouse/keyboard events directly, etc). Anyway what I'm doing currently is saving the last good 'validated' selection, and reverting back to it if the user cancels a future selection. It's admittedly not the prettiest solution, but it works:
// save the last good (i.e. validated) selection:
private ProjectClass lastSelectedProj;
// listing of available projects:
private JList list;
// true if current selected project has been modified without saving:
private boolean dirty;
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
if (evt.getValueIsAdjusting()) return;
// first validate this selection, and give the user a chance to cancel.
// e.g. if selected project is dirty show save: yes/no/cancel dialog.
if (dirty) {
int choice = JOptionPane.showConfirmDialog(this,
"Save changes?",
"Unsaved changes",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
// if the user cancels the selection event revert to previous selection:
if (choice == JOptionPane.CANCEL_OPTION) {
dirty = false; // don't cause yet another prompt when reverting selection
list.setSelectedValue(lastSelectedProj, true);
dirty = true; // restore dirty state. not elegant, but it works.
return;
} else {
// handle YES and NO options
dirty = false;
}
}
// on a validated selection event:
lastSelectedProj = list.getSelectedValue();
// proceed to update views for the newly selected project...
}
}
I think you would need to override the setSelectionInterval(...) method of JList to do nothing under your special situations.
Handling it at the event level is too late as the event has already occured.
I would suggest that you implement a custom ListSelectionModel.
table.setSelectionModel(new DefaultListSelectionModel(){
#Override
public void setSelectionInterval(int index0, int index1) {
if (dragState==0 && index0==index1 && isSelectedIndex(index0)) {
// Deny all clicks that are one row & already selected
return;
} else {
super.setSelectionInterval(index0, index1);
}
}
});

Categories

Resources