I can open a dialog programmatically in primefaces like this post :
Primefaces open closable dialog programmatically
I can open another dialog into my dialog too ! but when I want to close it with this code it won't close !
RequestContext.getCurrentInstance().closeDialog(null);
and I can't click on anything
it happen only when I open 2 dialogs into each other
index.xhtml
<p:commandButton value="Open First Dialog" process="#form" update="#form" actionListener="#{mybean.openFirstDialog}"/>
mybean.java
#Component
#Scope("session")
public class MyBean{
public void openFirstDialog() {
RequestContext requestContext = RequestContext.getCurrentInstance();
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
options.put("width", "850");
options.put("contentWidth", "520");
options.put("closable", false);
options.put("resizable", false);
requestContext.openDialog("/page/firstdialog", options, null);
}
}
firstdialog.xhtml
<p:commandButton value="Open Second Dialog" process="#form" update="#form" actionListener="#{firstDialogBean.openSecondDialog}"/>
FirstDialogBean.java
#Component
#Scope("view")
public class FirstDialogBean{
public void openSecondDialog() {
RequestContext requestContext = RequestContext.getCurrentInstance();
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
options.put("width", "850");
options.put("contentWidth", "520");
options.put("closable", false);
options.put("resizable", false);
requestContext.openDialog("/page/seconddialog", options, null);
}
}
seconddialog.xhtml
<p:commandButton value="Close Second Dialog" process="#form" update="#form" actionListener="#{secondDialogBean.close}"/>
secondDialogBean.java
#Component
#Scope("view")
public class SecondDialogBean{
public void close() {
RequestContext.getCurrentInstance().closeDialog(null);
}
}
actually i don't pass NULL while I'm closing dialog ! I do stuff and pass an object ! but I can't write full code here
then while I close second dialog I can get that Object in first Dialog and again do some stuff
I hope I could say what I mean
and after clicking "Close Second Dialog" it stuck !
I tried this too but no use :
RequestContext.getCurrentInstance().closeDialog("/page/seconddialog");
You need to name what dialog you are closing like...
RequestContext.getCurrentInstance().openDialog("titleEdit", options,
null);
RequestContext.getCurrentInstance().closeDialog("titleEdit");
See this example for having two dialogs open at once and how to close them.
Related
Using Zk 6.5.11CE.
In a modal window I got a button which clicked send an email. It is a long operation, and in waiting time I want to use Clients.showBusy to block the user to click/modify my modal window.
Here's the ZUL
<window apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('viewmodel.EventView')">
...fill the form...
<button label="SEND" onClick="#command('send')" autodisable="self" />
</window>
Here's Java EventView.java
#Command
#NotifyChange("*")
public void send() {
Clients.showBusy(winFather.getModalWin(), "Please wait...");
// ... do something ...
sendMail(); // it takes 2/3 seconds
Clients.clearBusy(winFather.getWinEvent());
}
Where winFather is the win (my home page) that called the modal window and getModalWin() get the modal window, in which i got the showBusy problem. Hope it is clear :)
However, i'm searching the web and found something interesting here and here. So I got I have to use Echo Events.
For those had not clicked links:
<window id="w" width="200px" title="Test echoEvent" border="normal">
<attribute name="onLater">
doLongOperation(); //take long to execute
Clients.clearBusy(); //remove the busy message
</attribute>
<button label="Echo Event">
<attribute name="onClick">
Clients.showBusy("Execute..."); //show a busy message to user
Events.echoEvent("onLater", w, null); //echo an event back
</attribute>
</button>
</window>
Question(s):
is Echo Events the only chance to resolve the problem, or maybe I forgot to do something to make showBusy properly works?
because I really don't want code in my zul page, how can I define the stuff in my viewModel?
If i assign with binded value
disabled="#load('vm.busy')"
to all components I want to disable during email sending, and substitute Clients showBusy and clearBusy with
busy = true; // Clients.showBusy(winFather.getModalWin(), "Please wait...");
...
busy = false; // Clients.clearBusy(winFather.getModalWin());
I got the same problem, the email is sending before zul components were disabled. It seems to be a sync problem.
hi
i had same problem before , in my code you can see that I've override onClientInfo on my target component,so if you call this event , you can reach your goal.
#Listen("onClick = #addRejectDocumentBtn")
public void openWaiting() {
Clients.showBusy(saleRejectMainPageWin,"please wait...");
saleRejectMainPageWin.addEventListener(Events.ON_CLIENT_INFO, new EventListener<Event>() {
#Override
public void onEvent(Event event) throws Exception {
LongOperationExample(); <- here is my long operation
Clients.clearBusy(saleRejectMainPageWin);
}
});
"Here you can call the event"
Events.echoEvent("onClientInfo", saleRejectMainPageWin, null);
}
I have a situation where i need to download a excel file. So i user Window.open for that. The problem is i need to check whether the file is exsist in the server location before call the Window.open. So when user click the download buton below call happens,
public void onClick(Button button, EventObject e) {
final String url = GWT.getModuleBaseURL() + "fileupload/dailyLogReport?param1=param1
openFileDownloadWindow(url,fileName);
}
public void openFileDownloadWindow(final String url,String fileName){
CommonServiceAsync serviceAsyn = CommonService.Util.getInstance();
final AsyncCallback callback = new AsyncCallback() {
public void onSuccess(Object result)
{
isFileExsist = (Boolean)result;
if(isFileExsist){
Window.open( url, "_blank", "status=0,toolbar=0,menubar=0,location=0");
}else{
Window.alert("File not found.");
}
}
public void onFailure(Throwable caught)
{
MessageBox.alert("Error", "Error while getting data"
+ caught.getMessage());
}
};
// calling of the action
serviceAsyn.isDailyLogFileExsists(fileName, callback);
}
But the problem is if i put the Window.open inside the success it just open a Window and getting it close quickly with out download the file. But if i put the Window.open directly in onClick method it successfully open the window pop up and download the file successfully. But Since i have to download the file conditionally by checking whether the file is exists or not I can not put the Window.open inside onClick.
What is the reason Window.open not working properly inside the call back success function?
The problem is popup blocker.
When you click on a element you can open a new window since the browser considers it is a deliberate user action to open the window.
Otherwise, the browser blocks any window.open in asynchronous blocks, because it considers that it could be malicious code run out of the user control.
The best solution, is to open the file in an iframe, but you have to set the appropriate content-disposition header in server side which causes the browser to show the "Save" dialog.
Client Code:
// Create a new iframe
final Frame f = new Frame();
f.setUrl(url_to_my_excel_file");
// Set a size of 0px unless you want the file be displayed in it
// For .html images .pdf, etc. you must configure your servlet
// to send the Content-Disposition header
f.setSize("0px", "0px");
RootPanel.get().add(f);
// Configure a timer to remove the element from the DOM
new Timer() {
public void run() {
f.removeFromParent();
}
}.schedule(10000);
Server Code:
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
[...]
// Set the appropriate type for your file
resp.setContentType("application/vnd.ms-excel");
// Mandatory if you want the browser open the save dialog
resp.setHeader("Content-Disposition:", "attachment;filename='my_excel_file.xls'");
[...]
}
I am working with 4-5 primefaces dialogboxes. When click ESC i want close all dialogboxes which are opened.
Call the dialog's hide() function through the client side object specified with widgetVar. So if you defined your p:dialog like:
<p:dialog widgetVar="dialog1" header="Dialog 1"/>
<p:dialog widgetVar="dialog2" header="Dialog 2"/>
Your ESC button should look like:
<p:commandButton value="ESC" onclick="dialog1.hide();dialog2.hide()"/>
You can also create a reusable p:remoteCommand to close all your dialog and use that in your p:commandButton or in p:hotkey - if by "click ESCAPE" you mean hittig the Escape button:
<p:remoteCommand name="closeAll" onsuccess="dialog1.hide();dialog2.hide()"/>
then in your components refer to the closeAll() command:
<p:hotkey bind="esc" handler="closeAll()"/>
<p:commandButton value="ESC" onclick="closeAll()"/>
Although the post is old, but the answer is rather a static solution, here's a dynamic one using jQuery.
function escDialog() {
$(document).keyup(function(e) {
if (e.keyCode == 27) { // esc code is 27
closeAllDialog() ;
}
});
}
function closeAllDialog() {
for (var propertyName in PrimeFaces.widgets) {
if (PrimeFaces.widgets[propertyName] instanceof PrimeFaces.widget.Dialog ||
PrimeFaces.widgets[propertyName] instanceof PrimeFaces.widget.LightBox) {
PrimeFaces.widgets[propertyName].hide();
}
}
}
Then in your document.ready you would call escDialog()
Hope this helps.
I'm writing an eclipse-plugin which creating a new Console. Please see my source code:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IConsoleView consoleView = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
MessageConsole myConsole = new MessageConsole("CLI", null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { myConsole });
consoleView.display(myConsole);
MessageConsoleStream stream = myConsole.newMessageStream();
stream.println("Hello World");
The Console "CLI" appeared, but it is not editable by user input. I would like to make user can input directly into the Console by typing in the Console.
And I also want to handle the input but any listener or keybinding.
Anyone know can help me?
Use an IOConsole instead! MessageConsole is basically a read-only version of IOConsole.
From MessageConsole.createPage(...):
public IPageBookViewPage createPage(IConsoleView view) {
IOConsolePage page = (IOConsolePage) super.createPage(view);
page.setReadOnly();
return page;
}
I have a list of urls in a grid, And I need that when a user click in a url a new browser windows open with the same url
I read some threads but in my case I believe my situation is a little different. In my controller
I'm using the following code
UrlListCollection.generateListUrl();
dataGrid.setRowRenderer(new RowRenderer() {
public void render(Row row, Object data) throws Exception {
UrlObj url = (UrlObj) data;
row.getChildren().add(new Label("Some data"));
row.getChildren().add(new Toolbarbutton(url.getUrlApp())); // url.getUrlApp() will be return a link like http://www.google.com
}
});
In my view(zul) I have
<grid id="dataGrid" width="100%">
<columns>
<column label="Some Data" sort="auto(FIELD_NAME)" width="200px" />
<column label="URL LINK" sort="auto(URL)" width="630px" />
</columns>
</grid>
But the common way to set an event an component in java can be:
Toolbarbutton button = new Toolbarbutton(url.getUrlApp()));
button.addEventListener(Events.ON_CLICK, new EventListener() {
public void onEvent(evt) {
// what I put here to open a Link in another web browser window ????
// and I need to be able to open every object value retrieved by url.getUrlApp() ???
}
});
I don't now what is necessary to make my code works..for me the way to apply a Event to toolbar button inside a grid that use RowRenderer method is strange. I can't see a solution by myself.
You can use the following example,
Executions.getCurrent().sendRedirect("http://www.google.com", "_blank");
Or you may use the A component with the setHref() method instead of the Toolbarbutton component.
This works fine for me, thanks!
UrlObj url = (UrlObj) data;
Toolbarbutton tb = new Toolbarbutton(url.getUrlApp());
tb.setHref(url.getUrlApp());
tb.setTarget("_blank");
row.getChildren().add(new Label("Some data"));
row.getChildren().add(tb);