You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sebastian Stein <se...@hpfsc.de> on 2005/11/30 17:33:00 UTC

Why does has no value?

Hi,

I'm still in the process of learning struts... but I have a HTML form with
an input field:


<bean:define id="sourceDate" name="sourceDate" type="java.lang.String"/>
...
<html:text property="sourceDate" styleClass="input"/>

This string sourceDate is set in advance in a java class (extending Action):

sourceDate="2005/10/14";
request.setAttribute("sourceDate", sourceDate);

If I write in my jsp page <bean:write name="sourceDate"/> the correct string
is shown in the HTML output. So I'm sure that the value for sourceDate is
correctly handed over to the jsp page.

However, in the form above, the html input field does not contain the
string of sourceDate as default value. If I add name="sourceDate" to the
<html:text .../> line, I get the following exception:

javax.servlet.ServletException: No getter method for property sourceDate of
bean sourceDate

Is there a way to easily fix this?


Sebastian

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


Re: Why does has no value?

Posted by Sebastian Stein <se...@hpfsc.de>.
Laurie Harper <la...@holoweb.net> [051201 07:43]:
> >		<action path="/EditDoc"
> >		        type="org.contineo.actions.documan.document.EditDocAction">
> >			<forward name="editdoc"
> >			         path="/pages/editDoc.jsp"
> >			         redirect="false"/>
> >...
> >		<action input="/EditDoc.do"
> >		        name="docForm"
> >		        path="/ChangeDoc"
> >		        type="org.contineo.actions.documan.document.ChangeDocAction"
> >		        validate="false"/>
> >
> >The second step already works, I can access the form content in
> >ChangeDocAction.
> 
> Assuming editDoc.jsp contains an html:form tag which submits to 
> /EditDoc, you don't need any additional configuration to use the form in 
> editDoc.jsp. The html:form tag will automatically create a scripting 
> variable 'docForm'.
> 
> However, to pre-populate the form bean in EditDocAction, you do need the 
> extra configuration: you need to tell Struts to provide the form bean to 
> the action. To do that, just add 'name="docForm"' in the /EditDoc 
> mapping, just as you did for the /ChangeDoc mapping.

Thanks, that was the problem. Now it is working!


Sebastian

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


Re: Why does has no value?

Posted by Laurie Harper <la...@holoweb.net>.
Sebastian Stein wrote:
> Dave Newton <ne...@pingsite.com> [051130 17:43]:
>>> If I write in my jsp page <bean:write name="sourceDate"/> the correct 
>>> string
>>> is shown in the HTML output. So I'm sure that the value for sourceDate is
>>> correctly handed over to the jsp page.
>>>
>>> Is there a way to easily fix this?
>> The property in an html:text tag is expecting a sourceDate property in 
>> whatever type of ActionForm you're using, not a scoped attribute.
> 
> So this means instead of:
> 
> request.setAttribute("sourceDate", srcDate);
> 
> I should use:
> 
> MyForm myForm = (MyForm) form; // ActionForm form in the constructor
> myForm.setSourceDate(srcDate);

Yes, exactly.

> But I guess that I have to tell the jsp page about the form in the
> struts-config.xml. At the moment the relevant parts in the struts-config
> look as follows:
> 
> 
> 		<form-bean name="docForm" type="org.contineo.forms.DocForm"/>
> ...
> 		<action path="/EditDoc"
> 		        type="org.contineo.actions.documan.document.EditDocAction">
> 			<forward name="editdoc"
> 			         path="/pages/editDoc.jsp"
> 			         redirect="false"/>
> ...
> 		<action input="/EditDoc.do"
> 		        name="docForm"
> 		        path="/ChangeDoc"
> 		        type="org.contineo.actions.documan.document.ChangeDocAction"
> 		        validate="false"/>
> 
> The second step already works, I can access the form content in
> ChangeDocAction.

Assuming editDoc.jsp contains an html:form tag which submits to 
/EditDoc, you don't need any additional configuration to use the form in 
editDoc.jsp. The html:form tag will automatically create a scripting 
variable 'docForm'.

