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.
Related
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();
}
},
});
});
I have two separate textProperty listeners to listen to changes on my javaFX application so it can update a password strength icon, and a valid username icon respectively. Both functions take their data from a TextField (username) and a PasswordField (password). These are the listeners:
if(loginCheck.passwordValidator(password.getText()) == -1) {
passwordImg.setImage(fail);
submit.setDisable(true);
}
if(loginCheck.usernameValidator(username.getText()) == -1) {
usernameImg.setImage(fail);
submit.setDisable(true);
}
I'm trying to get the button (submit) to stay disabled when one or the other functions return -1. I can disable the button when either function has the correct output, but I can't enable the button again without using separate submit.setDisable(false) calls; which falls flat on its face when one listener is trying to enable the button, when it should still be disabled according to the other listener. Is there a way I can set the button to ALWAYS stay off unless both events are true?
Thanks in advance!
Just combine your conditions using logic OR operation -- ||
boolean invalidPassword = loginCheck.passwordValidator(password.getText()) == -1;
boolean invalidUsername = loginCheck.usernameValidator(username.getText()) == -1;
if (invalidPassword) {
passwordImg.setImage(fail);
}
if(invalidUsername) {
usernameImg.setImage(fail);
}
// if at least one of variables is true then submit will be disabled
submit.setDisable(invalidPassword || invalidUsername);
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
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.
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);
}
}
});