How to dynamically add & update JSF components from bean? - jsf

I'm trying to generate dynamic chat windows within a PanelGroup. The structure is like this:
<h:panelGroup id="chats">
<p:dialog id="chatWindow1">
</p:dialog>
<p:dialog id="chatWindow2">
</p:dialog>
</h:panelGroup>
The problem is when I'm adding a new chat window, it's not showing. I think the newly created dialog is not updating [ by RequestContext's update method] since it's not existing yet in view. So, I've to update "chats" panel group in order to see the new dialog. But the problem in that is pre-existing dialogs in that panel group gets updated.
Consider a scenario: user types some text in chat window.Suddenly a new chat window pops up & all his chat text in that pre-existing dialog vanishes.
I just want to prevent that scenario. How can it be done?

Related

JSF 1.2 to open external link in new tab. without distrubing current flow [duplicate]

I need to open a JSF page in a new window by POST on click of a <h:commandButton>. I know I can acheive this using the JavaScript. But I would like to achive this using JSF and not JavaScript.
How can I achieve this? I'm using JSF 2.0.
The only non-JS way is to set target="_blank" in the parent <h:form>.
<h:form target="_blank">
...
<h:commandButton value="Open in new Window" />
</h:form>
This however affects all non-ajax(!) actions which are performed in the very same form. So if you're smart, make the action which shouldn't open in a new window an ajax action. However, ajax is also JavaScript and you mentioned that you don't want to use JS (I hope you don't get shocked once you discover that PrimeFaces is actually full of JavaScript).
If you absolutely need to restrict it to a single action, then you really can't go around asking little help to JavaScript.
<h:form>
...
<h:commandButton value="Open in new Window" onclick="this.form.target='_blank'" />
</h:form>
When you restrict the target only to a single action, maybe you want to get the form in its initial state.
With the oncklick action you set the target of the form to a _blan page.
After the click, the page is opened in a new tab/page (triggers the action event).
At last, the onblur action is triggered and set the form again to its initial state (the rest of the buttons will open in the _self page)
With this code, you can restrict to only a h:commandbutton to open in a new page.
The rest of the buttons will be opened in the self page:
<h:commandButton
onclick="this.form.target='_blank'"
onblur="this.form.target='_self'"
id="listadoRebuts"
action="#{giaquaBusquedaCorte.abrirListadoRebuts}"
value="#{msg.seqVisorbtnRecibos}">
</h:commandButton>

How to upgrade select one of my other xhtml page?

I have a jsf form of registration that usually works on a select one menu is displayed a list of vehicles, in case the user needs to register a new vehicle for the issuance of the note he clicks one side of the select menu and opens a dialog to register .
Until then everything is working but when I close the dialog the registered vehicle only appears after typing F5. How can I do to update the select one menu. It is important to point out that the registration of the notes and open dialog xthmml are different pages, so do not know how.
Try putting styleClass="vehicles" to <p:selectOneMenu>, and update="#(.vehicles)" on <p:commandButton> in the dialog (the button in the dialog that adds the new vehicle). If everything is wired up correctly in the managed bean (the list that select one menu displays is updated), you should see the new car in the list.
<p:selectOneMenu styleClass="vehicles" ...>
<p:commandButton update="#(.vehicles)" ...>

Open dialog to register vehicle on the register of notes

Personally I have a registration page of notes, it got a selectOneMenu vehicle. But I want to offer the user the ability to click a button to open a dialog where he registers a vehicle if you do not already in the registry. And this is set back in the notes page to close the dialog. I know it sounds very simple. But would an example of how I can do this.I use JSF, Primefaces, JEE7 Thank you
Here's the most important, the buttons:
In main page, surrounded by form mainForm:
<p:commandButton icon="ui-icon-plus"
value="New"
actionListener="#{bean.prepareCreate}"
update=":formInDialog"
oncomplete="PF('dialogWidgetVar').show()"/>
In bean.prepareCreate you create the new entity for binding into.
In dialog, which has its own form formInDialog inside it:
<p:commandButton actionListener="#{bean.create}"
value="Save"
update=":mainForm:listOfEntities, formInDialog, :growl"
oncomplete="if(args && !args.validationFailed {PF('dialogWidgetVar').hide()}" />
formInDialog and growl needs to be updated in case of errors.

