Struts2JqueryPlugin, refresh a textfield VALUE with ajax

115 views
Skip to first unread message

ngald

unread,
Jul 13, 2012, 4:08:24 AM7/13/12
to struts2...@googlegroups.com
hello everybody

I want async. refresh a single textfield Ty value whith jquery plugin tags.
The async. request (href or submit) has as parameter the instaneous value of
anothet texrt field Tx.

I want refresh the value, not hidden/appears. After clic value appears A,
before B.

the questions :

1. the result type for strus. what is ? dispatcher jsp ? json ?
2. refresh in main jsp. I must define a DIV section with FIELDTEXT inside
and target the Id DIV ?
or is possible target the id <s:fieldtext name="Ty" id="Ty" > ?

3. Tha Struts action. IT must contains the Ty property. Depends of result
type I suppose.

Thank you regards Nicola

--
View this message in context: http://struts2-jquery-plugin.109969.n3.nabble.com/Struts2JqueryPlugin-refresh-a-textfield-VALUE-with-ajax-tp4025293.html
Sent from the Struts2 jQuery Plugin mailing list archive at Nabble.com.

jchin

unread,
Jul 13, 2012, 11:44:55 AM7/13/12
to struts2...@googlegroups.com
See comment inline. I hope I am interpreting your question correctly.


On Friday, July 13, 2012 4:08:24 AM UTC-4, nicola galdiolo wrote:
hello everybody

I want async. refresh a single textfield  Ty value whith jquery plugin tags.
The async. request (href or submit) has as parameter the instaneous value of
anothet texrt field Tx.

I want refresh the value, not hidden/appears. After clic value appears A,
before B.

the questions :

1. the result type for strus.  what is ? dispatcher jsp ? json ?
IMO, I will use json as a result type. You will need the struts-json plugin in your webapps, and set the action mapping in your struts.xml with the result type="json"
 
2. refresh in main jsp.  I must define a DIV section with FIELDTEXT inside
and target the Id DIV ?
Not a must, you don't need to define a div if you are using json.

 if you set the target with the Div's id, assuming you are using the sj:submit with targets set, you will need the result type to be a jsp with your textfield in it.
<s:textfield name="Ty" value="%{whatever_value_you_want_replace_from_your_ajax_request}" /> 
 
   or is possible target the id <s:fieldtext name="Ty"  id="Ty" > ?
 
If you go the json route, you will need to use javascript to have a topic listener for your Ajax request, and populate the textfield value inside the listener.

For e.g.
<sj:submit 
  ...
  onSuccessTopics="updateTextfieldTyTopic"/>

$.subscribe("updateTextfieldTyTopic", function(event,data) {
  // you may need to set this correctly look at the example in the wiki: 
  var newTyValue = event.original.data.newTyValue;  // assuming your new value is called "newTyValue" in your action class 
 
  // TODD: replace value to the textfield with the new value
});
 

3. Tha Struts action.  IT must contains the Ty property.  Depends of result
type I suppose.
See comment above

nicola galdiolo

unread,
Jul 14, 2012, 6:06:52 PM7/14/12
to struts2...@googlegroups.com
Yhank you really

I have tried with Jsp result but I get doubled text field in response.
e.g.
--- main jsp ---
<s:form action="myActionAsync" >
  <s:fieldtext name="first" />
  <s:fieldtext name="second" />
<s:fieldtext name="first" />

</s:form >

nicola galdiolo

unread,
Jul 14, 2012, 6:21:39 PM7/14/12
to struts2...@googlegroups.com
Thank you really. It is a very great help

I have tried with Jsp result but I get doubled fieldtext in response. Monday I will try json.
e.g.
----- main jsp -------
<s:form action="myActionSyncTotal"  id="id_form_total" >

       <s:fieldtext name="first" />
       <s:fieldtext name="second" />
        <s:fieldtext name="last" />
       
           <s:form action="myActionAsync"  id="id_form_async" >
               <div id="id_asyn_part" >
                  <s:fieldtext name="asyncProp" />
               </div>
                    // -----------  this submit async,  classic---------------   
                 <sj:submit  targets ="id_form_async"  />
           </s:form >

          // -----------  this submit all, sync classic---------------   
         <s:submit />
</s:form >


------ struts.xml ----
<action="myActionAsync" class="...">
     <result>asyncJsp.jsp</result>
  
---- asyncJsp.jsp ---------
<s:fieldtext name="asyncProp" />

        
thank you again    nicola

Reply all
Reply to author
Forward
0 new messages