2 Replies Latest reply on Feb 22, 2011 10:26 PM by psramkumar.ps.ramkumar.gmail.com

    Extended Datatable with Modalpanel

    bhr9119

      Hi all...

      I am facing the problem ExtendedDataTable with MODAL PANEL.In the ExtendedDataTable I am using context menu for selecting EDIT,NEW,DELETE buttons. I used MODAL PANEL for edit the selected Row object,But it displays previous rowobject not displays current row object.
      i want the modalPannel to display the current row object .
      I am sending all files(xhtml and java)



      Thank you.
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"

          xmlns:a="http://richfaces.org/a4j"
          template="layout/template.xhtml">

      <ui:define name="body">

          <rich:panel>
              <f:facet name="header">Countries</f:facet>
               <div class="results" id="countryList">


                     <h:form id="countryListForm" styleClass="edit">

                     

                           <rich:contextMenu submitMode="server" id="m" attached="false">

                                <rich:menuItem action="#{countryS.selectCountry}"

                                     value="Edit: {param}" submitMode="ajax" immediate="true"

                                     actionListener="#{countryS.actionListener}" icon="/img/ico_edit.gif"

                                     oncomplete="javascript:Richfaces.showModalPanel('countryListForm:_panel2');">

                                     <a:actionparam assignTo="#{countryS.param}" name="param" value="{param}">

                                     </a:actionparam>

                                </rich:menuItem>

                                

                                <rich:menuSeparator id="menuSeparator1" />

                                

                                <rich:menuItem action="#{countryS.delete}"

                                     value="Delete: {param}" submitMode="ajax" immediate="true"

                                     actionListener="#{countryS.actionListener}" icon="/img/ico_delete.gif">

                                     <a:actionparam assignTo="#{countryS.param}" name="param"

                                          value="{param}">

                                     </a:actionparam>

                                </rich:menuItem>

                                

                                <rich:menuSeparator id="menuSeparator2" />

                                

                                <rich:menuItem action="#{countryS.new}"

                                     value="New" submitMode="ajax" immediate="true"

                                     actionListener="#{countryS.actionListener}" icon="/img/ico_new.gif">

                                </rich:menuItem>

                          </rich:contextMenu>

                          

                         <h:outputText value="The country search returned no results."
                               rendered="countries != null and countries.rowCount==0}"/>
                          

                          <rich:extendedDataTable id="countryListTable" var="_country"

                               selectionMode="single" height="190px"

                              value="#{countries}"

                           rendered="#{countries.rowCount > 0}">

                                     

                               <rich:column id="regionCode" width="140px" sortable="true"

                                    sortBy="#{_country.region.regionCode}"

                                    filterBy="#{_country.region.regionCode}"

                                    filterEvent="onkeyup" label="Region Code">

                                  <f:facet name="header">

                                       <h:outputText styleClass="headerText" value="Region Code"/>

                                  </f:facet>

                                    <h:outputText value="#{_country.region.regionCode}"/>

                               </rich:column>

                

                               <rich:column id="countryCode" width="140px" sortable="true"

                                    sortBy="#{_country.countryCode}"

                                    filterBy="#{_country.countryCode}"

                                    filterEvent="onkeyup" label="Country Code">

                                  <f:facet name="header">

                                       <h:outputText styleClass="headerText" value="Country Code"/>

                                  </f:facet>

                                    <h:outputText value="#{_country.countryCode}"/>

                               </rich:column>

                

                               <rich:column id="countryName" width="150px" sortable="true"

                                    sortBy="#{_country.name}"

                                    filterBy="#{_country.name}"

                                    filterEvent="onkeyup" label="Country Name">

                                  <f:facet name="header">

                                       <h:outputText styleClass="headerText" value="Country Name"/>

                                  </f:facet>

                                    <h:outputText value="#{_country.name}"/>

                                    

                               </rich:column>

                               

                               <rich:column id="countryFActive" width="100px" sortable="true"

                                    sortBy="#{_country.FActive}" label="Active">

                                  <f:facet name="header">

                                       <h:outputText styleClass="headerText" value="Active"/>

                                  </f:facet>

                                    <h:outputText value="#{_country.FActive}"/>

                                    <rich:componentControl event="oncontextmenu" attachTo="regionCode,countryCode,countryName,countryFActive" for=":countryListForm:m"

                                                   operation="doShow">

                                                   <f:param name="param" value="#{_country.countryId}"></f:param>

                                    </rich:componentControl>

                               </rich:column>

                          </rich:extendedDataTable>

                

                          <rich:modalPanel height="400" top="100" width="600" id="_panel2" controlsClass="pointerCursor" zindex="500">

                               

                               <rich:panel>

                                 <f:facet name="header">Country</f:facet>

                                 <s:decorate id="countryCodeField" template="layout/edit.xhtml">

                                     <ui:define name="label">Country code</ui:define>

                                     <h:inputText id="countryCode"

                                            required="true"

                                                size="5"

                                           maxlength="5"

                                               value="#{country.countryCode}">

                                         <a:support event="onblur" reRender="countryCodeField" bypassUpdates="true" ajaxSingle="true"/>

                                     </h:inputText>

                                 </s:decorate>

           

                                    <s:decorate id="regionField" template="layout/edit.xhtml">

                                     <ui:define name="label">Region</ui:define>

                                     <h:selectOneMenu value="#{country.region}" required="true" id="region">

                                         <s:selectItems value="#{regiones}" var="region" label="#{region.name}" noSelectionLabel="Please Select..."/>

                                         <s:convertEntity />

                                    </h:selectOneMenu>

                                 </s:decorate>

                      

                                 <s:decorate id="nameField" template="layout/edit.xhtml">

                                     <ui:define name="label">Name</ui:define>

                                     <h:inputText id="name"

                                            required="true"

                                                size="50"

                                           maxlength="100"

                                               value="#{country.name}">

                                         <a:support event="onblur" reRender="nameField" bypassUpdates="true" ajaxSingle="true"/>

                                     </h:inputText>

                                 </s:decorate>

           

           

                                 <s:decorate id="FActiveField" template="layout/edit.xhtml">

                                     <ui:define name="label">F active</ui:define>

                                     <h:inputText id="FActive"

                                            required="true"

                                                size="2"

                                           maxlength="2"

                                               value="#{country.FActive}">

                                         <a:support event="onblur" reRender="FActiveField" bypassUpdates="true" ajaxSingle="true"/>

                                     </h:inputText>

                                 </s:decorate>

                                 <div style="clear:both">

                                     <span class="required">*</span>

                                     required fields

                                 </div>

                             </rich:panel>

                             

                             <div class="actionButtons">

                     

                                 <h:commandButton id="save"

                                               value="Save"

                                              action="#{countryS.persist}"/>

                     

                                 <s:button id="cancel"

                                        value="Cancel"

                                  propagation="end"/>

                     

                             </div>

                     

                          </rich:modalPanel>

                     </h:form>


               </div>
          </rich:panel>


      </ui:define>

      </ui:composition>




      @Stateful
      @Name("countryS")
      @Scope(ScopeType.SESSION)
      public class CountrySAction implements  CountryS  {
           
           
           @PersistenceContext(type=PersistenceContextType.EXTENDED)
           private EntityManager em;
           
           @In(required=false, create=true)
           @Out(required=false)
           private Region region;
           
           @Logger
           private Log log;
           
           private int param;
          
           @DataModel
           private List<Country> countries;
          
           @DataModelSelection
           @Out(value="country", required=false)
           @In(value="country", required=false)
           private Country selectedCountry;
         
           @Factory
           @Observer("countryConfirmed")
           @SuppressWarnings("unchecked")
           public void getCountries()
           {
                String qry = "select country from Country country";
                countries = em.createQuery(qry).getResultList();
           }
          
           public void selectCountry() {
                System.out.println("Selected Country.................: " + param);
                // refetch the region, loading all lazy associations
                selectedCountry = em.find(Country.class, param);
                selectedCountry.getRegion();
                System.out.println("Selected Country.................: " + selectedCountry.getName());
           }

           public Country getSelectedCountry()
           {
             return selectedCountry;
           }
          
           public String addCountry() {
                selectedCountry = new Country();
                //region = new Region();
                //selectedCountry.setRegion(region);
               return "sucess";
           }

         
           public String persist() {
                //selectedCountry = new Country();
                log.info(":Rao:------------Country Code" + selectedCountry.getCountryCode());
                log.info(":Rao:------------Region Code" + selectedCountry.getRegion().getRegionCode());
               
                /*if (region != null){
                     region = em.find(Region.class, region.getRegionId());
                     selectedCountry.setRegion(region);
                }*/
                em.persist(selectedCountry);
                log.info(":Rao:------------persisted");
           return "success";
           }
          
           public String remove(){
                selectedCountry = em.find(Country.class, selectedCountry.getCountryId());
                if(selectedCountry!=null)
                em.remove(selectedCountry);
                     return "String";
                    
                }
                public String update(){
                   selectedCountry = em.find(Country.class, selectedCountry.getCountryId());
                     if(selectedCountry!=null)
                     em.merge(selectedCountry);
                    
                  
                     return "String";
                }
               
                public  void selectRegion(){
                    if (region != null)
                    {
                       region = em.find(Region.class, region.getRegionId());
                    selectedCountry.setRegion(region);
                    }
                }  
           
           public int getParam() {
                return param;
           }

           public void setParam(int param) {
                this.param = param;
           }
           
           public void delete() {
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage("Package deleted: " + param));
                //System.out.println("Bean.action()" + param);
           }
           
           public void edit() {
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage("Package edited: " + param));
                //System.out.println("Bean.action()" + param);
           }
           
           /*public void actionListener(ActionEvent event) {
                log.info(":Rao:------------Bean.actionListener()" + event.getComponent());
                System.out.println("Bean.actionListener()" + event.getComponent());
           }*/
           
           @Destroy @Remove
           public void destroy() {}
           }