1

In my backend view, I have a list of some POJO:

BackingView.java

@Getter @Setter private List<SomePOJO> pojoList = ...

SomePojo.java

@EqualsAndHashCode(callSuper = false, of = {"id"})
public class SomePojo implements Serializable {

    private static final long serialVersionUID = 1L;
    
    @Getter @Setter private Long id;
    @Getter @Setter private Long date;
    @Getter @Setter private Date name;
    ....
    
  @Override
  public String toString() {
      return String.format("%s[id=%s]", getClass().getSimpleName(), id);
  }

  //making a readable string-representation of the object to display on the orderList
  public String toStringOrderlistDisplay() {
      return "Pojo with id " + id + "and so on... " 
  }

This list acts as you would expect in all regards. Recently, I wanted to add a feature to my frontend which allows the user to manually order this list. For that purpose I use Primefaces OrderList, like this:

Frontend.xhtml

<p:orderList id="ordList" widgetVar="ordList"
                                     value="#{backingview.pojoList }" var="rfg"
                                     controlsLocation="left"  responsive="true" itemValue="#{rfg}"
                                     itemLabel="#{rfg.toStringOrderlistDisplay()}">
    
</p:orderList>

As soon as I add the above p:orderList to my .xhtml file, I can see when inspecting in debug mode that pojoList no longer contains instances of PojoClass but rather plain strings (to be more precise, the string representation of the PojoClass-Object (What the toString() method would return)). If I simply remove the orderList this problem does not occur. What is going on here? How is such a thing even possible in Java?

Christian O.
  • 468
  • 2
  • 12

1 Answers1

2

I tried using a converter as shown here CountryConverter.java, and it worked.

Maybe when you don't specify a convertor, it uses a default .toString() implementation and can't serialize back to a PojoClass.

You can submit an issue here to see if it's a bug.

stefan-dan
  • 586
  • 5
  • 19