Primefaces resetinput in cancel button hanging other tabs - primefaces

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.

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

Pass a bean in a dialog with Dialog Framework in 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

Scroll p:messages into view when it is updated and (error) messages are present

I am working with PrimeFaces messages, I want my whole page to scroll to top when p:messages is rendered.
Assign an ID to your p:message component
<p:messages autoUpdate="true" id="myMessage" />
Then, in your backing bean call RequestContext.scrollTo method:
in PrimeFaces >= 6.0:
PrimeFaces.current().scrollTo("myMessage")
in Primefaces < 6.0:
RequestContext context = RequestContext.getCurrentInstance();
context.scrollTo("myMessage");
which is deprecated in PrimeFaces 6.0
Deprecated with PrimeFaces < 6.2
In you backing bean (that one which produces the messages), you should know when you render a p:message. If so simply execute this:
RequestContext.getCurrentInstance().execute("window.scrollTo(0,0);");
Update:
With the newer PrimeFaces versions (>= 6.2), the approach to execute Javascript on the client side is (by using x and y coordinates):
PrimeFaces instance = PrimeFaces.current();
instance.execute("window.scrollTo(0,0);");
To scroll to an element use the element's clientId:
PrimeFaces instance = PrimeFaces.current();
instance.scrollTo("myElementsClientId");
Find more information here:
http://de.selfhtml.org/javascript/objekte/window.htm#scroll_to
examples with jQuery for smooth scrolling as well: Scroll to the top of the page using JavaScript/jQuery?
Lets say that your button is causing the messages to appear.
XHTML
<p:commandButton value="Save"
oncomplete="scrollToFirstMessage()" />
javascript
//javascript function which scroll to the first message in page
function scrollToFirstMessage() {
try {
PrimeFaces.scrollTo($('.ui-message :first-child').eq(0).parent().attr('id'));
} catch(err) {
//No Message was found!
}
}
Hope this helps.
There are valid answers already that show how to scroll to the p:messages component, but they all require you to execute code in a backing bean. This requires you to do / call the same in each action. None show how to scroll to the messages component when it is rendered (updated).
You can implement a phase listener and check messages are present and if the messages component's clientId is present in the PartialViewContext renderIds:
These client identifiers are used to identify components that will be processed during the render phase of the request processing lifecycle.
Your listener can look something like this:
public class MessagesUpdateListener implements PhaseListener {
private final String MESSAGES_ID = "yourMessagesClientId";
#Override
public void afterPhase(PhaseEvent event) {
// Empty
}
#Override
public void beforePhase(PhaseEvent event) {
FacesContext fc = FacesContext.getCurrentInstance();
if (!fc.getMessageList().isEmpty() &&
fc.getPartialViewContext().getRenderIds().contains(MESSAGES_ID)) {
RequestContext.getCurrentInstance().scrollTo(MESSAGES_ID);
}
}
#Override
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
}
Make sure to register it in your faces-config.xml:
<lifecycle>
<phase-listener>your.MessagesUpdateListener</phase-listener>
</lifecycle>
Tested with XHTML:
<h:form id="main">
<p:messages id="messages" />
<p:inputText id="text1" required="true" />
this<br/>is<br/>a<br/>long<br/>page<br/>this<br/>is<br/>a<br/>long<br/>page<br/>
this<br/>is<br/>a<br/>long<br/>page<br/>this<br/>is<br/>a<br/>long<br/>page<br/>
this<br/>is<br/>a<br/>long<br/>page<br/>this<br/>is<br/>a<br/>long<br/>page<br/>
this<br/>is<br/>a<br/>long<br/>page<br/>this<br/>is<br/>a<br/>long<br/>page<br/>
this<br/>is<br/>a<br/>long<br/>page<br/>this<br/>is<br/>a<br/>long<br/>page<br/>
this<br/>is<br/>a<br/>long<br/>page<br/>this<br/>is<br/>a<br/>long<br/>page<br/>
this<br/>is<br/>a<br/>long<br/>page<br/>this<br/>is<br/>a<br/>long<br/>page<br/>
<p:commandButton value="Update" update="messages text1"/>
<p:commandButton value="No update"/>
</h:form>
To check for global messages, use:
fc.getMessageList(null).isEmpty()
See also:
Add global message when field validation fails

PrimeFaces open dialog several times with rendered attribute

I try to implement a dialog box accessible everywhere in my project and I was wondering if this solution is possible.
The dialog is included in the template of my project. For example, where I am on the login page, I would like to show the dialog when the button "Login" is clicked and the authentication is successful. So I catch the bean linked to the dialog with:
getFacesContext().getELContext().getELResolver().getValue(getFacesContext().getELContext(), null, beanName);
and I set the "show" argument. (have a look below)
The first time, it's working. When I access the login page, the dialog is not rendered and when I click the button login, the attribute show is set, the page is updated and the dialog appears. But if I close it, I could not fire it again when I click again the button. (The dialog is rendered but not shown)
My dialog is like this (I have visible="true" cause I want to show each time it's rendered):
<h:form>
<p:dialog header="Dialog" widgetVar="myDialog" rendered="#{bean.show}" visible="true">
<p:ajax event="close" listener="#{bean.onClose}" />
...
</p:dialog>
</h:form>
The bean is in viewscope:
#ManagedBean(name = "bean")
#ViewScoped
public class MyBean {
private boolean show; // + Getters and Setters
#PostConstruct
public void init() {
this.show = false;
...
}
public void onClose() {
this.show = false;
}
}
And I can add that my LoginBean which is setting the show argument is in viewScope too.
Thanks

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.