Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes form submitting on html link Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "form submitting on html link " Watch "form submitting on html link " New topic
Author

form submitting on html link

Naveen bpl
Greenhorn

Joined: Apr 03, 2005
Posts: 11
Hi,

I am using frames in my application. The left frame has the navigation hyperlinks and the right frame as the form fields like text boxes.

Now I am trying to implement refresh functionality, so that after entering data on page1.jsp and if I click the Page1 hyperlink, the page1.jsp should be submitted and the data on it should be read and stored into the sessison.

I am having problem with form submit. I am doing like this:

<html:link action="/Page1.do?actionType=refresh" onKlick="javascript: document.myForm.submit()" target="dataEntryPage"> Personal</html:link> 

and I have a ActionForward method refresh() in the Page1Action.java class which reads the data from the form

Line of code from Page1Action.java

Page1Bean pa = new Page1Bean();
pa.Name = (String) form.get("Name");
System.out.println("Name: " + pa.Name);

When I do that, its just printing Name:
And no data what ever I entered on the form text field.

Structs Config Action Mapping for this is:

<action path="/Page1Link" name="Page1Form" type="org.tiaa.tda.action.PersonalInfoAction"
parameter="actionType" scope="request" >

<forward name="refresh" path="/jsp/Personal.jsp" redirect="true" />

</action>

I hope the form is not submitting.
Can anyone suggest me how should I submit a form in this case.

Thanks in Advance,
Naveen
David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Hi, Naveen:

It seems that you meet the same problemm I met couple days ago, please check that thread (a html:link problem):

http://www.coderanch.com/t/51791/Struts/html-link

hope it may help.

Thanks
David
Naveen bpl
Greenhorn

Joined: Apr 03, 2005
Posts: 11
Hi David,

Actually I went through your post before I added a new post. I tried the way it was suggested in your post, but it didn't work for me. So I made new post.

Thanks,
Naveen
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Let me see if I understand the problem corrently. You have a link in a navaigation bar frame that will cause page 1 to display in the dataEntryPage frame. But if you're currently already displaying page 1 in the dataEntryPage frame and the user clicks the page 1 link, you want it to submit page 1 before redisplaying it, right?

First off, you need a way of telling whether Page 1 is currently displayed in the dataEntryPage frame or not. I'd suggest setting a global javascript variable (for example g_page) containing the identity of the page currently displayed in the dataEntryPage frame. So, for each page you display, set g_page to "pageone" or "pagetwo" or whatever the page is.

When the user clicks the link in the navigaion bar, test if parent.dataEntryPage.g_page is "pageone". If not, have the link do what it currently does. If so, have the link submit the form in the dataEntryPage frame, NOT the form in the navigation bar frame. So, the command would be: parent.dataEntryPage.forms[0].submit();


Merrill
Consultant, Sima Solutions
Naveen bpl
Greenhorn

Joined: Apr 03, 2005
Posts: 11
hi Merrill,

Thanks a lot for your help, I did the way you have suggested me. Its working except that its opening the popups. I have a navigation panel jsp on the left side of the page. So when I submit the page, its opening a new empty page besides and the original page still has both the navigation panel and also the pag1 jsp. And the address of that empy page shows the navigation panel jsp addres.

I am doing a submit as shown below using the javascript.

<html:link action="/Page1.do?actionType=refresh" onKlick="doRefresh()" target="dataEntryPage"> Page1</html:link>

<script language="JavaScript">

function doRefresh()
{
document.forms[0].action = '/tdaomni/Page1.do' ;
document.forms[0].submit() ;
}

</script>

Please suggest me what's the reason for the navigation panel to be opened in a differnt page, though the newly opened page is empty and the actual page still has the navigation panel.

Thanks,
Naveen
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You are encountering this problem because your script is submitting the form for the wrong frame. It should submit the form for the dataEntryPage frame, not the navigationBar frame. In Javascript, you refer to another frame by first referring to "parent", which is a reference to the frameSet that caused the current frame to be displayed. From there, you can get a reference to another frame by name.

Therefore, your doRefresh script should read:

parent.dataEntryPage.document.forms[0].submit()


This will submit whatever form is in dataEntryPage frame, so you will want to check to make sure the right page is in the frame before submitting the form.
Naveen bpl
Greenhorn

Joined: Apr 03, 2005
Posts: 11
Hi Merrill,

Thanks for suggesting me. I tried the way by adding the parent.dataentrypage.document.forms[0].submit();

but I still have the same problem of the new empty IE page opening as I explained before.

Thanks,
Naveen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: form submitting on html link
 
Similar Threads
Javascript submit not working
Help in struts
Struts with Javascript problem
want help in iframe
two actionForms for one action class?