File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes problems with form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problems with form" Watch "problems with form" New topic
Author

problems with form

Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
I want to get the values of a form in an action but the problem I have is that they get no value at all.

I have a button that submits the form but it is out of it...what can I do to get these values?
the button has to be outside of the form...


this is my code:




<html:form action="/sam/updateEntity">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<nested:iterate property="availableAttributes">
<tr>
<td valign="top" align="left" width="15%">
<img src="../images/spacer.gif" width="20"/><font class="label"><nested:write property="attribute.name"/>:</font>
</td>
<td width="85%">
<nested:nest property="attribute.attributeType">
<nested:equal property="name" value="single line text area">
<nested:text property="../../value" size="35"/>
</nested:equal>
<nested:equal property="name" value="check box">
<nested:checkbox property="../../value"/>
</nested:equal>
<nested:equal property="name" value="drop down menu">
<nested:select property="../../value">
<html ption value=""> </html ption>//this is an empty option, do not change it
<nested ptions property="../possibleValuesAsStringArray"/>
</nested:select>
</nested:equal>

<nested:equal property="name" value="multi line text area">
<nested:textarea property="../../value" rows="4" cols="28"/>
</nested:equal>
</nested:nest>
</td>
</tr>
</nested:iterate>
<tr>
<td height="10"> </td>
</tr>
<tr>

<td colspan="2">
<hr>

</td>
</tr>
</table>
</html:form>


more code in between....



<html:form action="/sam/updateEntity">
<input type="image" src="../images/button_save_bold.gif" alt="Save Entity" title="Save Entity" accesskey="V">
</html:form>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The only way I know to submit one form from a button in another form is through JavaScript. For example, if the form you want to submit is the first form on the page and the form containing the button is in the second form on the page, you could do something like this:

*Note: onklick above should be onclick


Merrill
Consultant, Sima Solutions
Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
I did so in my js code but the form fields don't get any value

any other idea?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This will work if done properly. Show us your code.

One question: Are you absolutely sure that the form you want to submit is the first one on the page? If you're using tiles, another tile may be adding a form to the page.
[ February 22, 2007: Message edited by: Merrill Higginson ]
Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
Ok, I tried what you suggest...

the problem now is that when I hit the save button the action is accessed twice.The first time it get the values of the form correctly but the second time it lose them.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Are you writing this onclick event in a submit button? If so, that's the problem. This would cause the submit to occur twice: once from the onclick event and once from the submit button itself.

Solution: use either <html:button> or <input type="button" > instead of <html:submit> or <input type="submit" />
Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
I used an <a> tag insted of an input image and It works now...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems with form