[jboss-user] [JBoss Seam] - Re: Custom JSF Converter???
nebukadnezzar
do-not-reply at jboss.com
Tue Sep 11 06:18:21 EDT 2007
"pete.muir at jboss.org" wrote : Try using @Converter.
doesn't work...
.page.xml:
| ...
| <param name="category" value="#{appointmentList.appointment.category}" converter="#{appointmentCategoryConverter}" />
| ...
.xhtml
| ...
| <h:selectOneMenu id="category" value="#{appointmentList.appointment.category}" >
| <s:selectItems value="#{appointmentCategoryList.resultList}" var="c" label="#{c.name}" noSelectionLabel="" />
| <s:convertEntity/>
| </h:selectOneMenu>
| ...
.java
| @Converter
| @Name("appointmentCategoryConverter")
| @Stateless
| public class AppointmentCategoryConverterBean implements javax.faces.convert.Converter, AppointmentCategoryConverter {
|
| @PersistenceContext
| private EntityManager entityManager;
|
| public Object getAsObject(FacesContext arg0, UIComponent arg1, String str)
| throws ConverterException {
| try {
| long id = Long.parseLong(str);
|
| return entityManager.createQuery("Select ac from AppointmentCategory where ac.id = :id")
| .setParameter("id", id)
| .getSingleResult();
|
| } catch (Exception e) {
| throw new ConverterException(e);
| }
|
| }
|
| public String getAsString(FacesContext arg0, UIComponent arg1, Object obj)
| throws ConverterException {
| try {
| return Long.toString(((AppointmentCategory)obj).getId());
| } catch (Exception e) {
| throw new ConverterException(e);
| }
| }
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4082929#4082929
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4082929
More information about the jboss-user
mailing list