0

I have some trouble dealing with PrimeFaces 5.0 and a panelGroup with "binding". I know, "binding" sucks, but I'm working with a legacy system and believe me, it's truly hard to make it the right way, without "binding".

So, when I click mi link, the getter of the "binding" property is called before the "action", then the action is called, and after all the "update". But, the component is not properly updated.

Even if I make it to run the "action" before the getter of the binding, and the getter is returning the right stuff, this particular component is not updated.

I have more components without binding which are updated properly, but not the one with "binding".


UPDATE:

Here is the rest of the code. flag starts with "false" value.

The page always print "READ ONLY".

Somepage.xhtml

<h:form id="frm">

   <p:commandLink value="#{messages.Guardar}" id="bt_Guardar" action="#{myBean.flagFalse}" update="someid" />
   <p:commandLink value="#{messages.Editar}" id="bt_Editar" action="#{myBean.flagTrue}" update="someid" />


   <h:panelGroup id="someid" layout="block">
      <h:panelGroup id="panelCamposTD" layout="block" binding="#{myBean.someStuff}"  ></h:panelGroup>                            
   </h:panelGroup>

</h:form>

And my myBean, wich is a SessionScoped bean (because it comes from a legacy system)

@ManagedBean(name="myBean")
@SessionScoped
public class MyBean implements Serializable{


   private static final long serialVersionUID = 7628440827777833854L;

   private boolean flag = false;

   public void flagFalse(){
      flag = false;
   }

   public void flagTrue(){
      flag = true;
   }

   public HtmlPanelGroup getSomeStuff(){

       HtmlPanelGroup pg = new HtmlPanelGroup();   
       HtmlOutputText t = new HtmlOutputText();

       if (flag){          
           t.setValue("EDITED");           
       }else{          
           t.setValue("READ ONLY");            
       }
       pg.getChildren().add(t);

       return pg;
   }   

   public void setSomeStuff(HtmlPanelGroup pg){
      return;
   }


   public boolean isFlag() {
      return flag;
   }

   public void setFlag(boolean flag) {
      this.flag = flag;
   }


}
Cristian
  • 63
  • 9
  • It is not possible to comment without checking the complete code but still i think you need to update tabView component as well. – psi Jun 13 '14 at 08:08
  • I already tried to update the whole form (tabView included) and didn't work either. I'll try to update specifically the tabView... – Cristian Jun 13 '14 at 12:31
  • I just edited my question with the rest of the code... I just tried that way and didn't work for me. – Cristian Jun 13 '14 at 12:48

1 Answers1

0

You should avoid bindings to managed beans with session scope. This can cause a lot of touble:

JSF 2.0 Spec

3.1.5 Component Bindings

[...]

Component bindings are often used in conjunction with JavaBeans that are dynamically instantiated via the Managed Bean Creation facility (see Section 5.8.1 “VariableResolver and the Default VariableResolver”). It is strongly recommend that application developers place managed beans that are pointed at by component binding expressions in “request” scope. This is because placing it in session or application scope would require thread-safety, since UIComponent instances depends on running inside of a single thread. There are also potentially negative impacts on memory management when placing a component binding in “session” scope.

There are two solutions which could avoid the binding:

In this solution, the output text is always visible and just get a different text from the backed bean:

<h:panelGroup id="someid" layout="block">
    <h:panelGroup id="panelCamposTD" layout="block">
      <h:outputText value="#{myBean.flaggedText}"></h:outputText>
    </h:panelGroup>
</h:panelGroup>

Add the getter to the backed bean:

 public String getFlaggedText(){
       if (flag){          
           return "EDITED";
       }else{          
           return "READ ONLY";
       };
   }   

The other option is to put both output texts in the front end and hide one of them:

   <h:panelGroup id="someid" layout="block">
    <h:panelGroup id="panelCamposTD" layout="block">
      <h:outputText value="EDITED" rendered="#{myBean.flag}"></h:outputText>
      <h:outputText value="READ ONLY" rendered="#{not myBean.flag}"></h:outputText>
    </h:panelGroup> 
</h:panelGroup>
derMrich
  • 316
  • 4
  • 12
  • It's appreciated if you attribute the source where you found this information instead of mimicking an existing answer and doing off as if it's your own. See also http://meta.stackexchange.com/questions/160077/users-are-calling-me-a-plagiarist-what-do-i-do Or, if it happens to be an duplicate Q&A, flag/vote accordingly. – BalusC May 12 '16 at 10:47