0

I am using a selectmanycheckbox to edit entries of a table in a DB (in this case for a user) to create like:

userid | system
1        4
2        4
2        5
2        6
3        4
...  

like this. And it's working just fine. The problem is, that all systems in the selectmanycheckbox are highlighter, even when the selected user has only a few of the available options in the system list.

in detail:

User x has x systems in the DB In the application I set the x systems I call the list where to select systems for that user and it highlights all and not just the systems for that user so it looks like the user had all systems in list.

User Entity:

@ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "users_system_groups", joinColumns = {
            @JoinColumn(name = "user_id", referencedColumnName = "id") }, inverseJoinColumns = {
            @JoinColumn(name = "system_group_id", referencedColumnName = "id") })
    private List<SystemGroup> systemGroups = new ArrayList<>();
html:

<p:selectManyCheckbox layout="pageDirection" value="#{userEditBoundary.user.systemGroups}"
                                              converter="#{systemGroupConverter}">
                            <f:selectItems value="#{systemBoundary.systemGroups}" var="group" itemLabel="#{group.name}"
                                           itemValue="#{group}"/>
                            <p:ajax listener="#{userEditBoundary.save}"/>
                        </p:selectManyCheckbox>

system boundary

    public List<SystemGroup> getSystemGroups() {
        LinkedList<SystemGroup> result = new LinkedList<>();
        for (SystemGroup systemGroup : systemGroupStore.findAll()) {
            if (user.getSubject().isPermitted(LhtPermission.forSystemGroupReadAccess(systemGroup)))
                result.add(systemGroup);
        }
        return result;
    }

SystemGroup Converter

@Inject
    SystemGroupStore systemGroupStore;

    @Override public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String string) {
        SystemGroup systemGroup = systemGroupStore.findOne(Long.parseLong(string));
        return systemGroup;
    }

    @Override public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) {
        if (!(object instanceof SystemGroup))
            throw new IllegalArgumentException(
                    "Object has to be from type SystemGroup, " + object.getClass().getName() + " given!");
        SystemGroup systemGroup = (SystemGroup) object;
        return String.valueOf(systemGroup.getId());
    }

I have no further ideas to solve this and I don't know why all options are checked.

Kevin Andrid
  • 1,795
  • 1
  • 13
  • 25
PROLOGik
  • 68
  • 1
  • 8
  • 1
    Runnable code snippets work differently [here](http://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) it is. – Tiny May 06 '15 at 11:30
  • How is that a duplicate. I maybe was not specific enough in my question, the problem is, that when I open the site with the selectmanycheckbox, it automatically checks (highlights) all options in the box and not only those, that fit to the systems that the user has. I am not sure if implementing equals in my entity will do the job but I'll try. Thank you in advance – PROLOGik May 06 '15 at 13:39
  • Ok that worked, thank you all! – PROLOGik May 13 '15 at 06:43

0 Answers0