Calendar convertermessage

UI Components for JSF
Post Reply
edudebom
Posts: 70
Joined: 14 Jan 2011, 18:01
Location: Brazil

30 Apr 2012, 21:42

I would like to put a converter on a Calendar. I tried this code:

Code: Select all


import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;

@FacesConverter(value = "converteData")
public class ConverteData implements Converter {

    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");   
    
    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        
        df.setLenient(false);
        try {
            
            return df.parse(arg2);            
            
        } catch (Exception e) {
            
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro", null));
            
            throw new ConverterException( new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error2", null) ); 
        }
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        try {
            
            df.setLenient(false);
            String d = df.format((Date) arg2);
            
            return d;
        } catch (Exception e) {
            return "";
        }
    }
}
It work's except the converterMessage. This line code is displayed in the growl so is not growl error.
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro", null));

But the throw new ConverterException message and de converterMessage does not appear.

My component:

Code: Select all

                            <p:calendar value="#{pedidoMB.dataEmissao}"
                                        size="10"
                                        pattern="dd/MM/yyyy"
                                        converter="converteData"
                                        converterMessage="Erro ao converter data de emissão">
Mojarra 2.1.6; GlassFish 3.1.2.2; PrimeFaces 4.0-SNAPSHOT
Brasil

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

01 May 2012, 05:07

Do you have h:message, h:messages, p:message, or p:messages in your xhtml? Please reply with more of your xhtml, so we can verify and/or see what is responsible for displaying the message.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

edudebom
Posts: 70
Joined: 14 Jan 2011, 18:01
Location: Brazil

02 May 2012, 20:49

Code: Select all

<p:growl id="msgCadPed" globalOnly="true"/>
<h:form id="dadosPedidos">
      <p:calendar value="#{pedidoMB.dataEmissao}"                                        
                                        pattern="dd/MM/yyyy"
                                        converter="converteData"
                                        converterMessage="Erro ao converter data de emissão">

      <p:commandButton
                    value="Gravar"
                    process="dadosPedidos"
                    action="#{pedidoMB.cadastraPedido}"
                    update=":msgCadPed" />
</h:form>
But I would like to show the converterMessage error.
Mojarra 2.1.6; GlassFish 3.1.2.2; PrimeFaces 4.0-SNAPSHOT
Brasil

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

02 May 2012, 20:55

Add a p:message or h:message 'for' the following component, add id="..." to p:calendar and respond with your test results:

Code: Select all

      <p:calendar value="#{pedidoMB.dataEmissao}"                                        
                                        pattern="dd/MM/yyyy"
                                        converter="converteData"
                                        converterMessage="Erro ao converter data de emissão">
Refer to showcase or user guide for sample code for p:message,

OR remove globalOnly="true" from p:growl and reply with your test results.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

edudebom
Posts: 70
Joined: 14 Jan 2011, 18:01
Location: Brazil

02 May 2012, 22:28

I changed to <p:messages id="msgCadPed" /> and it work's. The problem is that in all pages of the project is used to growl. :?
Mojarra 2.1.6; GlassFish 3.1.2.2; PrimeFaces 4.0-SNAPSHOT
Brasil

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests