I have a search page for which I am using the Primefaces datatable and the backingbean scope is Viewscope. For the searchresults I am using the primefaces p:commandLink so when I click on the commandlink I will navigate to details page of that link. When I click on the browser back button from the details page it is navigating to the search page but the datatable is not displayed.
I need the datatable to be displayed with the results it has previously when I click on the browser back button from the details page.
Checked in the forums but could not find any solution for it. Any help is greatly appreciated.
Related
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
I add a checkbox in front of specific components like dropdowns on page load. When a particular dropdown on change reRenders the a4j:outputPanel which has the checkbox, the checkox disappears. Is it because of the view being created and then I have added the checkbox. OR the a4j:outputPanel is the cause. I cannot remove the panel. Can anyone please guide me?
P.S : If I dont reRender the a4j:outputPanel the checkbox remains. But I need to reRender the panel.
The reason it disappears is that as you said it is added using javascript. When you render an element using jsf + ajax the element is created from the response from server. As the server knows nothing about your onload code, it removes the element and recreates it with response from server.
I'm using the rich faces popup panel which contains the search criteria and the search results. I need to render the search results on click of he search button. I'm using <a4j:commandButton> for search button, on click of the button the results are not rendering.
<a4j:commandButton id="popupSearchButton" action="#{riskAreaSearchBean.search}"
styleClass="saveAsDraft" immediate="true" execute="areaPopupSearch"
value="#{riskLabel['customs.common.search']}" render="addAreaPopupPanel" />
"addAreaPopupPanel" is my popup panel id
If your addAreaPopupPanel is having rendered attribute set to false before onclick of your search button there is no chance of finding it in the DOM tree. Enclose it in a h:panelGroup or h:paneGrid which will always present in DOM and render that panelGroup or panelGrid.
*remove immediate=true as it will skip update modal values phase.
Hope this helps.
I have a JSF Portlet which has user form in the view JSP. The requirement is whenever i click on the theme navigation menu, a new form needs to be displayed to the user. But the problem is whenever i click on the menu, the values are getting retained. Please suggest how to the remove/re-initialize the backing bean on click of theme navigation.
Thanks,
Raj
I did a workaround by adding a queryString parameter to the navigation URL generation (since we are using custome themes) and in my doView i am checking for the parameter and if its not NULL, then display a fresh form. Hope it helps
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#..