You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rafael Nami <ra...@gmail.com> on 2006/12/03 07:04:31 UTC

Weird submit failure

Hi everyone
I'm using myfaces to port a delphi 5 application to JavaEE.
So far, it's being quite a pleasure, but I drove into some weird behaviors
yesterday.
I'm using a converter to convert model values from combo values and the
other way around. I'm using another converter to
convert model values from lookup values (String) and the other way around.
Now I'm experiencing a exception when the user try to save without selecting
a value in the combobox, or without selecting a row in the modal lookup (a
HibernateSystemException), when it seems to be the right behavior
throw the ConverterException
from the getAsObject or getAsString methods, to the JSF-Lifecycle phase
Conversion and Validation Phase. Wasn't it to be "automatic", without going
into my backend?
My application's other weird behavior is when the user try to save with all
the required data, strangely the lookup model data isn't being converted...
This is the converter code
*BairroWebBean.java*
**
*public* Converter getComboBairroConverter() {

*return* *new* Converter() {

*public* Object getAsObject(FacesContext context,

UIComponent component, String value) {

*if* (value == *null* || "-1".equals(value) || "".equals(value)) {

*return* *null*;

}

Bairro obj = *null*;

BairroService service = getBairroService();

obj = service.recuperar(EntidadesUtil.*cast*.castId(Bairro.*class*,

value));

lookUpCache.put("Bairro_" + obj.getNome(), obj);

*return* obj;

}

*public* String getAsString(FacesContext context,

UIComponent component, Object value)

*throws* ConverterException {

*if* (value == *null* || "-1".equals(value) || "".equals(value)) {

*return* *null*;

}

*if* (value *instanceof* String) {

*return* (String) value;

}

*if* (((Bairro) value).getId() == *null*) {

Long valorChave = *new* Long(-1l);

((Bairro) value).setId(valorChave);

}

*return* ((Bairro) value).getId().toString();

}

};

}

*public* Converter getLookUpBairroConverter() {

Converter converter = *new* Converter() {

*public* Object getAsObject(FacesContext context,

UIComponent component, String value)

*throws* ConverterException {

*if* (value == *null* || "-1".equals(value) || "".equals(value)) {

*return* *null*;

}

Bairro obj = lookUpCache.get("Bairro_" + value);

*if* (obj == *null*) {

obj = *new* Bairro();

obj.setNome(value);

}

*return* obj;

}

*public* String getAsString(FacesContext context,

UIComponent component, Object value)

*throws* ConverterException {

*if* (value == *null* || "-1".equals(value) || "".equals(value)) {

*return* *null*;

}

*return* ((Bairro) value).getNome();

}

};

*return* converter;

}

and the jsp using this converter

<t:saveState id="logradouro" value="#{manterLogradouroWebBean.logradouro}"
/>

....

<tr>

<td class="label"><h:outputText value="#{texto['logradouro.detalhe.bairro']}"
/></td>

<td>

<h:inputText size="4" readonly="true" required="true"

maxlength="40" value="#{manterLogradouroWebBean.logradouro.bairro}"

id="bairro" converter="#{bairroWebBean.comboBairroConverter}"/>

<a href="#" onclick="DialogUtils.openPopup('<%=ctx%>
/paginas/localidade/bairropopupconsulta.faces','panelPopup');">

<img src="<%=ctx%>/tema/images/lupa.gif" border="0" class="lupa" alt="Buscar
: Bairro"></a>

<h:inputText size="30" id="Descricao_bairro" disabled="true" value="#{
manterLogradouroWebBean.logradouro.bairro}" converter="#{
bairroWebBean.lookUpBairroConverter}"/>

</td>

<td class="label">

<h:outputText value="#{texto['logradouro.detalhe.cidade']}" /></td>

<td>

<h:inputText size="30" id="Descricao_cidade" value="#{
manterLogradouroWebBean.logradouro.bairro.cidade}" converter="#{
cidadeWebBean.lookUpCidadeConverter}" disabled="true"/>

</tr> .....

Anyone can show me the right path to get rid of this weird behavior?

Thanks in advance

Rafael Mauricio Nami