0 Replies Latest reply on Sep 22, 2010 5:24 AM by Vasyl Tegza

    howto a4j:commandButton in rich:column 4.0.0.20100826-M2 ?

    Vasyl Tegza Newbie

      Hi all.

       

      here is a problem : when I use a4j:commandButton inside subTable`s column, action not triggered well, in reality it working only on second click after first load.

       

      xhtml page used as component:

       

       

      <h:form>

              <rich:dataTable var="template" value="#{mailTemplateList.sharedMailTemplates}" >

                  <rich:column>

                      <rich:subTableToggleControl for="efields" />

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

                  </rich:column>

                  <rich:subTable id="efields" var="templateFields" value="#{template.template}" expandMode="client"  >

                      <rich:column id="efields">

                          <a4j:commandButton  value="edit" action="#{mailTemplateManagment.editIt(template.id)}" />

                          <h:inputTextarea id="tarea" value="#{templateFields}" style="width:1000px;height:200px" readonly="#{mailTemplateManagment.getEditFlag(template.id)}"/>

                          <p/>

                      </rich:column>

                  </rich:subTable>

              </rich:dataTable>

          </h:form>

       

              <rich:dataTable var="template" value="#{mailTemplateList.sharedMailTemplates}" >
                  <rich:column>
                      <rich:subTableToggleControl for="efields" />
                      <h:outputText value="#{template.name}"/>
                  </rich:column>
                  <rich:subTable id="efields" var="templateFields" value="#{template.template}" expandMode="client"  >
                      <rich:column id="efields">
                          <a4j:commandButton  value="edit" action="#{mailTemplateManagment.editIt(template.id)}" />
                          <h:inputTextarea id="tarea" value="#{templateFields}" style="width:1000px;height:200px" readonly="#{mailTemplateManagment.getEditFlag(template.id)}"/>
                          <p/>
                      </rich:column>
                  </rich:subTable>
              </rich:dataTable>
          </h:for

       

      mailTemplateManagment bean :

       

       

      @Named

      @SessionScoped

      public class MailTemplateManagment implements Serializable{

          @EJB

          private FenixLoggerFactory logger;

       

          @Inject

          private MailTemplateList mailList;

       

          public MailTemplateManagment() {

          }

       

          @PostConstruct

          private void initResources(){

              initHashMaps();

          }

       

          private HashMap<Long, Boolean> editBoolHashmap;

       

          private void initHashMaps() {

              this.editBoolHashmap = new HashMap<Long, Boolean>();

              for (OasysMailTemplateEntity mail : mailList.getSharedMailTemplates()) {

                  editBoolHashmap.put(mail.getId(), true);

              }

          }

       

          public void editIt(long id){

              setAllEdits(true);

              editBoolHashmap.put(id,false);

              logger.log(FenixLoggerFactory.LogMod.Hydra, Level.INFO ,"### set editing id = " + id +" result map is =" + editBoolHashmap);

          }

       

          private void setAllEdits(boolean value){

              for(Long key :editBoolHashmap.keySet()){

                 editBoolHashmap.put(key,value);

              }

          }

       

          public HashMap<Long, Boolean> getEditBoolHashmap() {

              return editBoolHashmap;

          }

       

          public void setEditBoolHashmap(HashMap<Long, Boolean> editBoolHashmap) {

              this.editBoolHashmap = editBoolHashmap;

          }

          public boolean getEditFlag(long id){

              logger.log(FenixLoggerFactory.LogMod.Hydra, Level.INFO ,"get editing id = " + id +" result map is =" + editBoolHashmap);

              return editBoolHashmap.get(id);  

          }

      }

      mailTemplateList bean:
      @Named
      @RequestScoped
      public class MailTemplateList {
          @EJB
          private MailServiceBean mservice;
          public MailTemplateList() {
          }
          private ArrayList<OasysMailTemplateEntity> sharedMailTemplates = null;
          public ArrayList<OasysMailTemplateEntity> getSharedMailTemplates() {
              try {
                  sharedMailTemplates = new ArrayList<OasysMailTemplateEntity>(mservice.getSharedMailtemplatesList());
              } catch (NullPointerException e) {
                  return null;
              }
              return sharedMailTemplates;
          }
          public void setSharedMailTemplates(ArrayList<OasysMailTemplateEntity> sharedMailTemplates) {
              this.sharedMailTemplates = sharedMailTemplates;
          }
      }
      Screen shot 2010-09-14 at 20.16.05.png
      the logs shows :
      INFO: get editing id = 1 result map is ={1=true, 2=true}
      Sep 14, 2010 7:45:12 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 2 result map is ={1=true, 2=true}
      Sep 14, 2010 7:45:14 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 0 result map is ={1=true, 2=true}
      Sep 14, 2010 7:46:49 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 1 result map is ={1=true, 2=true}
      Sep 14, 2010 7:46:49 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 2 result map is ={1=true, 2=true}
      Sep 14, 2010 7:46:55 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 1 result map is ={1=true, 2=true}
      Sep 14, 2010 7:46:55 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 2 result map is ={1=true, 2=true}
      Sep 14, 2010 7:49:01 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: ### set editing id = 0 result map is ={0=false, 1=true, 2=true}
      Sep 14, 2010 7:50:09 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: ### set editing id = 0 result map is ={0=false, 1=true, 2=true}
      Sep 14, 2010 7:50:47 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 2 result map is ={1=true, 2=true}
      Sep 14, 2010 7:50:47 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 1 result map is ={1=true, 2=true}
      Sep 14, 2010 7:53:02 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 1 result map is ={1=true, 2=true}
      Sep 14, 2010 7:53:02 PM ua.co.oasys.fenix.report.FenixLoggerFactory log
      INFO: get editing id = 2 result map is ={1=true, 2=true}

       

      the string:

      ### set editing id = 0 result map is ={0=false, 1=true, 2=true}

      shows that action

      action="#{mailTemplateManagment.editIt(template.id)}" gives wrong parameter.

      but more strange why button works not properly, only in some condition..

       

      In addition, when I trying to use standard button :

      <h:commandButton  value="edit" action="#{mailTemplateManagment.editIt(template.id)}" />

      I got an exception

       

       

      java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.sun.faces.application.view.StateHolderSaver

           at com.sun.faces.application.view.StateManagementStrategyImpl$4.invokeContextCallback(StateManagementStrategyImpl.java:288)

           at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1253)

           at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:672)

           at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1262)

           at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:672)

           at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:284)

           at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:177)

           at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:131)

           at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:430)

           at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:143)

           at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:288)

           at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:199)

           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

           at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)

           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)

           at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)

           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)

           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)

           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)

           at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)

           at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)

           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)

           at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)

           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)

           at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)

           at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)

           at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)

           at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)

           at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)

           at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)

           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)

           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)

           at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)

           at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)

           at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)

           at com.sun.grizzly.ContextTask.run(ContextTask.java:69)

           at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)

           at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)

           at java.lang.Thread.run(Thread.java:619)

       

       

      some ideas || help ?

       

      Thank you.