Pass a bean in a dialog with Dialog Framework in Primefaces - primefaces

I have some problem to pass a entire bean in a dialog.
I would like to open a dialog with Dialog Framework in Primefaces, and pass the method and attributes content in bean.
I tried to make this code, but it don't work.How should I do?
<p:commandButton value="open dialog" ajax="true"
actionListener="#{processController.openSelectFieldDialog}"
update="tableResult , :notificationForm:info-messages">
<f:attribute name="controller" value="#{processController}" />
</p:commandButton>
This is the code inside openSelectFieldDialog method:
public void openSelectFieldDialog(){
RequestContext.getCurrentInstance().openDialog("genericSelectFieldDialog");
}
And this is the code inside the dialog controller:
public void onload() {
Object somethingBean= FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("controller");
}
I understand that i pass parameters on openDialog method, but i don't find any example on primefaces site. Can you help me?
Thanks

Related

PrimeFaces confirmdialogs from single Bean

Submit button is pressed the bean first checks for valid values, if it fails validation a dialog is presented. While the process is running another session submits a button press and the bean checks the flag and need to present a different dialog.
Is there away to have a single commandButton interact with two
different confirmDialogs, commandButton "update" interacts with the
confirmDialog
The main difference with my issue verse the other examples/solutions, there is only one button. And the update="confirmValid" on the submit button is only working for the first button push.
The bean is called successfully from "second" button press, the forceRequest method doesn't display the dialog
<p:commandButton id="myButton" update="confirmValid growl"
value="Submit"
actionlistener="#{message.sendMessage}"
...
/>
This dialog is presented for display when the request is invalid
<p:confirmDialog header="#{message.invalidValuesHdr}"
id="confirmValidData" message="#{message.invalid}"
wigdetVar="confirmValidData">
<p:commandButton value="Ok" update="growl" oncomplete="PF('confirmValidData').hide()"
</p:confirmDialog>
This dialog is presented when the process flag has been updated
<p:confirmDialog header="#{message.forceRequestHdr}"
id="confirmValidData" message="#{message.invalid}"
wigdetVar="confirmForce">
<p:commandButton value="Ok" update="growl" oncomplete="PF('confirmForce').hide()"
</p:confirmDialog>
Bean:
#ViewScoped
#Override
public void sendMessage() {
if (....)
forceRequest();
}
public void forceRequest(){
FacesMessage message = new
FacesMessage(FacesMessage.SEVERITY_INFO,"Message Title", "Message body");
RequestContext.getCurrentInstance().showMessageInDialog(message);
}
Displays a dialog the method below does nothing, which is the issue
public void forceRequest(){
RequestContext context = RequestContext.getCurrentInstance();
context.openDialog("Confirm");
context.execute("PF('confirmForce').jq.click();");
}
faces-config.xml is updated
public void forceRequest(){
RequestContext.getCurrentInstance().execute("PF('confirmForce').show();");
}
Above was the solution and now on to the bean

primefaces dialog framework: close dialog "onclick"

I show a Primefaces Dialog using the dialog framework, in this way:
RequestContext.getCurrentInstance().openDialog("myDialog", options, params);
In the page myDialog.xhtml I have a message and two buttons: YES or NO.
I would like to close the Pf dialog with the event "onclick", is there a way the to do this?
I cannot statically define the dialog using p:dialog and than close it using PF('widgetVarName').hide();
Generally, you may want something like this:
<p:commandButton action="#{someBean.closeDialog('yes')}" process="#form" update="#form"
icon="#{icons.yes}" value="#{bundle.yes}" />
<p:commandButton action="#{someBean.closeDialog('no')}" process="#form" update="#form"
icon="#{icons.no}" value="#{bundle.no}" />
public void closeDialog(String choice)
{
RequestContext requestContext = RequestContext.getCurrentInstance();
Object someData = executeChoice(choice);
requestContext.closeDialog(someData);
}
Otherwise, if you really need to close the dialog on onclick (sounds a little strange...) you may use:
<p:remoteCommand name="closeDialog" action="#{someBean.closeDialog}" process="#this" />
<p:commandButton type="button" onclick="closeDialog()" icon="#{icons.close}"
value="#{bundle.close}" />
public void closeDialog()
{
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.closeDialog(null);
}
Finally, if you need a pure javascript solution, you may want:
<p:commandButton type="button"
onclick="PrimeFaces.closeDialog({pfdlgcid:'#{param.pfdlgcid}'})"
icon="#{icons.close}" value="#{bundle.close}" />

