You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Emmanuel.Leguy" <Em...@lifl.fr> on 2005/10/14 18:07:01 UTC

logic:present and html:text tags problem

Hello,

I use the following code in a jsp:

<logic:present name="person">
         <html:text property="name" " value='<%= person.getName() %>'/>
 </logic:present>

If 'person' is not present <%= person.getName() %> is compiled and I get 
this error: membreLIFL cannot be resolved

If i use this code:

<logic:present name="person">
         <input type="text" name="name" value="<bean:write name="person" 
property="name"/>"/>
 </logic:present>

No problem.

How can i use the html:text tag?

Thanx,

Manu.

-- 
Emmanuel Leguy          	LIFL - UMR8022 CNRS - Bat M3
Tel: +33 3 28 77 85 32  	USTL - Universite de Lille 1
Fax: +33 3 28 77 85 37  	59655 VILLENEUVE D'ASCQ CEDEX - FRANCE

mailto:Emmanuel.Leguy@lifl.fr	http://www.lifl.fr/ANNUAIRE/employee.php?login=leguye

Ce mail est signe par un certificat X509 fourni par le CNRS
La verification de ce certificat peut etre faite a l'adresse suivante: 
http://igc.services.cnrs.fr/CNRS-Standard/recherche.html 


Re: logic:present and html:text tags problem

Posted by Dave <no...@yahoo.com>.
Try using the -el taglib:
<%@ taglib uri="/tags/struts-html-el" prefix="html-el" %>
...
<html-el:text property="name" value="${person.name}" />



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[OT]Re: logic:present and html:text tags problem

Posted by Dave Newton <ne...@pingsite.com>.
Emmanuel.Leguy wrote:
[nothing]

Why do I not see anything for Emmanuel's emails? I'm running Thunderbird 
on XP SP2.

Dave




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: logic:present and html:text tags problem

Posted by "Emmanuel.Leguy" <Em...@lifl.fr>.
Emmanuel.Leguy a écrit :

>>
> Yes name is specified. I think it needs more explanations. My action 
> sequence is:
>
> jsp0 -------> Action1--------> jsp1 ---------> Action2 --------> jsp2
>                         |                                               |
>                   Formbean1                             Formbean2
>
> I would like to pre-populate Formbean2 in Action1 to put default 
> values in jsp1. Formbean2 specifies a name property. Unfortunately, 
> when  i code this
>
> DynaActionForm dForm = (DynaActionForm) form;
> dForm.set( "name", person.getName() );
>
> in Action1 dForm refers to Formbean1 (not Formbean2). Formbean1 is 
> used to get informations entered in jsp0. Since Formbean1 does not 
> specify a name property (it does not need any), i get an error.
>
> My question is then:
>
> How to populate Formbean2 in Action1?

Fixed!

I red the struts doc again and i solved my problem. I did not understand 
that i need 2 actions: an action to populate the form (before the jsp  
is displayed) and one to process the user infos. So my flow is now:


jsp0 -------> Action1-------->prepareAction ---------> jsp1 ---------> 
Action2 --------> jsp2
                        |                                  
|                                                    |
                  Formbean1              Formbean2(pre-populated)        
Formbean2

and it works!!!

Thanx for all,

Manu.

-- 
Emmanuel Leguy          	LIFL - UMR8022 CNRS - Bat M3
Tel: +33 3 28 77 85 32  	USTL - Universite de Lille 1
Fax: +33 3 28 77 85 37  	59655 VILLENEUVE D'ASCQ CEDEX - FRANCE

mailto:Emmanuel.Leguy@lifl.fr	http://www.lifl.fr/ANNUAIRE/employee.php?login=leguye

Ce mail est signe par un certificat X509 fourni par le CNRS
La verification de ce certificat peut etre faite a l'adresse suivante: 
http://igc.services.cnrs.fr/CNRS-Standard/recherche.html 


Re: logic:present and html:text tags problem

Posted by "Emmanuel.Leguy" <Em...@lifl.fr>.
Laurie Harper a écrit :

