コンバーターに問題があります。コンバーターが機能しなくなり、何も起こりません。エンティティクラス「グループ」があります。
@Entity
@Table(name="users_group")
public class Group implements Serializable {
private int id;
private String name;
private boolean active = true;
private String code;
private List<User> users = new ArrayList<User>();
// getters, setters
@Override
public String toString() {
return "Group.id="+getId();
}
@Override
public boolean equals(Object obj){
System.out.println("OBJ :"+obj);
if(obj == null )return false;
if(obj instanceof String){
if(obj.toString().equals(this.toString())){
return true;
}
}
if(obj instanceof Group){
Group objGroup = (Group) obj;
if(objGroup.getId() == this.getId()){
System.out.println("EUREKA! Found");
return true;
}
}
return false;
}
}
これが私のjsfビューコードです:
<p:selectOneMenu id="group" value="#{priviligeMB.groupPrivilige.group}" converter="#{groupConverter}" >
<f:selectItems value="#{priviligeMB.groups}"
var="group" itemLabel="#{group.name}" itemValue="#{group}" />
</p:selectOneMenu >
そしてもちろん、GroupConverterクラス:
@Component("groupConverter")
public class GroupConverter implements Converter {
@Autowired
GroupService groupService;
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
// arg2 is "Group.id=x" where x is just an id, for example "Group.id=2"
try {
System.out.println("getasObj: "+arg2);
return groupService.getGroupById(Integer.parseInt(arg2.split("=")[1]));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
// arg2 is object with toString() method that prints: "Group.id=x"
System.out.println("getAsString: "+arg2);
return arg2.toString();
}
}
これが私のログです:
> getAsString: Group.id=1
> getAsString: Group.id=2
> Hibernate: SELECT locale.code from messages_locale locale left join users_user u sers on
> users.locale_id = locale.id where users.username =?
> getasObj: Group.id=1
> Hibernate: select group0_.id as id0_0_, group0_.active as
> active0_0_, group0_.co de as code0_0_, group0_.name as name0_0_ from
> users_group group0_ where group0_. id=?
> OBJ :Group.id=1 EUREKA! Found
> OBJ :Group.id=1 EUREKA! Found
> OBJ :Group.id=2
そしてその後...何も起こらなかった!エラー、アクション、ページのリロード、メッセージはありません...