Search Results

Search found 2 results on 1 pages for 'ehsun'.

Page 1/1 | 1 

  • <h:selectOneMenu> ValueChangeListener Problem

    - by Ehsun
    I have two <h:selectOneMenu> tags on my form like this: <h:outputText value="#{lbls.incomeType}:"/> <h:selectOneMenu id="incomeType" label="#{lbls.incomeType}" onchange="submit();" valueChangeListener="#{price.earnTypeValueChanged}" immediate="true"> <f:selectItems value="#{price.earnTypes}"/> <f:converter converterId="ir.khorasancustoms.EarnTypeConverter"/> </h:selectOneMenu> <h:message for="incomeType" infoClass="info" errorClass="error" warnClass="warning" fatalClass="fatal"/> <h:outputText value="#{lbls.earnAttribute}:"/> <h:selectOneMenu id="earnAttribute" label="#{lbls.earnAttribute}" value="#{price.price.earnAttribute}"> <f:selectItems value="#{price.earnAttributes}"/> <f:converter converterId="ir.khorasancustoms.EarnAttributeConverter"/> </h:selectOneMenu> <h:message for="incomeType" infoClass="info" errorClass="error" warnClass="warning" fatalClass="fatal"/> <h:messages globalOnly="true" layout="table" infoClass="info" warnClass="warning" errorClass="error" fatalClass="fatal"/> <h:button value="#{lbls.cancel}" outcome="index"/> <h:commandButton value="#{lbls.ok}" action="#{price.save}"/> the handler in the bean looks like this: public void earnTypeValueChanged(ValueChangeEvent event) { EarnType newEarnType = (EarnType) event.getNewValue(); earnAttributes = newEarnType.getAttributes(); FacesContext.getCurrentInstance().renderResponse(); } Everything works fine, except the user needs to press the OK button twice because the first one fires the earnTypeValueChanged. How is that caused and how can I fix it? Update 1: public void earnTypeValueChanged(ValueChangeEvent event) { EarnType oldEarnType = (EarnType) event.getOldValue(); EarnType newEarnType = (EarnType) event.getNewValue(); earnAttributes = newEarnType.getAttributes(); if (!newEarnType.equals(oldEarnType)) { FacesContext.getCurrentInstance().renderResponse(); } }

    Read the article

  • Object as itemValue in <f:selectItems>

    - by Ehsun
    Is it possible to have objects as itemValue in tag? for example I have a class Foo: public class Foo { private int id; private String name; private Date date; } And another class Bar public class Bar { private Foo foos; } public class BarBean { private Set<Foo> foos; } Now in a Bean called BarBean I need to have a to get the Foo of the current Bar from User like this: <h:selectOneMenu value="#{barBean.bar.foo}" required="true"> <f:selectItems value="#{barBean.foos}" var="foo" itemLabel="#{foo.name}" itemValue="#{foo}" /> </h:selectOneMenu> ---------------edited: my converter: package ir.khorasancustoms.g2g.converters; import ir.khorasancustoms.g2g.persistance.CatalogValue; import java.util.ResourceBundle; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.FacesConverter; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; @FacesConverter("ir.khorasancustoms.CatalogValueConverter") public class CatalogValueConverter implements Converter { @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { SessionFactory factory = new Configuration().configure().buildSessionFactory(); Session session = factory.openSession(); try { int id = Integer.parseInt(value); CatalogValue catalogValue = (CatalogValue) session.load(CatalogValue .class, id); return catalogValue; } catch (Exception ex) { Transaction tx = session.getTransaction(); if (tx.isActive()) { tx.rollback(); } ResourceBundle rb = ResourceBundle.getBundle("application"); String message = rb.getString("databaseConnectionFailed"); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, message, message)); } finally { session.close(); } return null; } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { return ((CatalogValue) value).getId() + ""; } } and my facelet: <h:outputText value="#{lbls.paymentUnit}:"/> <h:selectOneMenu id="paymentUnit" label="#{lbls.paymentUnit}" value="#{price.price.ctvUnit}" required="true"> <f:selectItems value="#{price.paymentUnits}"/> <f:converter converterId="ir.khorasancustoms.CatalogValueConverter"/> </h:selectOneMenu> <h:message for="paymentUnit" infoClass="info" errorClass="error" warnClass="warning" fatalClass="fatal"/>

    Read the article

1