p:commandButton show other button after this button clicked - jsf

Hi I have a JSF "Register.xhtml" inside I have two Primefaces Command Buttons:
<p:commandButton id="registerButton"
action="#{registerController.register()}" rendered="#{!registerController.IsUserRegistered()}" />
<p:commandButton id="unregisterButton"
action="#{registerController.unregister()}" rendered="#{registerController.IsUserRegistered()}"/>
It works if I manually refresh the page.
I want a method to show the unregisterButtonand hiding the registerButton after I call the
registerController.register() function by clicking on the register Button.

You need to refresh the part of the page where the second button is after the click on the first button.
With Primefaces you can use PartialSubmit, http://www.primefaces.org/showcase/ui/ajax/partialSubmit.xhtml

Related

Display Primefaces's OverlayPanel when the page loads

The page shows a Primefaces's overlayPanel when the target component (a commandButton) is clicked on:
<p:commandButton id="inputBtn" value="Choose a data source" type="button" action="#{dataImportBean.oAuth}"/>
<p:overlayPanel
id="overlaypanel1"
for="inputBtn"
dynamic="false"
widgetVar="inputChooser"
>
// contents of the overlay panel
</p:overlayPanel>
I would need the overlayPanel to be displayed when the page loads, without the need to click on the target commandButton.
The use case is: the user had the overlayPanel opened but an oAuth flow made the user navigate away from the page. When the oAuth is completed the user is redirected to the page. However the overlayPanel is closed when the page loads, whereas I need the user to be brought back directly to the overlayPanel, for consistency.
Use the client side API on your widget var. You can use show() to show the panel, so in your case: PF('inputChooser').show().
To do this on page load, you could place this after the p:overlayPanel:
<c:if test="#{yourCondition}">
<script>$(function() { PF('inputChooser').show() })</script>
</c:if>
See also:
https://primefaces.github.io/primefaces/10_0_0/#/components/overlaypanel?id=client-side-api

primefaces Cancel button not navigating to previous page

I have a p:commandButton, which when I click on, I want it to take me to the previous page. This is the code I have used -
<p:commandButton id="cancel" value=" Cancel" action="cancel" ajax="false" process="#this"/>
However, when I click on Cancel, nothing happens. Please let me know how I can get my button to navigate to the previous page.
You can use javascript in the oncomplete event of the button.
oncomplete = "window.history.back();"

refreshing a datatable

dudes, does any of you know how to do this?
i have a page that has a datatable on it. it has a button to delete a row. the button works as expected, when you click it, it will delete the selected row/s. i also have another button that opens a popup window where you search for items and them add them to the said datatable. i am having a hard time figuring out how to refresh the datatable once you click the "select" button on the popup window.
my solution is having a hidden button that will refresh the datatable. it works when i litterally click it. but when i trigger the click event on the popup window using javascript, it doesnt always work. sometime it refreshes, sometimes it doesnt.
what's actually the best way to refresh a datatable?
If you use JSF2.0, there is an option to update part of your application with
<h:form>
...
...(here you have the binding data)
<h:commandButton action="#{yourbean.updateRows}" >
<f:ajax render="tableName" />
</h:commandButton>
</h:form>
EDITED
If you want to invoke it from JAVASCRIPT use:
document.getElementById('elementName').click();
How are you accessing your DataTable in the popup window ? by keeping it in some session variable and in you parent page are you displaying the datatable through some UI Component like GridView ? In that case you can reload your parent window from where you opned the popu windo through javascript. E.g. window.opener.location.reload();
I can think of .. Datatable.AcceptChanges(); But that's for C#..

how to refresh the whole tabpanel in jsf

I am using richfaces and jsf.
I am using <rich:tabpanel> to create the tabs.
I have taken 4 tabs.
In 1st tab , one refresh button is available. If I click that button, the whole tabpanel is refreshed. whatever the data is kept in tab2, tab3 and tab4 will be clear.
use <a4j:support reRender="tabPanelComponentId"> inside your button, or use <a4j:commandButton reRender="tabPanelComponentId" />

Opening a Rich Modal Panel on Button Click

I m trying to open a rich modal panel with populated data on a button click
tried
<h:commandButton id="btn_search" value="#{text['button.add']}"
action="#{cartBean.search}"
oncomplete="#{rich:component('dlg_results')}.show()">
</h:commandButton>
and
<h:commandButton id="btn_search" value="#{text['button.add']}"
action="#{cartBean.search}" immediate="true">
<rich:componentControl for="dlg_results" attachTo="btn_search" operation="show" event="onclick"/>
</h:commandButton>
This code opens the model panel on button click but when response is sent back from the server the whole page gets refreshed
can some one suggest a way to handle this ???
Use <a4j:commandButton> instead of h:commandButton.
Thanks, this was helpful information.
I used showWhenRendered tag in rich:modalpanel to solve my problem. I added a variable in my bean and set its value to true on click of button if records are found.

Resources