Display Primefaces's OverlayPanel when the page loads - jsf

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

Related

Is loading triggered from the click of a submit button generated by h:commandButton a full load?

A jsf page contains a form with a commandButton element like <h:commandButton action="#{bean.search}". This submit button will trigger a bean, which then will send more data back to this same jsf page.
Question: after the submit, is the jsf page fully loaded again? or is just the part containing the newly retrieved data reload and other parts are not loaded again?
By default JSF will fully reload the page. This can be tested by looking at the browser network developer tools while submitting the commandButton. If you intend to only render a part of the page - e.g. a label that outputs the result - you can do that by using AJAX.
For example if your commandButton is in a form, by adding
<f:ajax execute="#form" render="#form:result" />
within your commandButton tag, you can specify that only the contents of the form are processed by the server and only the label with the ID 'result' is rendered.
For further information take a look at this guide for AJAX in JSF: https://www.beyondjava.net/a-comprehensive-guide-to-jsf-ajax
You will see that the author shows the full page loading without AJAX.
Alternatively here is the official documentation for <f:ajax>:
https://jakarta.ee/specifications/faces/2.3/vdldoc/f/ajax.html

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>

p:commandButton show other button after this button clicked

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

Open new window by POST using h:commandButton

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>

Pop up Window in spring web flow

i am still new to spring.I need to make a popup window when the button is clicked in spring web flow.
Let say in html file
<h:commandLink value="Sick Leave" action="sickleave" id="sickleave" /></div>
When the action command link is clicked I have to populate the page with some value on-entry itself.
In my flow.xml
<transition on="sickleave" to="sickLeave"></transition>
<view-state id="sickLeave" view="sickLeave.xhtml" popup="true"></view-state>
i have added popup=true.But still i am not able to get a popup window.
I think you need a to use a sf:commandLink component instead of the h:commandLink setting the reRender tag as follows:
<sf:commandLink value="Sick Leave" action="sickleave" reRender="#{flowRenderFragments}" processIds="*" id="sickleave" />
I'm not sure if the "processIds" tag is needed, so try it with and without it.

Resources