Primefaces open closable dialog programmatically

I want to dynamically create a primefaces dialog from the backing bean.
I have written the code above:
public void showDialog(){
UIComponent panelGroup = facesContext.getViewRoot().findComponent("form1");
System.out.println("found or not??"+ panelGroup.toString());
Dialog dialog = new Dialog();
dialog.setId("sample");
dialog.setWidgetVar("widget");
dialog.setHeader("Sample");
dialog.setVisible(true);
dialog.setMinimizable(true);
dialog.setDynamic(true);
dialog.setHideEffect("fade");
dialog.setFooter("footer");
dialog.setDraggable(true);
dialog.setMinWidth(600);
dialog.setClosable(true);
dialog.setModal(true);
dialog.setAppendToBody(false);
panelGroup.getChildren().add(dialog);
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.openDialog("widget");
requestContext.update("form1");
}
and in my jsf page: i have
<h:form id="form1" >
<h:commandButton value="show Dialog" action="#{createDialog.showDialog()}" />
</h:form>
The problem is that when i set it to visible , i got the dialog but neither i can close (i don't get the close icon nor i can drag it)!
You need to replace this line:
requestContext.openDialog("widget");
to that:
requestContext.execute("PF('widget').show()");
RequestContext.openDialog() method reffers to Primefaces Dialog Framework API which is different to p:dialog component.
From primefaces user guide:
Dialog Framework (DF) is used to open an external xhtml page in a
dialog that is generated dynamically on runtime.
So, RequestContext.openDialog() expects you to provide path to xhtml page as argument.
And p:dialog component have javascript api show() and hide() methods to interact with it.

Primefaces resetinput in cancel button hanging other tabs

I have got an issue with primefaces resetinput. When I press this cancel button all of my other Tabs just hanged. I am using primefaces 3.5.
<p:commandButton id="cancelMainButton" process="#this"
value="#{bundle.Cancel}" update=":ss_form:ss_tabView:main_tab"
actionListener="#{eccmServiceSpecController.cancelServiceSpec}"
icon="ui-icon-cancel">
<p:resetInput target=":ss_form"/>
</p:commandButton>
**Controller**
#Named("eccmServiceSpecController")
#SessionScoped
public void cancelServiceSpec(ActionEvent event) {
eccmServiceSpec = ejbFacade.findByServiceSpec(eccmServiceSpec);
this.setSelected(eccmServiceSpec);
}
**Facade** Statefull session bean with Extended mode.
public EccmServiceSpec findByServiceSpec(EccmServiceSpec eccmServiceSpec){
this.getEntityManager().detach(eccmServiceSpec);
eccmServiceSpec = this.find(eccmServiceSpec.getServSpecId());
eccmServiceSpec = this.getEntityManager().merge(eccmServiceSpec);
return eccmServiceSpec;
}
Thanks for your reply. I have added my controller and Facade please look at this. I shall be thankful to you.

java.awt.HeadlessException when calling JOptionPane.showMessageDialog in backing bean action method

I'm trying the following:
labelconfig.xhtml:
<h:form id="ok">
<h:commandButton value="click">
<f:ajax event="click" listener="#{canvasController.oeps}" />
</h:commandButton>
</h:form>
And I'm trying to get it here:
CanvasController.java
#ManagedBean(name = "canvasController")
#SessionScoped
public class CanvasController
public void oeps(AjaxBehaviorEvent event) {
JOptionPane.showMessageDialog(null, "SUCCES3");
}
}
But when I click the button, I get:
serverError: class java.awt.HeadlessException
How is this caused and how can I solve it?
You are trying to call Swing from server application without any desktop GUI. Instead of JOptionPane use logger or FacesContext.addMessage to get feedback. If for some reason you do want to control Swing app through JSF make sure DISPLAY etc are set but then I suggest rephrasing your question.