PrimeFaces 3.5 dynamic context menu using menu model and static context menu of primefaces is not working together

I am using the PrimeFaces 3.5 in my application.
I have made some changes in my code and I started using Dynamic Context Menu using server side code instead on static simple context menu of primefaces.
sample code
MenuItem menu1= new MenuItem();
menu1.setValue(Label);
menu1.setActionExpression(expFact.createMethodExpression(elCtx, "#{classname.methodname}", Void.class, new Class[0]));
menu1.setOncomplete("Dialog1.show()");
model.addMenuItem(menu1);
this dynamic menu is working fine.
In this context menu on oncomplete event a Dialog is popup-ed. I am using another simple context menu for this dialog. Earlier I was able to handle context menu on Dialog box but as I have changed dynamic context menu on my main xhtml page. The context menu is not appearing on dialog box now.
I am not getting any exception or error on browser so I am unable to trace the cause why my simple context menu is lost or what extra I need to do to handle simple context menu on dialog now?
Please help me and thanks in advance.
ACtually I am using a Datatable and in datatable I was unable to implement the context menu. But I have used simple solution and my problem got resolved.
<p:contextMenu for="Tableid" id="contextid" widgetVar="contextwidgetvar">
<p:menuitem value="Menu 1" oncomplete="confirmationdialog.show()" />
</p:contextMenu>
<p:dataTable id="Tableid" widgetVar="Table" var="sItem"
value="#{classname.methodname}" rowKey="#{sItem.id}" selection="#{classname.methodname.selectedObject}"selectionMode="single" lazy="true" editable="true">
<p:ajax event="contextMenu" oncomplete="contextwidgetvar.show();" />
</p:dataTable>
This simple steps solved the problem.
some time you may need to add some javascript to avoid the always getting the first row in selected object.

How to show a personalized error/warning/info message in a popup window?

Hi I want to show a popup message about errors or warnings in my app, for example if a user try to enter a registry that is already in the data base. I'm working with JSF and my app doesn't add a registry that is already in the data base but I need to show a message that informs the user about that.
Thanks.
This answer is specifically for icefaces (since I read in comments that the #Mel is working with icefaces.
To open a popup in icefaces:
<ace:dialog widgetWar="mydialog">
<h:outputText value="This is a dialog" />
</ace:dialog>
Then call this popup in your xhtml code like this:
E.g. I am using a command link that when clicked opens the popup.
<h:commandLink onlick="mydialog.show()" action="#{myBean.doSomething()}" />
To show messages in dialog:
<h:form id="myform">
<ace:dialog id="mydialog" widgetWar="mydialog">
<h:panelGrid columns="1" width="100%">
<ace:messages id="allMsgsAdd" initEffect="highlight" for="myform:mydialog" />
</h:panelGrid>
<h:outputText value="This is a dialog" />
</ace:dialog>
</h:form>
Then you can use this code to push messages to the ace:message you just created.
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(SEVERITY_INFO, "My Message", null));
Please note that SEVERITY_INFO is a FacesMessage defined constant. You will need to import it. Depending on whether you need to show warning or error to user, you can import these
import static javax.faces.application.FacesMessage.SEVERITY_ERROR;
import static javax.faces.application.FacesMessage.SEVERITY_INFO;
Also note the first parameter of addMessage() method. You will notice that I am passing null as the first paramter. See here, and you will find that the first paramter is the client id, which basically means that which client do you want to send this message to. If clientId is null, this FacesMessage is assumed to not be associated with any specific component instance. So all of the message dialogs in your page will receive this error/warning. If you wish to ONLY show the message on the dialog, you need to pass your dialog client id here like this:
FacesContext.getCurrentInstance().addMessage("myform:mydialog", new FacesMessage(SEVERITY_INFO, "My Message", null));
You can try to use some existing open source JSF component library .Many of them already provide the pop-up UI . For example ,Richfaces provides it by . You can refer to this official link to see how to use : http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_modalPanel.html
Check my asnwer in another question, maybe it will be useful for you
How do I get a richfaces modal window to display without an onclick event?
This will show your exception messages (or another message added by you in middle of the code) in a <rich:modalPanel>.

Resources