You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by lk <ce...@email.it> on 2005/07/10 11:16:38 UTC
What's wrong? [prepopulating a form...]
Hi,
I'm trying to prepopulate a form for editing it and I can't understand
what's wrong.
From a list of objects I want to edit one. I have an action for that:
<action path="/polizza_mod"
type="mypackage.PolizzaFormModAction"
name="polizza_newForm"
scope="request"
input="/gestione/polizza_mod.jsp"
validate="false">
<forward name="OK" path="/gestione/polizza_mod.jsp"/>
</action>
^^^^^^^^^^^^^^^^^
polizza_newForm is a DynaActionForm defined in the struts-config.xml
^^^^^^^^^^^^^^^^^
The action is:
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
public class PolizzaFormModAction extends Action
{
public boolean DEBUG = true;
public ActionForward execute( ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
HttpSession session = request.getSession();
// Here I create the bean
PolizzaBean pb = new PolizzaBean(getDataSource(request,
Parameters.NOME_DATA_SOURCE));
PolizzaDTO p = pb.getPolizza(request.getParameter("id"));
// SAVE THE OBJECT "polizza" in the session
session.setAttribute("polizza", p);
ServletContext sc = this.getServlet().getServletContext();
xferToForm(p,form,sc);
session.setAttribute("polizzaForm", form);
return (mapping.findForward("OK"));
}
/**
* transfer bean data to form
*/
private void xferToForm(PolizzaDTO polizza, ActionForm form,
ServletContext sc)
{
((DynaValidatorForm)form).set("nome",polizza.getNome());
}
}
^^^^^^^^^^^^^^^^^
Everything works fine but the form
"/gestione/polizza_mod.jsp"
is empty?
Why???
If I try to print on that form the bean polizza_newForm the properties
are correct:
<c:out value="${polizza_newForm}" />
gives:
DynaActionForm[dynaClass=polizza_newForm,nome=test]
My form is:
<html:form action="/polizza_new_preview.do">
<html:text
name="polizza_newForm"
property="nome"
size="25"
maxlength="25"
value= ""
/>
<html:submit value="Conferma" styleClass="bottone" />
<html:button value="Elimina" property="Elimina" styleClass="bottone"
/> <html:reset value="Annulla" styleClass="bottone" />
</html:form>
Thanks
LuKe
--
Email.it, the professional e-mail, gratis per te: http://www.email.it/f
Sponsor:
Iscriviti GRATUITAMENTE: ci sono 5 Euro che ti aspettano .e decine di corsi...
*
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=3416&d=10-7
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: What's wrong? [prepopulating a form...]
Posted by lk <ce...@email.it>.
Gotcha!!!!
Oh poor man :-)
The problem was in the form:
I used the attribute value="" for the html:text tag from an old form!!!!
ByE
>
> If I try to print on that form the bean polizza_newForm the properties
> are correct:
>
> <c:out value="${polizza_newForm}" />
> gives:
>
> DynaActionForm[dynaClass=polizza_newForm,nome=test]
>
> My form is:
> <html:form action="/polizza_new_preview.do">
> <html:text
> name="polizza_newForm"
> property="nome"
> size="25"
> maxlength="25"
> value= ""
> />
> <html:submit value="Conferma" styleClass="bottone" />
> <html:button value="Elimina" property="Elimina" styleClass="bottone"
> /> <html:reset value="Annulla" styleClass="bottone" />
> </html:form>
>
> Thanks
>
> LuKe
>
--
Email.it, the professional e-mail, gratis per te: http://www.email.it/f
Sponsor:
Email.it Phone Card: chiami in tutto il mondo a tariffe imbattibili da tutti i telefoni fissi e cellulari! Clicca e scopri come
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=2686&d=10-7
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org