How to render a4j outputpanel from iframe - jsf

I have a a4j:commandButton in a iframe and a a4j:outputPanel where both of the iframe and the panel resides in a same page. Is it possible to reRender that panel on that button click?
Thanks.

It looks to be not possible to be done using standard JSF+A4J approach. The content inside of iframe is build by a separate request to separate view, so it has its own JSF components tree. So a4j:commandButton and a4j:outputPanel are in different views (different components trees), and it is not possible to do 'cross-tree' rerender.
To access parent page from iframe you can try using JavaScript.
For example put to parent page jsFunction, like this:
<a4j:jsFunction name="reRenderPanel" reRender="panelId"/>
And in iframe add the following onclick javascript to commandButton:
<a4j:commandButton onclick="parent.reRenderPanel();"/>

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>

Content loading in JSF page layouts

I am developing an application in JSF. My page has been divided into 3 layouts. Menu bar will be displayed at left side and content will be shown at center of the page. I want menu bar in all pages throughout the application. Now i have achieved it using templates. But its reloading the entire page while clicking the menu items.
Is there any other option to display the content in the content area without reloading the entire page?
Thanks.
I have faced similar issues in my application. You have to use <f:ajax> within your menu item and render only the div you want refresh.
e.g.
<f:ajax render="idOfDivToRefresh" />

Open a link in new tab/window without loosing the view scope of current JSF page

I need to open a new JSF page (say 2.xhtml) in new tab from current JSF page (say 1.xhtml).
Which JSF component should I use for it? <h:commandLink> or <h:outputLink>?
I do not want to lose the scope of current page 1.xhtml after clicking on the link to open 2.xhtml in new tab.
The bean of 1.xhtml is #ViewScoped. Should I change it to #RequestScoped?
In HTML, a link which opens the given URL in a new window/tab via a GET request is to be achieved using <a ... target="_blank">.
In JSF you can just write down plain vanilla HTML:
Open 2.xhtml in new window
You can also use <h:outputLink>, which is only beneficial if you ever want to use its rendered attribute:
<h:outputLink value="#{request.contextPath}/2.xhtml" target="_blank">Open 2.xhtml in new window</h:outputLink>
You can also use <h:link> which can take a navigation outcome instead of an URL, JSF will then generate the right URL:
<h:link value="Open 2.xhtml in new window" outcome="2" target="_blank" />
The bean scope is irrelevant to this all. Just choose the right one for the data it holds. The <h:commandLink> is insuitable as it fires a POST request instead of a GET request.
See also:
How to choose the right bean scope?
How to navigate in JSF? How to make URL reflect current page (and not previous one)
When should I use h:outputLink instead of h:commandLink?

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>

Resources