However, to pre-populate the form bean in EditDocAction, you do need the 
extra configuration: you need to tell Struts to provide the form bean to 
the action. To do that, just add 'name="docForm"' in the /EditDoc 
mapping, just as you did for the /ChangeDoc mapping.

You can then use the code you wrote above to initialise the form.

L.


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


Re: Why does has no value?

Posted by Sebastian Stein <se...@hpfsc.de>.
Dave Newton <ne...@pingsite.com> [051130 17:43]:
> >If I write in my jsp page <bean:write name="sourceDate"/> the correct 
> >string
> >is shown in the HTML output. So I'm sure that the value for sourceDate is
> >correctly handed over to the jsp page.
> >
> >Is there a way to easily fix this?
>
> The property in an html:text tag is expecting a sourceDate property in 
> whatever type of ActionForm you're using, not a scoped attribute.

So this means instead of:

request.setAttribute("sourceDate", srcDate);

I should use:

MyForm myForm = (MyForm) form; // ActionForm form in the constructor
myForm.setSourceDate(srcDate);

But I guess that I have to tell the jsp page about the form in the
struts-config.xml. At the moment the relevant parts in the struts-config
look as follows:


		<form-bean name="docForm" type="org.contineo.forms.DocForm"/>
...
		<action path="/EditDoc"
		        type="org.contineo.actions.documan.document.EditDocAction">
			<forward name="editdoc"
			         path="/pages/editDoc.jsp"
			         redirect="false"/>
...
		<action input="/EditDoc.do"
		        name="docForm"
		        path="/ChangeDoc"
		        type="org.contineo.actions.documan.document.ChangeDocAction"
		        validate="false"/>

The second step already works, I can access the form content in
ChangeDocAction.


Sebastian

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


Re: Why does has no value?

Posted by Dave Newton <ne...@pingsite.com>.
Sebastian Stein wrote:

>If I write in my jsp page <bean:write name="sourceDate"/> the correct string
>is shown in the HTML output. So I'm sure that the value for sourceDate is
>correctly handed over to the jsp page.
>
>Is there a way to easily fix this?
>  
>
The property in an html:text tag is expecting a sourceDate property in 
whatever type of ActionForm you're using, not a scoped attribute.

Dave



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


Re: Why does has no value?

Posted by Sebastian Stein <se...@hpfsc.de>.
Gaet <ga...@free.fr> [051130 17:39]:
> Please send your code of tag <html:text>

I think <html:text .../> is a tag defined by struts-html.tld using tag class
org.apache.struts.taglib.html.TextTag. By the way, according to
struts-config.xml, I'm using Struts version 1.1.


Sebastian

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


Re: Why does has no value?

Posted by Gaet <ga...@free.fr>.
Please send your code of tag <html:text>

But if you specify 'sourceDate' in the name that means that you will look in the bean sourceDate and not that you will display its value...don't know if you see the difference...send more lines of code

Cordialement, 
 
  ----- Original Message ----- 
  From: Sebastian Stein 
  To: user@struts.apache.org 
  Sent: Wednesday, November 30, 2005 5:33 PM
  Subject: Why does <html:text property="..."/> has no value?


  Hi,

  I'm still in the process of learning struts... but I have a HTML form with
  an input field:


  <bean:define id="sourceDate" name="sourceDate" type="java.lang.String"/>
  ...
  <html:text property="sourceDate" styleClass="input"/>

  This string sourceDate is set in advance in a java class (extending Action):

  sourceDate="2005/10/14";
  request.setAttribute("sourceDate", sourceDate);

  If I write in my jsp page <bean:write name="sourceDate"/> the correct string
  is shown in the HTML output. So I'm sure that the value for sourceDate is
  correctly handed over to the jsp page.

  However, in the form above, the html input field does not contain the
  string of sourceDate as default value. If I add name="sourceDate" to the
  <html:text .../> line, I get the following exception:

  javax.servlet.ServletException: No getter method for property sourceDate of
  bean sourceDate

  Is there a way to easily fix this?


  Sebastian

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