java - Primefaces - how to pass parameter between 2 ui:define -


i need pass parameter between 2 forms both being in separate ui:define.

i have web site left part of tree table , center part form. want click node on left side , pass id center part use later on.

the goal enable user add new categories left side treetable. came idea if user clicks '+' sign on treetable form displayed hidden until then.

this main part of layout.

        <p:layoutunit position="west" size="600" header="categories" resizable="true" closable="false" collapsible="true">             <h:form>                 <ui:insert name="westcontent">west default content</ui:insert>             </h:form>         </p:layoutunit>          <p:layoutunit position="center">             <h:form>                 <ui:insert name="centercontent">center default content</ui:insert>             </h:form>         </p:layoutunit> 

this left side content treetable is. want pass document.id form located in centercontent.

<ui:define name="westcontent">     <h:form id="form">          <p:treetable value="#{documentscontroller.root}" var="document"                      selection="#{documentscontroller.selectednodes}" selectionmode="single">              <p:column style="width:300px">                 <f:facet name="header">                     name                 </f:facet>                 <h:outputtext value="#{document.name}" />             </p:column>              <p:column style="width:20px">                 <f:facet name="header">                     add category                 </f:facet>                 <p:commandbutton value="+" styleclass="ui-priority-primary"                                  actionlistener="#{editorbean.print}"                                  onclick="addcategory.show();">                 </p:commandbutton>              </p:column>          </p:treetable>      </h:form> </ui:define> 

this center content want document.id passed into.

<ui:define name="centercontent">     <h:form id="addcategoryform">         <p:panel id="addcategory" widgetvar="addcategory" header="new category" style="margin-bottom:10px;" closable="true" visible="false">             <p:messages id="messages" />             <h:panelgrid columns="3">                 <h:outputlabel for="name" value="name: *" />                 <p:inputtext id="name" value="#{editorbean.name}" required="true" label="name">                     <f:validatelength minimum="2" />                 </p:inputtext>                 <p:message for="name" />                  <h:outputlabel for="description" value="description: *" />                 <p:inputtext id="description" value="#{editorbean.description}" required="true" label="description"/>                 <p:message for="description" />             </h:panelgrid>             <h:panelgrid columns="1">                 <h:outputlabel value="html" />                 <pe:ckeditor id="editor" value="#{editorbean.html}" interfacecolor="#cccccc" />                  <p:commandbutton id="submitbutton" value="submit" update="addcategoryform"                                   icon="ui-icon-disk" actionlistener="#{editorbean.print}" />             </h:panelgrid>         </p:panel>     </h:form> </ui:define> 

this structure of managed bean i'm using.

@managedbean @scope("view") public class editorbean {      private string name;     private string description;     private string html;     private boolean iscategory;     private int id;  } 

i'm used working jsp , old style of handling things in constructors pretty confusing me. i'm open other solutions issue.

i thought can fill id treetable editorbean , fill rest later on doesn't seem work.

thanks replies

just have property in bean keeps selected document command button left form , have accessed right form in way see it.

for example, add property bean:

private document selected;//getter + setter 

preset in command button's action method (el 2.2 , higher), or using <f:setpropertyactionlistener> (el lower 2.2). note onclick wrong place hook on ajax callback events, use oncomplete instead:

<p:commandbutton value="+" styleclass="ui-priority-primary"                  actionlistener="#{editorbean.print}"                  action="#{editorbean.action(document)}"                  oncomplete="addcategory.show();"> </p:commandbutton> 

with

public void action(document document) {     selected = document;     //other business logic } 

or:

<p:commandbutton value="+" styleclass="ui-priority-primary"                  actionlistener="#{editorbean.print}"                  oncomplete="addcategory.show();">     <f:setpropertyactionlistener target="#{editorbean.selected}" value="#{document}" /> </p:commandbutton> 

this way clicked item available in bean. can decompose in action method, if want. can referenced other form , other form's id included in ajax update these changes reflected in it.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -