You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Roberto Mabini <Ro...@headstrong.com> on 2009/02/23 03:16:03 UTC

Velocity Template

Hi All,

I am a new user of struts 2 , please give some direction on what template to used free marker or velocity. I am planning to used velocity but when I creating sample application , I have encounter a problem that struts 2 fix but seem I can 't get anything working. If you have simple application hello world on struts2  and velocity please help on this thanks

Roberto Mabini (Bibbs)
SA
Tel:
Email: roberto.mabini@headstrong.com

Headstrong
Strong opinions. Strong results.


Struts 2.1 Ajax based input validation inside innerHTML problem

Posted by Qunhuan Mei <qm...@qm18.wanadoo.co.uk>.
Hi, 

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):


<div id="validationTest>
	<s:form namespace="/test" action="save">

	<s:textfield label="Name:" name="name" required="true"/>
	<sx:submit validate="true" ajaxAfterValidation="true"
targets="response" showLoadingText="false"/>

	</s:form>
	<div id="response" style="border: 1px solid black"></div>
</div>

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

<form id="save_jsessionid_CF15DE4BE891D610713C8ACBC8968F7B"
action="save;jsessionid=CF15DE4BE891D610713C8ACBC8968F7B" method="post">
	<table class="wwFormTable">

	<tr>
		<td class="tdLabel"><label
for="save_jsessionid_CF15DE4BE891D610713C8ACBC8968F7B_name"
class="label">Name:
			<span class="required">*</span>:</label> </td>
		<td><input type="text" name="name" value=""
id="save_jsessionid_CF15DE4BE891D610713C8ACBC8968F7B_name"/></td>
	</tr>
	<tr>
		<td colspan="2">
			<div align="right"><input type="submit"
dojoType="struts:Bind" events="onclick" value="Submit" validate="true"
ajaxAfterValidation="true" id="widget_1324883642" targets="response"
showLoading="false"  /></div>
		</td>
	</tr>
	<script language="JavaScript"
type="text/javascript">djConfig.searchIds.push("widget_1324883642");</script
>        				
	</table>
</form>
<div id="response" style="border: 1px solid black">

Plus separate javascript code

<script language="JavaScript" type="text/javascript">    
    	djConfig = {
        	isDebug: false,bindEncoding: "UTF-8",baseRelativePath:
"/MapLov_Struts2_1/struts/dojo/",
    	    	baseScriptUri: "/MapLov_Struts2_1/struts/dojo/",parseWidgets
: false        
        };
</script>

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

	validationDiv = document.getElementById("validationDiv"); 	
    	validationDiv.innerHTML = ..multiple line of code strings..;
			
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:

    <input type="hidden" name="struts.enableJSONValidation" value="true">

Then the reply from the server became truly Json based: 

	/* { "fieldErrors": {" Name":[" name is required!"]}} */

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
form 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.

Qunhuan








---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org