Setting struts bean value by calling Ajax
-
25-06-2021 - |
Question
I am in a situation where I need to call a Class method and execute some tasks, which will return some data and need to set the same data to Struts bean and display the same dynamically in jsp page
<tr>
<td><s:select id="selectProductCode" list="#session['UDM_Product_Codes']" name="selectProductCode" onchange="callXmethod(this);" /></td>
<td><s:textfield theme="simple" name="assignedProductBean.assignedProductKey" value="" /></td>
<td><s:select label="selectRole" id="selectRole" name="roleList" list="assignedProductBean.roleList" /></td>
<td><b><s:a href="javascript:createRole()">CREATE</s:a></b></td>
<td></td>
<td></td>
</tr>
As shown in the code. as soon as i select Product, I need to call some method in my action class, which sets some data to bean again, based on which rest of the two fields depends
Solution
I am still not sure what problem you are facing.What you are describing is quite possible, all you need to take care of Ajax (Jquery).You can create a Ajax method which can pass the value to your Action class and can get back the result.
I suggest you to have a look at Struts2-Jquery plugin as JSON based communication is much more flexible and jQuery complements JSON in a good way and provides a lot of functionality out of the box.
Here is one example to see how this all work together