0

I have situation here. I use managed bean as converter to pre populate SelectManyCheckBox from database and it works good. Here is my Converter class

@ManagedBean
@RequestScoped
public class RoleConverter implements Converter{
    @EJB
    private UserRoleSingleton userRoleSingleton;


    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if(value == null){
            return null;
        }
        return userRoleSingleton.getUserRoleById(Integer.parseInt(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(!(value instanceof Userrole) || ((Userrole) value).getRoleId() == null){
            return null;
        }
        Userrole role = (Userrole) value;
        return String.valueOf(role.getRoleId());
    }

    public RoleConverter() {
    }
}

After it preselect checkboxes I select or deselect check boxes or do nothing and click submit button in form. Then button's first click just executes convertor's getAsString method again and reload page. And on second click it executes getAsObject method as expected then action.

Here is my SelectManyCheckBox:

<p:selectManyCheckbox id="orgpermission"
    value="#{adminView.selectedrolesorg}" layout="pageDirection">
    <f:selectItems value="#{adminView.allRolesRelatedToOrgInfo}"
        var="citrole" itemValue="#{citrole}"
        itemLabel="#{citrole.roledescription}" converter="#{roleConverter}" />
</p:selectManyCheckbox>

Why does it executes getAsString method again and how to solve it to fire action method on first click?

Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
Odgiiv
  • 683
  • 1
  • 11
  • 32
  • Why do you think that the converter is the cause? Does the button not require 2 clicks anymore if you remove `` from the form? – BalusC Jan 20 '13 at 01:48
  • oh I'm sorry button does require 2 clicks even if I removed . What is cause then pls – Odgiiv Jan 20 '13 at 03:58
  • Edit your question accordingly so that you ask a question about that instead, preferably along a copy'n'paste'n'runnable example along with an use case which should reproduce the problem for us (and you!) when copied into a completely blank project with everything set to default (unless explicitly otherwise mentioned). Usually, the cause is that the form content is been ajax-updated beforehand, but didn't receive a proper view state. There are various solutions depending on the use case. – BalusC Jan 20 '13 at 04:05
  • Maybe it's unrelated but anyway: I'm curious how does your `@EJB` injection work, cause from what I know you can inject `@EJB` only in `@ManagedBean`. What's more - I can't see `converter=""` in your `` tag. – gadzix90 Jan 20 '13 at 07:04
  • sorry I edited my question. it's managed bean implementing Converter. We can use that managed bean as converter – Odgiiv Jan 20 '13 at 08:04

0 Answers0