>>> Sure.
>>> DynaActionForm dForm = (DynaActionForm) form;
>>> dForm.set( "name", person.getName() );
>>>
>>> You can also use BeanUtils to copy properties from the Person to the 
>>> Form bean:
>>> BeanUtils.copyProperties( dForm, person );
>>>
>> Il get this error:
>>
>> javax.servlet.ServletException: Invalid property name 'name'
>>     
>> org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516) 
>>
>>     
>> org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423) 
>>
>>     
>> org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) 
>>
>>     
>> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
>>     org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
>>     javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>>     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>
>> *root cause*
>>
>> java.lang.IllegalArgumentException: Invalid property name 'name'
>>     
>> org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:600) 
>>
>>     org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:413)
>>     
>> fr.lifl.existant.struts.action.ChoisirHomonyme.execute(ChoisirHomonyme.java:67) 
>>
>>     
>> org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421) 
>>
>>     
>> org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) 
>>
>>     
>> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
>>     org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
>>     javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>>     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>
>> ?
>>
>> Thanx,
>>
>> Manu.
>
>
> Did you specify a 'name' property in your form bean declaration in 
> struts-config.xml? 'Dyna' forms only have the properties you specify. 
> I've never used them, but I think the 'lazy' versions allow you to use 
> arbitrary properties without having to declare them.
>
Yes name is specified. I think it needs more explanations. My action 
sequence is:

jsp0 -------> Action1--------> jsp1 ---------> Action2 --------> jsp2
                         |                                               |
                   Formbean1                             Formbean2

I would like to pre-populate Formbean2 in Action1 to put default values 
in jsp1. Formbean2 specifies a name property. Unfortunately, when  i 
code this

DynaActionForm dForm = (DynaActionForm) form;
dForm.set( "name", person.getName() );

in Action1 dForm refers to Formbean1 (not Formbean2). Formbean1 is used 
to get informations entered in jsp0. Since Formbean1 does not specify a 
name property (it does not need any), i get an error.

My question is then:

How to populate Formbean2 in Action1?

Thanx,

Manu.

-- 
Emmanuel Leguy          	LIFL - UMR8022 CNRS - Bat M3
Tel: +33 3 28 77 85 32  	USTL - Universite de Lille 1
Fax: +33 3 28 77 85 37  	59655 VILLENEUVE D'ASCQ CEDEX - FRANCE

mailto:Emmanuel.Leguy@lifl.fr	http://www.lifl.fr/ANNUAIRE/employee.php?login=leguye

Ce mail est signe par un certificat X509 fourni par le CNRS
La verification de ce certificat peut etre faite a l'adresse suivante: 
http://igc.services.cnrs.fr/CNRS-Standard/recherche.html 


Re: logic:present and html:text tags problem

Posted by Laurie Harper <la...@holoweb.net>.
Emmanuel.Leguy wrote:
> Wendy Smoak a écrit :
> 
>> From: "Emmanuel.Leguy" Emmanuel.Leguy@lifl.fr>
>> Wendy wrote:
>>
>>>> In Action code, before forwarding to the JSP, look up the Person 
>>>> object and pre-populate the form bean's 'name' property.
>>>
>>>
>>
>>> Is it possible with a dynaActionForm?
>>
>>
>>
>> Sure.
>> DynaActionForm dForm = (DynaActionForm) form;
>> dForm.set( "name", person.getName() );
>>
>> You can also use BeanUtils to copy properties from the Person to the 
>> Form bean:
>> BeanUtils.copyProperties( dForm, person );
>>
> Il get this error:
> 
> javax.servlet.ServletException: Invalid property name 'name'
>     org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516) 
> 
>     org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423) 
> 
>     org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) 
> 
>     org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
>     org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> 
> *root cause*
> 
> java.lang.IllegalArgumentException: Invalid property name 'name'
>     org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:600) 
> 
>     org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:413)
>     fr.lifl.existant.struts.action.ChoisirHomonyme.execute(ChoisirHomonyme.java:67) 
> 
>     org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421) 
> 
>     org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) 
> 
>     org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
>     org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> 
> ?
> 
> Thanx,
> 
> Manu.

Did you specify a 'name' property in your form bean declaration in 
struts-config.xml? 'Dyna' forms only have the properties you specify. 
I've never used them, but I think the 'lazy' versions allow you to use 
arbitrary properties without having to declare them.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: logic:present and html:text tags problem

