Im'using Primefaces 5.0 and I tried to use PF Dialog Framework features, but with some problems.
I open a dialog using openDialog() method.
In the dialog bean I managed an init() method annotated with #PostConstruct.
In that method I read parameters and load a list of records (to bind with a dataTable).
All seems work fine... dialog opens, I choose a record , close with closeReturn and so on.
But I want that in init(), if a single record was found, I could close immediately the dialog.
So I call closeDialog(), passing my bean... but nothing happens... the dialog opens and I have to close it manually.
And this is frustrating...
Could anyone help me?
Thanks
You can use primefaces requestContext to close the dialog from your bean.
#PostConstruct
public void init() {
recordList = loadListOfRecords();
if ( recordList.size() == 1 ) {
RequestContext.getCurrentInstance().execute('yourDialogWidgeVar.close()');
}
}
This is just a possibility to close a dialog from Bean. I don't know if it fits to your demands.
Please post your code next time. It is hard to figure out your problem without it.
Related
Hello I am using jdeveloper 12c. I have a test.jsf page in that I have form with a button. In the backing bean of this page I have actionListener method addKPI(ActionEvent e). when user click this button it calls addKPI() method. In this method I am doing some operations and after that I am trying to disable it using richButton.setDisable(true). It is not working in 12c. It is working in jdeveloper 11.1.2.4.
Please help me. How do I achieve this. My requirement is when user click this button I need to disable it. Means the button should be clickable only once.
Thanks in advance.
You can try firing a programatic PPR from the action listener:
public void addKPI(ActionEvent e) {
.........
richButton.setDisable(true);
AdfFacesContext.getCurrentInstance().addPartialTarget(richButton);
}
I'm using PrimeFaces 5.
I would like to open a dialog when a button is pressed.
<p:commandButton value="add upload" actionListener="#{theForm.openUpload}" >
public void openUpload() {
this.item = new Item();
RequestContext.getCurrentInstance().openDialog("uploadForm");
}
There will be a save button in the dialog to save the inputs.
<h:commandButton value="#{text['button.add']}" id="add" styleClass="btn btn-default" actionListener="#{theForm.confirmAdd}"/>
public void confirmAdd() {
RequestContext.getCurrentInstance().closeDialog("uploadForm");
}
My managed bean is #ViewScoped. Will the command button break the view scope if the dialog is in an external file as done by PrimeFaces Dialog Framework? Whenever I click the "add upload" button, the #PostConstruct method is called again just like the scope is lost.
Comments section of the official blog says it won't break the view scope, but here the forum a core developer says openDialog() creates a new view, therefore it breaks the view scope.
Can someone confirm this?
PrimeFaces' Dialog Framework basically shows another view in an <iframe> tag. I wouldn't call that breaking a view scope, but the dialog view will have it's own scope, because it is practically a different page. That may or may not be desirable in different circumstances. As PrimeFaces' User Guide says:
Dialog Framework (DF) is used to open an external xhtml page in a
dialog that is generated dynamically on runtime.
p:dialog
Exists in the same view scope.
Can easily have the same conversation context.
Statically defined, the dialog and its components get created immediately on view build. You can only delay rendering, e.g. with a dynamic=true.
Declarative definition means it's more readable and maintainable, because the dialog's existence is not hidden somewhere in java code.
Dialog Framework
Has its own view scope.
Developer has to worry about passing parameters, propagating conversation context. (And PF didn't support includeViewParams until 5.1.)
Dynamic creation means dialog and its components won't be created until the dialog is actually opened, but a new dialog will be created each time it's opened. If the dialog is opened many times, the total performance hit will be larger, plus many dialog views can exhaust JSF view limit and expire other views.
Imperative dynamic creation allows for more resource efficiency in certain cases. E.g. show one specific dialog out of dozens based on user input. Or a rarely used dialog, which could be opened from any page of an application.
My recommendation would be to use p:dialog by default. Only use Dialog Framework in cases like I mentioned in the last bullet point.
That's normal because you have already instantiated theForm(ManagedBean) in your main.xhtml. SO the scope is already used within the main.xhtml.
When you clicked to open the dialog: the dialog is a new view, then a new instance of theForm (ManagedBean) is created.
We had some problems with #ViewScoped in the JBoss 7.1/Mojarra 2.1.7 and we changed to Omnifaces
I suggest you to use #org.omnifaces.cdi.ViewScoped instead of #javax.faces.bean.ViewScoped
I tested with both your example and here on the log you can see the difference:
Log with #org.omnifaces.cdi.ViewScoped
18:58:40,887 INFO [xxx.TheForm] (http-localhost-127.0.0.1-8080-2) #postconstruct
18:58:40,890 INFO [xxx.TheForm] (http-localhost-127.0.0.1-8080-2) openUpload()
Log with #javax.faces.bean.ViewScoped
19:01:19,753 INFO [xxx.TheForm] (http-localhost-127.0.0.1-8080-5) #postconstruct
19:01:19,753 INFO [xxx.TheForm] (http-localhost-127.0.0.1-8080-5) #postconstruct
19:01:19,754 INFO [xxx.TheForm] (http-localhost-127.0.0.1-8080-5) openUpload()
I need to execute a metod before a <p:contextMenu> is displayed I was looking in the properties of the component and found beforeShow I'm not sure if I don't understand pretty well how this attribute works, but I tried to call the method with this
beforeShow="#{repositController.validate(item)}
and nothing happens when I do right click in the area, but the method is called once in the loading of the page.
The variable item come from the tree selection element. (I´dont know if that matters)
My java method is
public void validate(String cat) {
this.name = cat;
}
PD the the context menu is working right I just have that problem to run a method after display it.
thanks in advance for your time and answers.
I am making a dialog with a command. This command must close the dialog and go back to the previous form, but it is not working as expected. When I press the command, it closes the dialog but the form do not go back.
I am using the resource editor. State machine controls the app´s navigation.
The code inside the command´s logic is:
dialog.dispose();
StateMachine.back();
Is dispose() the method that I must use to close my dialog?
Thanks for reading.
As Nirmal said disposing the dialog goes to the previous form so while your call to "back()" works as expected your call to dispose() breaks that logic.
You can override the postShow method for the form you are showing and detect the case of leaving the dialog (just turn on a flag when you need to go back) and call the back method when the form is shown in that condition.
dont call StateMachine.back() just use dialog.dispose();
There is another solution : try to use the protected void onShowCompleted() method that you must implement in your Form. And declare a boolean variable in your Form ( for example private boolean isDialogShown; ), then in the constructor of your Form set that boolean variable to false, and just before the code of opening the Dialog set its value to true. Then in the code of the protected void onShowCompleted() test if it is true , and if it is true then set it to false and perform the back action : backForm.showBack();
I want to override Dialog so that it disposes itself the very moment it shows.
though it is a strange question, but you can override onShow() or onShowCompleted() and call dispose() inside one of them to close the dialog immediately.