Initialize a composite component based on the provided attributes

As to the cause, UIComponent instances are inherently request scoped. The postback effectively creates a brand new instance with properties like values reinitialized to default. In your implementation, it is only filled during encodeXxx(), which is invoked long after decode() wherein the action event needs to be queued and thus too late. You’d better fill … Read more

Populate p:selectOneMenu based on another p:selectOneMenu in each row of a p:dataTable

Whilst your initial solution works, it’s in fact inefficient. This approach basically requires the entire object graph of the Country and State tables (even with circular references) to be fully loaded in Java’s memory per JSF view or session even though when you simultaneously use only e.g. 5 of 150 countries (and thus theoretically 5 … Read more

Remove all styling from Primefaces components?

Set primefaces.THEME context parameter to none and you’ll get a functional ui with no styles. <context-param> <param-name>primefaces.THEME</param-name> <param-value>none</param-value> </context-param> You don’t need to spend hours editing styles. Styling of PrimeFaces is done via shared styles like ui-widget-header, ui-widget-content which you can customize via the themeroller web form. I don’t think JSF and theming can get … Read more

How to implement a PhaseListener which runs at end of lifecycle?

You need to implement the PhaseListener interface and hook on beforePhase() of the PhaseId_RENDER_RESPONSE. The render response is the last phase of the JSF lifecycle. public class MyPhaseListener implements PhaseListener { @Override public PhaseId getPhaseId() { return PhaseId.RENDER_RESPONSE; } @Override public void beforePhase(PhaseEvent event) { // Do your job here which should run right before … Read more

Calling Primefaces dialog box from Managed Bean function

You can, by using the RequestContext (or PrimeFaces if you are using the version 6.2 or higher) class. Suppose you have the following: <p:dialog id=”myDialogID” widgetVar=”myDialogVar”> …. </p:dialog> So the way you do in the facelet itself, i.e. onclick=myDialogVar.show();, the same can be done in your managed bean like so: For PrimeFaces <= 3.x RequestContext … Read more

Collection of selectManyCheckbox inside a ui:repeat knows which element of the repeater it belongs to

Simplest way would be to just bind the value of the checkbox group to the currently iterated object instead of all checkbox groups to one and same parent bean property. In code, just replace value=”#{gridPopUpBean.oneQuestionUserAnswerList}” by value=”#{p.oneQuestionUserAnswerList}” and make changes in the model accordingly. Alternatively, you can also provide a Map of all answers by … Read more

Conditionally render a component based on selectOneMenu value

Just check the dropdown menu’s value in the rendered attribute of the target components and update their common parent by a <f:ajax>. Here’s a kickoff example: <h:selectOneMenu value=”#{bean.item}”> <f:selectItem itemValue=”one” /> <f:selectItem itemValue=”two” /> <f:selectItem itemValue=”three” /> <f:ajax render=”results” /> </h:selectOneMenu> <h:panelGroup id=”results”> <h:panelGroup rendered=”#{bean.item eq ‘one’}”> You have selected “one”. </h:panelGroup> <h:panelGroup rendered=”#{bean.item eq … Read more