Posted by "Emmanuel.Leguy" <Em...@lifl.fr>.
Wendy Smoak a écrit :

> From: "Emmanuel.Leguy" Emmanuel.Leguy@lifl.fr>
> Wendy wrote:
>
>>> In Action code, before forwarding to the JSP, look up the Person 
>>> object and pre-populate the form bean's 'name' property.
>>
>
>> Is it possible with a dynaActionForm?
>
>
> Sure.
> DynaActionForm dForm = (DynaActionForm) form;
> dForm.set( "name", person.getName() );
>
> You can also use BeanUtils to copy properties from the Person to the 
> Form bean:
> BeanUtils.copyProperties( dForm, person );
>
Il get this error:

javax.servlet.ServletException: Invalid property name 'name'
	org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

*root cause*

java.lang.IllegalArgumentException: Invalid property name 'name'
	org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:600)
	org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:413)
	fr.lifl.existant.struts.action.ChoisirHomonyme.execute(ChoisirHomonyme.java:67)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

?

Thanx,

Manu.

-- 
Emmanuel Leguy          	LIFL - UMR8022 CNRS - Bat M3
Tel: +33 3 28 77 85 32  	USTL - Universite de Lille 1
Fax: +33 3 28 77 85 37  	59655 VILLENEUVE D'ASCQ CEDEX - FRANCE

mailto:Emmanuel.Leguy@lifl.fr	http://www.lifl.fr/ANNUAIRE/employee.php?login=leguye

Ce mail est signe par un certificat X509 fourni par le CNRS
La verification de ce certificat peut etre faite a l'adresse suivante: 
http://igc.services.cnrs.fr/CNRS-Standard/recherche.html 


Re: logic:present and html:text tags problem

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Emmanuel.Leguy" Emmanuel.Leguy@lifl.fr>
Wendy wrote:
>> In Action code, before forwarding to the JSP, look up the Person object 
>> and pre-populate the form bean's 'name' property.

> Is it possible with a dynaActionForm?

Sure.
DynaActionForm dForm = (DynaActionForm) form;
dForm.set( "name", person.getName() );

You can also use BeanUtils to copy properties from the Person to the Form 
bean:
BeanUtils.copyProperties( dForm, person );

-- 
Wendy 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: logic:present and html:text tags problem

Posted by "Emmanuel.Leguy" <Em...@lifl.fr>.
Wendy Smoak a écrit :

> From: "Emmanuel.Leguy" <Em...@lifl.fr>
>
>> Laurie Harper a écrit :
>>
>>> Did you try this?
>>>
>>>     <logic:present name="person">
>>>         <html:text name="person" property="name"/>
>>>     </logic:present>
>>>
>> No. I didn't try this. That works but if an error ocure (validate), 
>> the form is displayed with the person.name value and not with the 
>> formbean.name value.
>
>
> In Action code, before forwarding to the JSP, look up the Person 
> object and pre-populate the form bean's 'name' property.
>
> Then you have the choice of checking for the 'person' bean or the form 
> bean's 'name' property in <logic:present> before displaying the text 
> field. (From what you've posted I'm not sure which is more appropriate.)
>
Is it possible with a dynaActionForm?

Thanx,

Manu.

-- 
Emmanuel Leguy          	LIFL - UMR8022 CNRS - Bat M3
Tel: +33 3 28 77 85 32  	USTL - Universite de Lille 1
Fax: +33 3 28 77 85 37  	59655 VILLENEUVE D'ASCQ CEDEX - FRANCE

mailto:Emmanuel.Leguy@lifl.fr	http://www.lifl.fr/ANNUAIRE/employee.php?login=leguye

Ce mail est signe par un certificat X509 fourni par le CNRS
La verification de ce certificat peut etre faite a l'adresse suivante: 
http://igc.services.cnrs.fr/CNRS-Standard/recherche.html 


Re: logic:present and html:text tags problem

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Emmanuel.Leguy" <Em...@lifl.fr>
> Laurie Harper a écrit :
>> Did you try this?
>>
>>     <logic:present name="person">
>>         <html:text name="person" property="name"/>
>>     </logic:present>
>>
> No. I didn't try this. That works but if an error ocure (validate), the 
> form is displayed with the person.name value and not with the 
> formbean.name value.

