-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TheCoder4eu/BootsFaces-OSP#942 documented ´<b:selectOneMenu>` with co…
…nverters defined with an annotation like @FacesConverter(forClass=Some.class)
- Loading branch information
1 parent
45f4aaf
commit 915bfea
Showing
4 changed files
with
171 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.bootsfaces.demo.selectOneMenu; | ||
|
||
/** | ||
* Example taken from : https://memorynotfound.com/using-custom-converter-for-hselectonemenu/ | ||
*/ | ||
|
||
public class Wine { | ||
|
||
private Integer id; | ||
private String brand; | ||
|
||
public Wine(Integer id, String brand) { | ||
this.id = id; | ||
this.brand = brand; | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getBrand() { | ||
return brand; | ||
} | ||
|
||
public void setBrand(String brand) { | ||
this.brand = brand; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/bootsfaces/demo/selectOneMenu/WineConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.bootsfaces.demo.selectOneMenu; | ||
|
||
import javax.el.ValueExpression; | ||
import javax.faces.component.UIComponent; | ||
import javax.faces.context.FacesContext; | ||
import javax.faces.convert.Converter; | ||
import javax.faces.convert.FacesConverter; | ||
|
||
/** | ||
* Example taken from : https://memorynotfound.com/using-custom-converter-for-hselectonemenu/ | ||
*/ | ||
|
||
@FacesConverter(forClass = Wine.class) | ||
public class WineConverter implements Converter { | ||
|
||
@Override | ||
public Object getAsObject(FacesContext ctx, UIComponent uiComponent, String wineId) { | ||
System.out.println("getAsObject:" + wineId); | ||
|
||
ValueExpression vex = ctx.getApplication().getExpressionFactory().createValueExpression(ctx.getELContext(), | ||
"#{beersBean}", BeersBean.class); | ||
|
||
BeersBean beers = (BeersBean) vex.getValue(ctx.getELContext()); | ||
return beers.getWine(Integer.valueOf(wineId)); | ||
} | ||
|
||
@Override | ||
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object wine) { | ||
System.out.println("getAsString:" + wine); | ||
return ((Wine) wine).getId().toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters