JSF 2.0 and Primefaces integration for ajax update of center section - jsf

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?

Related

Richfaces 4.5 picklist having duplicates on right side

Environment:
Jboss 7.1.1.Final
JSF 2.2.6
Seam 2.3.1.Final
Richfaces 4.5.10.Final
Issue:
The rich:picklist populates the right hand side with duplicates during the second time load of a popup. Here are the steps to reproduce.
The popuppage with the rich:picklist is loaded by clicking on a link in a main page
The popup page loads with the rich:picklist populated with the right side and left side values
The values are added from left side of picklist to right side and the popup is saved.
Now when we reopen the popup the picklist has duplicate values on the right side
XHTML Snippet:
<rich:pickList id="AssignRole" value="#{staffResourceRolesTargetList}" sourceCaption="Roles" targetCaption="Assigned Roles" listHeight="120"
converter="#{org.jboss.seam.ui.EntityConverter}" orderable="false">
<f:selectItems value="#{staffResourceRolesSourceList}"
var="assignRoles" itemLabel="#{assignRoles.name}" />
<f:selectItems value="#{staffResourceRolesTargetList}"
var="assignedRoles" itemLabel="#{assignedRoles.name}" />
</rich:pickList>
Note:
I have overridden the hashcode and equals method in the entity used in the picklist
I had to use two f:selectItems list inorder for the right side to prepopulate
The source and target list are of the same entity collection
Please help me debug this. I have spent a lot of time and hope that someone can give me direction. Please let me know if you need more info.

Primefaces confirm dialog not centered when used in conjuntion with richfaces

As per my question title, when I use richfaces, specifically a rich:popupPanel, my primefaces confirm dialog, p:confirmDialog, gets placed top/left justified. If I remove the the richfaces popup panel the primefaces dialog gets centered in the browser window as expected.
I tried changing the order of the namespace entries but that didn't work. What else can I try. I see richfaces also has a confirm dialog that I'm going to look into, it's just that I already had the primefaces version working on other pages, that happen to not have the richfaces popup panel.
I can post code if necessary.
You should not use Richfaces and Primefaces together. There so many conflicts between them both in terms of css and javascript. You can solve css problems by overwriting them and using '!important' at the end of each setting.
for example,
.class{
//...
text-align: center !important
}
However, Your best bet is to use just primefaces

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

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

JSF 2.0: Preserving component state across multiple views

The web application I am developing using MyFaces 2.0.3 / PrimeFaces 2.2RC2 is divided into a content and a navigation area. In the navigation area, which is included into multiple pages using templating (i.e. <ui:define>), there are some widgets (e.g. a navigation tree, collapsible panels etc.) of which I want to preserve the component state across views.
For example, let's say I am on the home page. When I navigate to a product details page by clicking on a product in the navigation tree, my Java code triggers a redirect using
navigationHandler.handleNavigation(context, null,
"/detailspage.jsf?faces-redirect=true")
Another way of getting to that details page would be by directly clicking on a product teaser that is shown on the home page. The corresponding <h:link> would lead us to the details page.
In both cases, the expansion state of my navigation tree (a PrimeFaces tree component) and my collapsible panels is lost. I understand this is because the redirect / h:link results in the creation of a new view.
What is the best way of dealing with this? I am already using MyFaces Orchestra in my project along with its conversation scope, but I am not sure if this is of any help here (since I'd have to bind the expansion/collapsed state of the widgets to a backing bean... but as far as I know, this is not possible). Is there a way of telling JSF which component states to propagate to the next view, assuming that the same component exists in that view?
I guess I could need a pointer into the right direction here. Thanks!
Update 1: I just tried binding the panels and the tree to a session-scoped bean, but this seems to have no effect. Also, I guess I would have to bind all child components (if any) manually, so this doesn't seem like the way to go.
Update 2: Binding UI components to non-request scoped beans is not a good idea (see link I posted in a comment below). If there is no easier approach, I might have to proceed as follows:
When a panel is collapsed or the tree is expanded, save the current state in a session-scoped backing bean (!= the UI component itself)
The components' states are stored in a map. The map key is the component's (hopefully) unique, relative ID. I cannot use the whole absolute component path here, since the IDs of the parent naming containers might change if the view changes, assuming these IDs are generated programmatically.
As soon as a new view gets constructed, retrieve the components' states from the map and apply them to the components. For example, in case of the panels, I can set the collapsed attribute to a value retrieved from my session-scoped backing bean.
Update 3: I got it working as described above. To sum it up, the solution is to store the relevant properties in a session-scoped bean instead of making the entire UIComponent session-scoped. Then, when the component is re-constructed after navigation has occurred, set the attribute values by retrieving the saved properties (using EL), e.g.
<p:panel collapsed="#{backingBean.collapsedState}" ... />
(This is a simplified example. Since I am using multiple panels, I am using a map to store these properties, as described above).
One solution would be to use session-scoped beans.
What do you mean by collapsible panels? I ask because there is a component that is closable as well as a component. I am using in the navigation pane in my project. The accordianPanel has an attribute named "activeIndex". Here's what I did in my sessionBean to maintain the state of my accordion tabs:
private int tabIndex; //declared a private variable
public SessionBean() {
tabIndex = 100; //set the initial tab index to 100 so all tabs are closed when page loads.
}
public int getTabIndex(){
return tabIndex;
}
public void setTabIndex(int tabIndex){
this.tabIndex=tabIndex;
}
in my navigation pane:
<p:accordionPanel activeIndex="#{sessionBean.tabIndex}" collapsible="true" autoHeight="false">
<p:tab title="#{tab1_title}">
<h:commandLink value="link here" action="target_page?faces-redirect=true" /><br/>
</p:tab>
<p:tab title="#{tab2_title}">
<h:commandLink value="link here" action="target_page?faces-redirect=true" />
</p:tab>
<p:tab title="#{tab3_title}">
<h:commandLink value="link here" action="target_page?faces-redirect=true" />
</p:tab>
</p:accordionPanel>
I'm not using the tree component for navigation as that presented my project with some difficulties that were easily overcome by using the accordionPanel, so I can't speak to that part of your navigation.

How to avoid page flicker in JSF 1.1 + Ajax4jsf?

I am developing a small application usng JSF 1.1, Ajax4jsf and Tiles. When I click the a4j:commandLink, the entire page is reloaded. I want to update only portion of the page. How to resolve that?
<a4j:commandLink value="Get greeting" reRender="greeting" />
You must to use the property reRender to update some section of your page.
For more information, see this link.

Resources