aspose file tools*
The moose likes Struts and the fly likes Html:form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Html:form" Watch "Html:form" New topic
Author

Html:form

Ingoba Ningthoujam
Ranch Hand

Joined: Dec 04, 2006
Posts: 90
Cam we put attribute NAME in html:form like

<html:form name="form1">
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Not if you're using version 1.2.9 or above. The name attribute has been removed from these versions.

Even if you're using an earlier version, I wouldn't recommend using the name attribute of the <html:form> tag. It's completely redundant. You have already specified the name and type in the action mapping in your struts-config.xml file. There's no need to specify it again here.


Merrill
Consultant, Sima Solutions
Neerav Narielwala
Ranch Hand

Joined: Dec 08, 2006
Posts: 106
The form-related tags consist of the <form> tag itself plus all tags that must be used inside it. For example, the <text> and <password> tags are form-related tags because it does not make sense if they are not placed inside a form.

The <form> Tag
The <form> tag generates an HTML form. You must follow a number of rules to use this tag.

First and foremost, a <form> tag must contain an action attribute, the only required attribute for this tag. Without an action attribute, your JSP page will throw an exception. Then, you must assign a valid value to this action attribute. A valid value is the path in any of the <action> elements in the <action-mappings> element in the application's Struts configuration file. Also, the corresponding <action> element must have a name attribute whose value is the name of a form bean.

For example, if you have this <form> tag:

<html:form action="/login" >

the <action-mappings> element of your Struts configuration file must have this <action> element in bold:

<action-mappings>
<action path="/login"
type="com.javapro.struts.LoginAction"
name="loginForm"
scope="request"
input="/login.jsp">
<forward name="success" path="/mainMenu.jsp"/>
</action>
.
.
.
</action-mappings>

This is to say that a form tag is associated with a form bean.

Another rule to follow: Any tag contained within the <form> tag to receive user input (<text>, <password>, <hidden>, <textarea>, <radio>, <checkbox>, <select> must have its property value assigned to a property in the associated form bean. For instance, if you have a <text> tag whose property is assigned the value "userName", the associated form bean must also have a property called "userName". The value entered into this <text> tag will then be used to populate the userName property of the form bean.


<a href="http://www.java-tips.org/java-tutorials/tutorials/" target="_blank" rel="nofollow">Java Tutorials</a> | <a href="http://www.planet-java.org" target="_blank" rel="nofollow">Java Weblog</a> | <a href="http://computer-engineering.science-tips.org" target="_blank" rel="nofollow">Computing Articles</a>
Ingoba Ningthoujam
Ranch Hand

Joined: Dec 04, 2006
Posts: 90
But I have six buttons for each I have to call different action.How can I call from the same page?
Ingoba Ningthoujam
Ranch Hand

Joined: Dec 04, 2006
Posts: 90
But I have six buttons for each I have to call different action.How can I call from the same page?
Ingoba Ningthoujam
Ranch Hand

Joined: Dec 04, 2006
Posts: 90
But I have six buttons for each I have to call different action.How can I call from the same page?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
While there are ways to have different buttons call different actions, I'd recommend that you stick with a single action for the form and put logic in that action to branch depending on which button was pressed.

An <html:submit> tag will send whatever is in the value attribute to the server. You can use this value to determine what button was pressed. Example: Suppose you want three buttons: add, delete, and edit. You then add a property called "action" to your ActionForm, and put the following three tags in your JSP:

Then in the execute method of your Action class, you put the following logic:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Html:form