AnsweredAssumed Answered

Individual checkbox against each task item

Question asked by kshirod on Jul 11, 2008
Want to display individual checkbox against each and every task item in the dashlet.For that I have written a piece of code:


JSP code:

<h:column>
   <r:actions id="col10-actions" value="reassign_group_task_id"
      context="#{SelectManyCheckBoxBean}" showLink="false"
      styleClass="inlineAction" />
</h:column>
<h:inputHidden id="grpreassign"
   value="#{SelectManyCheckBoxBean.taskItems}" />
<a:richList id="tasks-todo-list" viewMode="details"
   value="#{WorkflowBean.tasksToDo}" var="r" styleClass="recordSet"
   headerStyleClass="recordSetHeader" rowStyleClass="recordSetRow"
   altRowStyleClass="recordSetRowAlt" width="100%" pageSize="10"
   initialSortColumn="created" initialSortDescending="true"
   rendered="#{not empty WorkflowBean.tasksToDo}" refreshOnBind="true">
   <a:column id="col9" actions="true" style="padding:2px;text-align:left">
      <h:selectManyCheckbox id="selectedItems"
         value="#{SelectManyCheckBoxBean.selectedItems}"
         onclick="grpreassign(this);">
         <f:selectItem itemLabel="" itemValue="#{r.id}"
            value="#{SelectManyCheckBoxBean.itemsSelected}" />
      </h:selectManyCheckbox>
   </a:column>
   <%– Primary column for details view mode –%>
   <a:column id="col1" primary="true" width="200"
      style="padding:2px;text-align:left">
      <f:facet name="header">
         <a:sortLink id="col1-sort" label="#{msg.description}"
            value="bpm:description" mode="case-insensitive" styleClass="header" />
      </f:facet>
      <f:facet name="small-icon">
         <a:actionLink id="col1-act1" value="#{r['bpm:description']}"
            image="/images/icons/workflow_task.gif" showLink="false"
            actionListener="#{WorkflowBean.setupTaskDialog}"
            action="dialog:manageTask">
            <f:param name="id" value="#{r.id}" />
            <f:param name="type" value="#{r.type}" />
         </a:actionLink>
      </f:facet>
      <a:actionLink id="col1-act2" value="#{r['bpm:description']}"
         actionListener="#{WorkflowBean.setupTaskDialog}"
         action="dialog:manageTask">
         <f:param name="id" value="#{r.id}" />
         <f:param name="type" value="#{r.type}" />
      </a:actionLink>
   </a:column>
        <a:dataPager styleClass="pager" />
</a:richList>



Java code:

package org.alfresco.sample;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.TransientNode;
import org.alfresco.web.bean.workflow.BaseReassignDialog;
import org.alfresco.web.ui.common.component.UIActionLink;


public class SelectManyCheckBoxBean extends BaseReassignDialog
{
   
   private static final long serialVersionUID = 1L;

   public static final String BEAN_NAME = "SelectManyCheckBoxBean";
   
   private List<String> selectedItems;
   protected NavigationBean navigationBean;
   private String taskItems;
      
   private String itemsSelected;
   
   public SelectManyCheckBoxBean() {
      }
   
   public List<String> getSelectedItems() {
       return selectedItems;
    }

    public void setSelectedItems(List<String> selectedItems) {
        this.selectedItems = selectedItems;
    }
   
    public String getGroupReassign(){
        return "selectManyCheckBox";
    }
   
    @Override
    public void init(Map<String, String> parameters)
    {
       super.init(parameters);
    }
   
    @Override
    protected String finishImpl(FacesContext context, String outcome)
          throws Exception
    {
       return "reassign_grp_task";
    }
   
    @Override
    protected String getErrorMessageId()
    {
       return "error_reassign_task";
    }

   public void setupTaskDialog(ActionEvent event)
      {
         //ParameterCheck.mandatoryString("Task ID", id);
        
         System.out.println("the input to task dialog");
         UIActionLink link = (UIActionLink)event.getComponent();
         Map<String, String> params = link.getParameterMap();
         String id = this.getTaskItems();
         System.out.println("id:::::"+id);
        
         // setup the dispatch context with the task we're opening a dialog for
         //TransientNode node = new TransientNode(QName.createQName(type), id, null);
         //this.navigationBean.setupDispatchContext(node);
        
         // pass on parameters for the dialog
         Application.getDialogManager().setupParameters(event);
      }
   
   public String getTaskItems() {
      System.out.println("Inside getTaskItems() method");
      return taskItems;
   }

   public void setTaskItems(String taskItems) {
      this.taskItems = taskItems;
   }
   
   public void setItemsSelected(String itemsSelected) {
      this.itemsSelected = itemsSelected;
   }
   public String getItemsSelected() {
      return itemsSelected;
   }
}



Java Script:

<script type="text/javascript">
function grpreassign(chkboxObj){
   var selectedTasks= document.getElementById("dashboard:dash-body:dashlet-3-view:grpreassign").value;
   var curVal = chkboxObj.value;
   if(chkboxObj != null)
   {
      if(selectedTasks == "")
         {
            document.getElementById("dashboard:dash-body:dashlet-3-view:grpreassign").value = chkboxObj.value;
         }
         else
         {
            if(selectedTasks.indexOf(curVal) == -1)
            {
               document.getElementById("dashboard:dash-body:dashlet-3-view:grpreassign").value = selectedTasks + "##" + chkboxObj.value;
            }
         }
   }
}
</script>



faces-config.xml

   <managed-bean>
   <managed-bean-name>SelectManyCheckBoxBean</managed-bean-name>
   <managed-bean-class>org.alfresco.sample.SelectManyCheckBoxBean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>   
   <managed-property>
            <property-name>nodeService</property-name>
            <value>#{NodeService}</value>
   </managed-property>
   <managed-property>
            <property-name>workflowService</property-name>
            <value>#{WorkflowService}</value>
   </managed-property>
   </managed-bean>



Also want to pass the selected items(checked task id) to the next page.As soon as I am trying to submit the selected items its throwing null pointer exception.

java.lang.NullPointerException: value
   javax.faces.model.SelectItem.<init>(SelectItem.java:74)
   javax.faces.component._SelectItemsIterator.hasNext(_SelectItemsIterator.java:75)
   javax.faces.component.UISelectMany.validateValue(UISelectMany.java:268)
   javax.faces.component.UIInput.validate(UIInput.java:354)
   javax.faces.component.UISelectMany.validate(UISelectMany.java:297)
   javax.faces.component.UIInput.processValidators(UIInput.java:184)
   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:627)
   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:627)
   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:627)
   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:627)
   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:627)
   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:627)
   javax.faces.component.UIForm.processValidators(UIForm.java:73)
   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:627)
   javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:149)
   org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:32)
   org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
   org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


Please provide me some solutions as sson as possible.

:)

Outcomes