1

I am trying to perform ajax on selecting any element in selectCheckBoxMenu primefaces. But ajax event fires only if itemValue is equal to String. If i am passing object then not event is fired. Please have a look.

package com.gsep.utility.bean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@ManagedBean
@Entity
@ViewScoped
public class Tool {

    @Id @GeneratedValue
    @Column(name="tool_id")
    private int toolId;
    @Column(name="tool_name")
    private String toolName;
    public int getToolId() {
        return toolId;
    }
    public void setToolId(int toolId) {
        this.toolId = toolId;
    }
    public String getToolName() {
        return toolName;
    }
    public void setToolName(String toolName) {
        this.toolName = toolName;
    }


}

Above is my bean class which i am iterating to display values in selectCheckboxMenu. Below is jsf code

        <p:selectCheckboxMenu id="multiple" value="#{projectBean.selectedToolList}" label="Tools" multiple="true"
                              filter="true" filterMatchMode="startsWith" panelStyle="width:250px" >
                                    <f:selectItems value="#{projectBean.toolList}" var="toolObject" itemLabel="#{toolObject.toolName}" itemValue="#{toolObject}" />
                                    <p:ajax  update="projectRequestForm:testTabView" listener="#{projectBean.addTab(requestBean,projectBean)}" />
                            </p:selectCheckboxMenu>

Here if i am changing itemValue attribute to toolObject.toolName then ajax call is happening but i want the selectedToolList as a Tool collection of objects instead of toolName collection of Strings.

@ManagedBean(name = "projectBean")
@ViewScoped
public class ProjectBeanCompUI {    
    @ManagedProperty(value="#{jiraDao}")
    private JiraProjectDAO jiraDao;

    private List<Tool> toolList;
    private List<String> selectedToolList;

    public List<Tool> getToolList() {
        toolList = getTools();
        return toolList;
    }
    public void setToolList(List<Tool> toolList) {
        this.toolList = toolList;
    }   
    public List<String> getSelectedToolList() {
        return selectedToolList;
    }
    public void setSelectedToolList(List<String> selectedToolList) {
        this.selectedToolList = selectedToolList;


        public List<Tool> getTools()
    {
        List<Tool> toolList = new ArrayList<>();
        Tool tool = new Tool();
        tool.setToolId(1);
        tool.setToolName("Eclipse");
        Tool tool1 = new Tool();
        tool1.setToolId(2);
        tool1.setToolName("Jira");
        toolList.add(tool);
        toolList.add(tool1);
        return toolList;
    }
}
Shivani Bhansali
  • 109
  • 1
  • 12
  • edited the subject. Issue seems to be with SelectCheckboxMenu with multiple selections. The ajax call happens only if itemValue is set to String or Integer. It does not happen when we set it to custom object. – Shivani Bhansali Feb 09 '18 at 07:40
  • 1
    Please take note of the duplicate question links in top of your question. The first link should tell you that you should have used h:messages/p:messags to get notified of any submit failure. The second link should explain you about the exact failure. The third link should show you how to correctly solve it. – BalusC Feb 09 '18 at 07:44
  • I Have seen the links provided. Please note that the issue i am facing is with SelectCheckBoxMenu and not selectOneCheckbox. The third link shows details about selectOneCheckbox which is not what I have issue with. – Shivani Bhansali Feb 09 '18 at 08:51
  • 2
    That doesn't matter. Underlying problem and answer is still exactly the same. It doesn't make sense to copypaste the same answer for every single component which happens to use a . The answer as to how to investigate a non-working form submit and how to correctly use is exactly the same for all of them. – BalusC Feb 09 '18 at 09:10
  • Think 'generic' not 'specific'. Helps in many, many other problem solving issues as well. – Kukeltje Feb 09 '18 at 09:46

0 Answers0