You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by red phoenix <ro...@gmail.com> on 2007/04/24 08:51:22 UTC

How to realize ajax in struts2

I want to use ajax within Struts to realize following function,there is a
textfield an a submit button which use register a username in a JSP
page,then you can put you name into textfield and click register button,then
will call ajax to search name is exist,if exist,there will be a message
behind textfield,say "name is exist,please use another name",like follows:
         ---------------------------
Name:|                         |
         ---------------------------
Register button

My code is follows,but my code can't reach my goal,I don't know how to
realize it?  Anybody could tell me how to do it? Thanks!

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
  <s:head theme="ajax"/>
</head>

<body>
Name:<s:textfield id="data1" name="data1"/><div id="t1"
style="display:none"></div>
<img id="indicator"
src="${pageContext.request.contextPath}/images/indicator.gif"
alt="Loading..." style="display:none"/>
<s:url id="ajaxTest" value="Test1.action" />
<s:submit type="submit" theme="ajax" value="submit" targets="t1"
href="%{ajaxTest}" align="left" indicator="indicator"/>
</body>
</html>

Re: How to realize ajax in struts2

Posted by Felipe Rodrigues <fe...@yahoo.com.br>.
I guess you're looking for custom validation. You can find it surfing at
http://struts.apache.org/2.x/docs/home.html

By the way, in your code, aren't you missing the <s:form> tag? Struts forms
are similar to HTML forms. You must wrap the ui components in a <s:form>,
except in special cases.

Regards,

Felipe


red phoenix-2 wrote:
> 
> I want to use ajax within Struts to realize following function,there is a
> textfield an a submit button which use register a username in a JSP
> page,then you can put you name into textfield and click register
> button,then
> will call ajax to search name is exist,if exist,there will be a message
> behind textfield,say "name is exist,please use another name",like follows:
>          ---------------------------
> Name:|                         |
>          ---------------------------
> Register button
> 
> My code is follows,but my code can't reach my goal,I don't know how to
> realize it?  Anybody could tell me how to do it? Thanks!
> 
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> 
> <html>
> <head>
>   <s:head theme="ajax"/>
> </head>
> 
> <body>
> Name:<s:textfield id="data1" name="data1"/><div id="t1"
> style="display:none"></div>
>  ${pageContext.request.contextPath}/images/indicator.gif 
> <s:url id="ajaxTest" value="Test1.action" />
> <s:submit type="submit" theme="ajax" value="submit" targets="t1"
> href="%{ajaxTest}" align="left" indicator="indicator"/>
> </body>
> </html>
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-realize-ajax-in-struts2-tf3636780.html#a10164514
Sent from the Struts - User mailing list archive at Nabble.com.


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