0

Hy all.Working with JSF 2.2. I have two panelGrid rendered in base of a selection of oneselctmenu. In the panels I want to put some form that should be executed with his ownn command button. The problem is that when the panels are rendered the commandbutton inside doesn't do any action. I know that the cause is due to the evalutation of rendered attribute to false, as mentioned in this post :
[commandButton/commandLink/ajax action/listener method not invoked or input value not updated : The rendered attribute of the component and all of the parent components should not evaluate to false during the apply request values phase of the form submit request.
I tried to bypass the problem adding a param to be evaltated as true in the desidered component, before the "apply request values phase", but it doesn't work. Can anybody help me to understad how achive my goal? The bean is ViewScope. I tried various configurations

     <h:form id="azione0">
    <h:selectOneMenu id="smenu0" value="#{bean.azione}">
        <f:selectItems value="#{bean.azioni}" />
        <f:ajax render=":panels  " />
    </h:selectOneMenu>
</h:form>
 <!--This panel is corrected rendered, but the form dosen't work -->
    <h:panelGroup id="panels"   >
        <h:form rendered="#{bean.azione eq 'A'}" >
        <!-- If I execute this command(AJAX) then  THE BEAN IS RECREATED -->
            <h:commandButton value="Add New user- aajax"
                action="#{bean.addnewUser}">
                <f:ajax execute="@this" render="newuser"  />
            </h:commandButton>
            <h:panelGroup id="newuser" rendered="#{bean.newuserinput}">
            Myname
            <h:inputText id="myname" value="#{bean.myname}" />
            <h:commandButton action="#{bean.saveNewUser()}" value="save" >
            <f:ajax execute="@form" render=":panels"/>
            </h:commandButton>
            </h:panelGroup>
            </h:form>       
</h:panelGroup>

Edit: I have modified the code after many test , and now it is syntetized to isolate the problem.

Community
  • 1
  • 1
antoiovi
  • 23
  • 2
  • 9
  • According to your title you have nested forms but in your code I see none... So please create an [mcve] that demonstrates the problem. And your explanation below the code has nothing about forms. – Kukeltje Nov 23 '15 at 16:43
  • Sorry: nested panels. The first form has a selcteOneMenu. In base of is selection is rendered the panelUser or the panleRoles. In the panelUser there the form newusercheck. The first button is correctly rendered. When it's clicked the panel panelData shoud be renderd. But nothing happen. As soon I post a verifiable example – antoiovi Nov 23 '15 at 16:55
  • Nested forms are most of the time a good way to...get in big trouble in JSF. In your case, I would leverage PrimeFaces p:outputPanel http://www.primefaces.org/showcase/ui/panel/outputPanel.xhtml and update it by id or style selection. If it can fit your requirements, I can provide you a detailed example as an answer proposal. – Ludovic Pénet Nov 23 '15 at 17:02
  • Yes , it could be useful. I wold try with rich facese, but i could try with primefaces if you can post me a good example. – antoiovi Nov 23 '15 at 20:11
  • Apparently bean is simply actually not view scoped. Put a breakpoint in constructor/postconstruct to confirm. – BalusC Nov 24 '15 at 06:13
  • Hy @BalusC . I have made many tests, an modified the code following your post balusc.omnifaces.org/2010/06/…; actually somethig goes wrong with view scope related to ajax calls. The code as rewritten above looks good , but I don't understand why the ajax commands run to that undesidered result. – – antoiovi Nov 25 '15 at 20:18

1 Answers1

0

I have solved the problem inverting the nesting component: If i render a panelGroup with a form that has rendered =false, then when I submit an ajax button the bean is reconstructed; If render a form with a panelGroup that has rendered false, the it works fine . When a component render :panels :

<!--This dosen't work -->       
<h:panelGroup id="panels"   >
            <h:form rendered="#{bean.azione eq 'A'}" >

    <!--This works -->
 <h:form id="panels">
    <h:panelGroup  rendered="#{bean.azione eq 'A'}">
antoiovi
  • 23
  • 2
  • 9
  • This matches point 9 of http://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked, but the bean action should be invoked on second click and forth. – BalusC Dec 30 '15 at 12:52
  • @BalusC Actually on the second click and forth the bean is no more reconstructed, and all the phases are executed, but he bean action (and i tried to insert others input to be executed) is not executed... – antoiovi Dec 30 '15 at 13:34