webtier@glassfish.java.net

Re: [webtier] JSF2 Nightly Build - Custom Component and Form Submit

From: Jim Driscoll <Jim.Driscoll_at_Sun.COM>
Date: Tue, 07 Apr 2009 22:04:59 -0700

Sorry, I shouldn't answer emails after 9pm - the reason the message is
doubled is because you have a message with only a summary, and you have
showDetail=true.

remove showDetail, and it's only one message.


Jim

On 4/7/09 9:57 PM, Jim Driscoll wrote:
> I'm afraid I wasn't able to duplicate your error, unfortunately.
>
> I was able to get the doubled Messages though, and I've filed that as
> bug # 1068.
>
> I wasn't able to completely duplicate your code, of course, and it has a
> lot of moving parts - if you could simplfy it to a small code section
> demonstrating the bug, that would be helpful in diagnosing the problem...
>
> Jim
>
> On 4/2/09 4:45 AM, webtier_at_javadesktop.org wrote:
>> Well, about the error, it was probably cause i'm using JBoss EL, maybe
>> a compatibility issue (i was mixing technologies for my testings),
>> anyway i removed it and it started to work again (now i'm testing with
>> plain jsf). But i found another problem.
>>
>> When i submit the form (using f:ajax), my action add a faces message
>> and populates a list, i used the render="@all" attribute, so i
>> expected that after the method invocation my list and my message get
>> rendered with their new values, but that's not what happened, not with
>> my custom component rendered in the form at least, because if i
>> comment it all the stuff start to work again. Another strange thing,
>> my faces message is being duplicated (but i think that it probably my
>> fault).
>>
>> Anyway, here it's the code. (Tomcat 6.0.18 / Nightly Build (yesterday
>> 01/04))
>>
>> ---------------------------------------------------------------------------------------------------------
>>
>> Main Page
>> ---------------------------------------------------------------------------------------------------------
>>
>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>> <ui:composition xmlns="http://www.w3.org/1999/xhtml"
>> xmlns:f="http://java.sun.com/jsf/core"
>> xmlns:h="http://java.sun.com/jsf/html"
>> xmlns:ui="http://java.sun.com/jsf/facelets"
>> template="/templates/template.xhtml"
>> xmlns:my="http://java.sun.com/jsf/composite/componentes">
>>
>> <h:form id="formulario">
>> Nome:
>> <h:inputText id="nome" value="#{crudTeste.pessoa.nome}"/>
>> <br/>
>>
>> <!-- Comment this part to see it "working" or uncomment to see it
>> failing -->
>> Idade:
>> <my:inputNumero id="idade" value="#{crudTeste.pessoa.idade}"/>
>> <br/>
>> <!-- -->
>>
>> <h:commandButton id="botao" value="Salvar" action="#{crudTeste.salvar}">
>> <f:ajax execute="@this @form" render="@all"/>
>> </h:commandButton>
>> </h:form>
>>
>> <h:messages id="message" globalOnly="true" showDetail="true"
>> showSummary="true"/>
>>
>> <h:dataTable id="tabela" value="#{crudTeste.lista}" var="item">
>> <h:column>
>> <f:facet name="header">
>> Nome
>> </f:facet>
>> #{item.nome}
>> </h:column>
>> <h:column>
>> <f:facet name="header">
>> Idade
>> </f:facet>
>> #{item.idade}
>> </h:column>
>> <h:column>
>> <f:facet name="header">
>> Cidade
>> </f:facet>
>> #{item.cidade.nome}
>> </h:column>
>> <h:column>
>> <f:facet name="header">
>> Funcao
>> </f:facet>
>> <h:form>
>> <h:commandButton value="Excluir" action="#{crudTeste.excluir}">
>> <f:ajax execute="@this @form" render="@all"/>
>> <f:param name="item" value="#{item.nome}"/>
>> </h:commandButton>
>> </h:form>
>> </h:column>
>> </h:dataTable>
>>
>> </ui:composition>
>> ---------------------------------------------------------------------------------------------------------
>>
>> Backing Bean Code
>> ---------------------------------------------------------------------------------------------------------
>>
>> @SuppressWarnings("serial")
>> @ManagedBean(name = "crudTeste")
>> @ViewScoped
>> public class CRUDTeste implements Serializable {
>>
>> private Pessoa pessoa;
>>
>> private List<Pessoa> lista;
>>
>> @PostConstruct
>> public void construct() {
>> lista = new ArrayList<Pessoa>();
>> pessoa = new Pessoa();
>> }
>>
>> public void salvar(){
>> lista.add(pessoa);
>> pessoa = new Pessoa();
>> FacesContext.getCurrentInstance().addMessage(null, new
>> FacesMessage("Pessoa salva com sucesso!"));
>> }
>>
>> public void excluir(){
>> String nome = FacesUtil.getParameter("item").toString();
>> for(Pessoa p : lista){
>> if(p.getNome().equals(nome)){
>> lista.remove(p);
>> }
>> }
>> FacesContext.getCurrentInstance().addMessage(null, new
>> FacesMessage("Pessoa removida com sucesso!"));
>> }
>>
>> public void setPessoa(Pessoa pessoa) {
>> this.pessoa = pessoa;
>> }
>>
>> public Pessoa getPessoa() {
>> return pessoa;
>> }
>>
>> public void setLista(List<Pessoa> lista) {
>> this.lista = lista;
>> }
>>
>> public List<Pessoa> getLista() {
>> return lista;
>> }
>>
>> /*
>> * No JSF2 os SelectItens podem apontar diretamente para objetos.
>> */
>> public List<Cidade> getCidades(){
>> List<Cidade> lista = new ArrayList<Cidade>();
>>
>> Cidade c = new Cidade("Tubarao");
>> lista.add(c);
>>
>> c = new Cidade("Criciuma");
>> lista.add(c);
>>
>> c = new Cidade("Ararangua");
>> lista.add(c);
>>
>> return lista;
>> }
>>
>> }
>> ---------------------------------------------------------------------------------------------------------
>>
>> Component Code
>> ---------------------------------------------------------------------------------------------------------
>>
>> <ui:composition xmlns="http://www.w3.org/1999/xhtml"
>> xmlns:h="http://java.sun.com/jsf/html"
>> xmlns:ui="http://java.sun.com/jsf/facelets"
>> xmlns:composite="http://java.sun.com/jsf/composite">
>>
>> <composite:interface>
>> <composite:attribute name="value"/>
>> </composite:interface>
>>
>> <composite:implementation>
>> <script type="text/javascript">
>> /*<![CDATA[ */
>> function isNumberKey(evt)
>> {
>> var charCode = (evt.which) ? evt.which : event.keyCode
>> if (charCode> 31&& (charCode< 48 || charCode> 57))
>> return false;
>>
>> return true;
>> }
>> /* ]]> */
>> </script>
>> <h:inputText value="#{compositeComponent.attrs.value}"
>> onkeypress="return isNumberKey(event)"/>
>> </composite:implementation>
>>
>> </ui:composition>
>> ---------------------------------------------------------------------------------------------------------
>>
>> And sorry about the text formatting, the forum broke it. I putted the
>> lines do make it easier to copy and paste it to an editor.
>> [Message sent by forum member 'israelbgf' (israelbgf)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=340253
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>