• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me. Error when show data on the textbox

 
Nguyen Minh Duc
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help me.

At my previous struts project, I can show data on the jsp page by such way:
<html:text property="userName" value="${Person.firstName}"/>
For example, when the value of Person.firstName is 'John', the value of the textbox is 'John'.

But now, at another struts project, when the value of Person.firstName is 'John', the value of the text box is '="${Person.firstName}"'.
The following code can show the correct Person.firstName.
<html:text property="userName"> <c ut value="${Person.userName}" /> </html:text>

But I want to show data by this way <html:text property="userName" value="${Person.firstName}"/>.
Because <html:text property="userName"> <c ut value="${Person.userName}" /> </html:text> can not keep the value when I paging in Struts.

Please help me.
Thank you.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two versions of <html:xxx> tags: The regular version and the Struts-el version. It looks like your previous project was using the strut-el version, and your current project is using the regular version.

To use the struts-el version of the tags, place the following in your JSP, replacing the other html tag definition:

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el"prefix="html"%>

Also, make sure the struts-el.jar file is in your WEB-INF/lib directory.

Once these changes are in place, you should be able to insert an EL expression in any of your html tag attributes that accept run-time expressions.

Now that I've hopefully answered your question, please indulge me as I go beyond the parameters of your question.

As I see it, the only reason to use the <html:text> tag as opposed to a plain old <input type="text"> tag is that the <html:text> tag automatically populates the value attribute. Using your example, Struts is already going to set the value attribute of this tag to the value of myForm.getUserName(). If you're not going to use the Struts standard practice of populating the form bean property in the action that forwards to the JSP, you might as well just write:

<input type="text" name="userName" value='<cut value="${person.firstName}"/>' >

When the form is submitted, Struts will still populate the myForm.userName property, because it is the name of the input that Struts uses to match it up to a form bean property.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic