my dog learned polymorphism*
The moose likes Struts and the fly likes Please help me. Error when show data on the textbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Please help me. Error when show data on the textbox" Watch "Please help me. Error when show data on the textbox" New topic
Author

Please help me. Error when show data on the textbox

Nguyen Minh Duc
Greenhorn

Joined: Jan 30, 2006
Posts: 2
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.


I love Java
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me. Error when show data on the textbox
 
Similar Threads
Problem Passing Parameter values to action
load page with new data, not forward in Struts action
Wanting to Displaying Empty Data on Initial Search Page
Wanting to Displaying Empty Data on Initial Search Page
Form data not mapping to bean automatically