You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gabriel França Campolina <ga...@gmail.com> on 2004/10/11 16:40:31 UTC
How work DynaValidatorForm and java.sql.date and beanUtils.copyAttribuites?
Hi folks,
I post in last week a topic iguals this, but i´m not sucess in my
aplication, but now i post my code to that all looks and find i
solution.
Well when I submit my form all values are send except the
java.sql.date, that send the value null, How i solutions this problem.
My struts-config:
.
.
.
<form-beans>
<form-bean name="produtoForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="method" type="java.lang.String"/>
<form-property name="nome" type="java.lang.String"/>
<form-property name="dataInclusao" type="java.sql.Date"/>
</form-bean>
</form-beans>
.
<action
path="/entity/cadastro/produto"
name="produtoForm"
type="br.com.shopfactory.entity.cadastro.produto.action.ProdutoAction"
scope="request"
validate="false"
parameter="method">
<forward name="sucesso" path="entity.cadastro.produto"/>
<forward name="erro" path="entity.cadastro.produto"/>
</action>
.
My action ProdutoAction with a only metho named search:
public ActionForward search(
ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws BaseException{
ActionErrors errors;
ProdutoModel produtoModel = new ProdutoModel();
DynaValidatorForm dynaForm = (DynaValidatorForm)form;
errors = dynaForm.validate(mapping, request);
if(errors.isEmpty()){
try{
//copia os dados do Form para o Model
BeanUtils.copyProperties(produtoModel,dynaForm);
}catch(Exception ex){
ex.printStackTrace();
//Envia o erro para o ExceptionHandler
throw new BaseException("errors.entity.produto", ex, new Object[]{ex});
}
return mapping.findForward(Constants.SUCESS);
}else{
saveErrors(request,errors);
return mapping.findForward(Constants.ERROR);
}
}
My model ProdutoModel:
public class ProdutoModel{
private String nome;
private Date dataInclusao;
private String method;
public ProdutoModel(){
super();
nome = "";
method = "search";
}
//getters and setters......
}
I use to the validator, lookupdispacthAction and tiles in this application....
Thanks,.....
--
Gabriel França Campolina
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How work DynaValidatorForm and java.sql.date and beanUtils.copyAttribuites?
Posted by Bill Siggelkow <bi...@bellsouth.net>.
Gabriel,
You should always use Strings for date fields on your form.
- Bill Siggelkow
Gabriel França Campolina wrote:
> Hi folks,
>
> I post in last week a topic iguals this, but i´m not sucess in my
> aplication, but now i post my code to that all looks and find i
> solution.
> Well when I submit my form all values are send except the
> java.sql.date, that send the value null, How i solutions this problem.
>
> My struts-config:
> .
> .
> .
> <form-beans>
> <form-bean name="produtoForm"
> type="org.apache.struts.validator.DynaValidatorForm">
> <form-property name="method" type="java.lang.String"/>
> <form-property name="nome" type="java.lang.String"/>
> <form-property name="dataInclusao" type="java.sql.Date"/>
> </form-bean>
> </form-beans>
> .
> <action
>
> path="/entity/cadastro/produto"
>
> name="produtoForm"
>
> type="br.com.shopfactory.entity.cadastro.produto.action.ProdutoAction"
>
> scope="request"
>
> validate="false"
>
> parameter="method">
>
> <forward name="sucesso" path="entity.cadastro.produto"/>
> <forward name="erro" path="entity.cadastro.produto"/>
> </action>
> .
>
> My action ProdutoAction with a only metho named search:
>
> public ActionForward search(
> ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response)
> throws BaseException{
> ActionErrors errors;
> ProdutoModel produtoModel = new ProdutoModel();
> DynaValidatorForm dynaForm = (DynaValidatorForm)form;
> errors = dynaForm.validate(mapping, request);
> if(errors.isEmpty()){
> try{
> //copia os dados do Form para o Model
> BeanUtils.copyProperties(produtoModel,dynaForm);
>
> }catch(Exception ex){
> ex.printStackTrace();
> //Envia o erro para o ExceptionHandler
> throw new BaseException("errors.entity.produto", ex, new Object[]{ex});
> }
> return mapping.findForward(Constants.SUCESS);
> }else{
> saveErrors(request,errors);
> return mapping.findForward(Constants.ERROR);
> }
> }
>
> My model ProdutoModel:
>
> public class ProdutoModel{
> private String nome;
> private Date dataInclusao;
> private String method;
>
> public ProdutoModel(){
> super();
> nome = "";
> method = "search";
> }
> //getters and setters......
> }
>
> I use to the validator, lookupdispacthAction and tiles in this application....
> Thanks,.....
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org