Resetting a JSF Backing bean from theme navigation menu in WPS 7.0 - jsf

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

Related

Primefaces: How to add icon and <p:badges> inside <p:submenu> on Panel Menu?

As title stated, I want to put icon and badge beside the title of submenu of Panel Menu. However, Primefaces' submenu default icon is the expand arrow/triangle. When I do this:
<p:badge value="2">
<p:submenu icon="pi pi-envelope">
</p:badge>
It will prompt error, and doing vice versa like wrapping badge and closing using </p:submenu> is impossible because there are menuitems also. Not to mention the icon is not showing.
So, can I really achieve this using free open source provided? Or this is exclusive to paid user only?
Example from Primefaces template
Badges are not supported on (sub)menu items at this moment (PrimeFaces 11). No matter if you use a free or paid theme. The only component that currently supports a badge on a child node is p:speedDial. What you can do is open a feature request and if possible submit a pull request.
See also:
https://github.com/primefaces/primefaces/issues/7898
https://github.com/primefaces/primefaces/pull/7922

JSF rerender clears html code added onload

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.

Using #ViewScoped with master template doesn't reset inputs

I am using a master template (i.e. <ui:composition template> / <ui:define>) where I have a navigation panel on the left, and the content panel in the center. When I go to one of my pages that is #ViewScoped, I edit some of the fields, go to another page which reloads the content area, and then go back to the original page, and the fields are all still populated with data. This implies that the view never ended. I tried #RequestScoped which produces the results I want, but breaks all of the ajax in the page related to that bean.
What is the best way to reset a page to its original state?
Can anyone see what is happening, exactly, regarding my layout and content area (consisting of a ui:include) being updated that would cause this not to be considered a change of View?
By navigating the content of the page using a backing bean, a ui:include updated by ajax, all in the same page, JSF's current view never goes out of scope, which is why the backing ViewScoped beans are never reset after navigating.
One possible fix for this is to redesign the page to use traditional navigation. In other words, lets say you have several p:menuitems. Rather than assigning the actionListener to some backing bean function that sets the content page (followed by an update of the panel containing the ui:include), you would set the "action" of each menuitem to the page to which each corresponds. This has the effect of causing a page to be loaded when a menuitem is clicked.
This generated the requirement that I had to reorganize my template a little so that every page of my site was embedded in it. There's a little bit of flicker as the entire page reloads, but the beans are being reset accordingly.

JSF 2.0 and Primefaces integration for ajax update of center section

I have left, right and center panels in my xhtml page. Left panel contains menu item links and want to use them to refresh the center section through ajax.
I have seen quite a few links related to this but I am not sure on the final solution.
If this is not the preferred approach, please do guide on the same.
I am using managed beans which are sessionscoped and xhtml file uses following to do the dynamic call.
<p:menuitem value="Done" action="#{navBean.setPageName('done')}" update="centerPanel" immediate="TRUE" />
When I use primefaces 2.2.1, i am able to update the center panel on second click only from the menu in left panel.
When I use primefaces 3, the center section doesn't get updated.
The managed bean setter does get invoked in both cases.
Is it something to do with primefaces configuration or am I missing something?

JSF component is not getting reloaded for page refresh

I am new to JSF framework and Facelets as view, I am stuck with a problem now. I have got a page where i show some dropdown menu using <h:selectOneMenu> tag. On each selection i used to fire an ajax event using <f:ajax> event it all are working fine. But my problem is, if i select an option 2 on a select box and if I reloads the page again that particular select box will be selected with option 2 by default. I dont need this. I have to reload the select boxes along with page refresh. Please help me to solve this issue.
The selectbox shows the option that is set in the backing bean (and bound by the value attribute of <h:selectOneMenu>). The behavior after a page refresh depends on the scope of your backing bean. If it is session scoped, a page refresh doesn't reset the bean. You could change the scope to #ViewScoped to get the desired behavior. The bean then will be recreated after a full request.
Just set null to backing bean property that used in selectonemenu value after the selected action or set default value in property get method.

Resources