File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts 2.1 Ajax based input validation inside innerHTML problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2.1 Ajax based input validation inside innerHTML problem" Watch "Struts 2.1 Ajax based input validation inside innerHTML problem" New topic

Struts 2.1 Ajax based input validation inside innerHTML problem

qm westview

Joined: Feb 22, 2009
Posts: 1


I run into a problem when trying to run Struts 2.1 Ajax based form input and validation code inside innerHTML

I managed to get the validation working on the server but the Json based Ajax return simply does not go into the form code inside innerHTML. The browser treat the Ajax return as having no relationship with the request issuer. Coding steps are listed below:

This is the original Struts 2.1 based form and input validation code (the client/server validation logic runs fine when not using innerHTML approach):

The same code turned into the following when coming from the server:

Plus separate javascript code

I simply merged the above code into multiple line of strings and assigned to a dedicated div’s innerHTML:

I found the http request sent to the server, after the form submit was hit, did not include struts.enableJSONValidation=true. So I inserted the following code into innerHTML:

Then the reply from the server became truly Json basd:

But the problem is that the browser, both Firefox and IE, does not insert the above reply into the form, but treat it as totally irrelevant to the Struts 2.1 code inside the innerHTML and prompt the viewer to save/open it.

It seems to me that when using this innerHTML approach, somehow the javascript connection between the Struts2.1 code inside innerHTML and outside the innerHTML are lost.

I was wondering if there is anyway this innerHTML approach for Strtus 2.1 Ajax based form input validation would work.


(Thanks David for editing suggestion)

David Newton

Joined: Sep 29, 2008
Posts: 12617

Please repost with your code in code tags and disable HTML; it's difficult to read it as-is.
I agree. Here's the link:
subject: Struts 2.1 Ajax based input validation inside innerHTML problem
Similar Threads
unable to do validation for select in struts2
spaces while populating using s:iterator
How to update a image using servlet?
jQuery tabs form validation is failing
struts-2 (set values to action class)