In Action code, before forwarding to the JSP, look up the Person object and 
pre-populate the form bean's 'name' property.

Then you have the choice of checking for the 'person' bean or the form 
bean's 'name' property in <logic:present> before displaying the text field. 
(From what you've posted I'm not sure which is more appropriate.)

-- 
Wendy 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: logic:present and html:text tags problem

Posted by "Emmanuel.Leguy" <Em...@lifl.fr>.
Laurie Harper a écrit :

> Emmanuel.Leguy wrote:
>
>> Hello,
>>
>> I use the following code in a jsp:
>>
>> <logic:present name="person">
>>         <html:text property="name" " value='<%= person.getName() %>'/>
>> </logic:present>
>>
>> If 'person' is not present <%= person.getName() %> is compiled and I 
>> get this error: membreLIFL cannot be resolved
>>
>> If i use this code:
>>
>> <logic:present name="person">
>>         <input type="text" name="name" value="<bean:write 
>> name="person" property="name"/>"/>
>> </logic:present>
>>
>> No problem.
>>
>> How can i use the html:text tag?
>
>
> Did you try this?
>
>     <logic:present name="person">
>         <html:text name="person" property="name"/>
>     </logic:present>
>
> L.
>
No. I didn't try this. That works but if an error ocure (validate), the 
form is displayed with the person.name value and not with the 
formbean.name value.

Thanks,

Manu.

-- 
Emmanuel Leguy          	LIFL - UMR8022 CNRS - Bat M3
Tel: +33 3 28 77 85 32  	USTL - Universite de Lille 1
Fax: +33 3 28 77 85 37  	59655 VILLENEUVE D'ASCQ CEDEX - FRANCE

mailto:Emmanuel.Leguy@lifl.fr	http://www.lifl.fr/ANNUAIRE/employee.php?login=leguye

Ce mail est signe par un certificat X509 fourni par le CNRS
La verification de ce certificat peut etre faite a l'adresse suivante: 
http://igc.services.cnrs.fr/CNRS-Standard/recherche.html 


Re: logic:present and html:text tags problem

Posted by Michael Jouravlev <jm...@gmail.com>.
If Person object is null, he will get the same NPE. Nice thing about
JSTL is that:

* JSTL looks in different contexts;
* JSTL does not throw NPE if accessed object was null

Michael.

On 10/15/05, Aldo Vadillo Batista <al...@gmail.com> wrote:
> It doesn't work because "person" is not declared in Java. Maybe "person" is
> in session scope (or request scope).
>  It's not a good solution using scriptlets but if you want, you have to put
> something like this:
>  <html:text property="name" values='<%=((Person) request.getSession
> ().getAttribute("person")).getName()%>'/>
>
>  >
> > > <logic:present name="person">
> > > <html:text property="name" " value='<%= person.getName() %>'/>
> > > </logic:present>
> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: logic:present and html:text tags problem

Posted by Aldo Vadillo Batista <al...@gmail.com>.
It doesn't work because "person" is not declared in Java. Maybe "person" is
in session scope (or request scope).
 It's not a good solution using scriptlets but if you want, you have to put
something like this:
 <html:text property="name" values='<%=((Person) request.getSession
().getAttribute("person")).getName()%>'/>

 >
> > <logic:present name="person">
> > <html:text property="name" " value='<%= person.getName() %>'/>
> > </logic:present>
>

Re: logic:present and html:text tags problem

Posted by Laurie Harper <la...@holoweb.net>.
Emmanuel.Leguy wrote:
> Hello,
> 
> I use the following code in a jsp:
> 
> <logic:present name="person">
>         <html:text property="name" " value='<%= person.getName() %>'/>
> </logic:present>
> 
> If 'person' is not present <%= person.getName() %> is compiled and I get 
> this error: membreLIFL cannot be resolved
> 
> If i use this code:
> 
> <logic:present name="person">
>         <input type="text" name="name" value="<bean:write name="person" 
> property="name"/>"/>
> </logic:present>
> 
> No problem.
> 
> How can i use the html:text tag?

Did you try this?

     <logic:present name="person">
         <html:text name="person" property="name"/>
     </logic:present>

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org