jsf - How do UISelectOne and UISelectMany components preselect defaults in f:selectItems -


i know how preselect <p:selectonemenu>, in selected value should 1 of objects <f:selectitems>, how component work under hood , can change behavior?

in case i've duplicate object, 2 objects same values created twice , selected object in <p:selectonemenu> differs object <f:selectitems> , doens't recognize it. change design so, point same object in case can't due legacy code or etc, how can change behavior of <p:selectonemenu> compare objects id example?

i'd thought converter responsible it, when rendered doesn't enter on getasobject method getasstring, guess there's different, what?

thank you

it uses object#equals() that. can change (fix) behavior implementing accordingly on entity.

private long id;  @override public boolean equals(object other) {     return (other != null && getclass() == other.getclass() && id != null)         ? id.equals(getclass().cast(other).id)         : (other == this); } 

don't forget hashcode() satisfy equals-hashcode contract.

@override public int hashcode() {     return (id != null)          ? (getclass().hashcode() + id.hashcode())         : super.hashcode(); } 

if can't change existing entity unclear reason, wrap in own dto.

the converter converts between entity , unique string representation usage in html output , http request parameters , has therefore no influence on preselection. has influence on potential validation error: value not valid trouble.

see also:


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -