0

All,

I have been reading and searching and although there are several itens on it, it seems that I'm missing something. My form keeps failing on the converted of a selectOneListBox

I have read and searched but so far I have not found what is causing this issue. The possible reasons as far as I have read and found are as follows:

  1. The Object.equals() not correct
  2. The list of the menu is empty.

Inline is my Converter based on Users class:

@FacesConverter("misc.util.UserConverter")
public class UserConverter implements Converter {
    private static HashMap<String, Users> map = new HashMap<String, Users>();
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Users user = map.get(value);
        Logger.getGlobal().log(Level.INFO, "UserConverter - getAsObject " + user.getEmail());
        Logger.getGlobal().log(Level.INFO, "UserConverter - getAsObject value " + value);
        return user;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Users user = (Users)value;
        map.put(user.getEmail().toString(), user);
        Logger.getGlobal().log(Level.INFO, "UserConverter - getAsString");
        return user.getEmail().toString();
    }
}

The code that is failing:

ticketUpdateController.lovResearchers - type List - list obtained from JpaController. ticketUpdateController.researcher - type Users

I tried to add also the inputHidden as this page has a viewParam and I need to maintain this value to refresh. Although without it it happens the same.

    <p:dialog id="assignResearcherDialog" header="Assign Researcher" widgetVar="assignResearcher" resizable="false">
        <h:form id="assignResearcherForm">
            <p:panel>
                <p:selectOneListbox id="selRec" value="#{ticketUpdateController.researcher}">
                    <f:selectItems value="#{ticketUpdateController.lovResearchers}" var="r" itemLabel="#{r.email}" itemValue="#{r}"></f:selectItems>
                    <f:converter converterId="misc.util.UserConverter"></f:converter>
                    <h:inputHidden value="#{ticketUpdateController.ticketNumber}"></h:inputHidden>
                </p:selectOneListbox>
                <p:commandButton value="Assign" actionListener="#{ticketUpdateController.setResearcher}" oncomplete="handleSubmitRequest(xhr, status, args, 'assignResearcherDialog','assignResearcherForm');" update=":ticketUpdateForm :message">
                    <h:inputHidden value="#{ticketUpdateController.ticketNumber}"></h:inputHidden>
                    <f:param id="tnr" value="#{ticketUpdateController.ticketNumber}"></f:param>
                </p:commandButton>
            </p:panel>
        </h:form>
    </p:dialog>

My troubleshooting:

  • I have check the Users class and the equals is not being called at all. (check by putting a logger there)
  • Put logging in the converter class to see when it is called. So far seems to be called when its neede. JSF page load up and when I press some button.
  • Added loggerto the init of by TicketUpdateController bean so that I can see if the values are still in memory or not.
WARNING: class gui.controller.TicketUpdateController Starting... 
WARNING: class gui.controller.TicketUpdateController Setting Values...
INFO: UserConverter - getAsString INFO: UserConverter - getAsString
INFO: UserConverter - getAsString INFO: UserConverter - getAsString
WARNING: class gui.controller.TicketUpdateController Starting... 
WARNING: class gui.controller.TicketUpdateController Setting Values...
INFO: UserConverter - getAsString INFO: UserConverter - getAsString
INFO: UserConverter - getAsString INFO: UserConverter - getAsString
INFO: UserConverter - getAsObject Researcher@localhost.com 
INFO:UserConverter - getAsObject value Researcher@localhost.com 
WARNING: class gui.controller.TicketUpdateController Starting...
Alexandre Alves
  • 411
  • 2
  • 10
  • 20
  • 1
    This can also happen if the state of `ticketUpdateController.lovResearchers` is inconsistent mid-request. How/where are you initializing the List? `map.put(user.getEmail().toString(), user);` is also probably not a good idea. It's safest to ensure that no datastore should be modified midrequest – kolossus Mar 06 '13 at 02:27
  • The lovResearchers is being created in a @PostContruct init with the following: this.setLovResearchers(ujc.findUsersEntitiesByRole("Researcher")); And the map in the Converter is just related to the converter itself. This converter is basically a copy of another that I have for another class (Roles) and in this case it works fine. I'll try to put the Roles converter here for troubleshooting sake, as I know this one works in another page and see what happens. – Alexandre Alves Mar 06 '13 at 05:55

1 Answers1

0

Found what was wrong.

So basically I was using the wrong class.
My page bean was TicketUpdateController but my Converter is for Users.

So I changed the field int he selectedItems from TicketUpdateController to UsersController.

After all I should obtain all my Users from UsersController instead of TicketUpdatecontroller.

Alexandre Alves
  • 411
  • 2
  • 10
  • 20