Java method never called while using JSON RPC in Struts2
I'm trying to get some code working that a previous developer has written. Yep, he now left the company. :-(
I have a JSON RPC call being made from the JS code. The JS all runs fine and the callback method gets an object back (not an error object).
But the method on the Java class never gets hit. The smd method does get hit though.
public String smd()
{
return SUCCESS; // break point reaches here
}
@SMDMethod
public void updateRowValueForField(String key, String value, String fieldname)
{
// We never get into this method.
}
<package name="EntryBarRPC" namespace="/" extends="star-default">
<action name="ebToggleSelection" class="eboggleSelectionAction" method="smd">
<interceptor-ref name="jsonStack">
<param name="enableSMD">true</param>
</interceptor-ref>
<result type="json">
<param name="enableSMD">true</param>
</result>
</action>
</package>
I'm stumped as to why, or what I'm missing. I've read JSON plugin page over and over.
I think I just need another set of eyes.
Note: no errors in the Tomcat console, no JS errors.
Anyone got any clues? Cheers Jeff Porter
Asked by: Alberta108 | Posted: 28-01-2022
Answer 1
You forgot to include the javascript code. From the example:
<s:url id="smdUrl" namespace="/nodecorate" action="SMDAction" />
<script type="text/javascript">
//load dojo RPC
dojo.require("dojo.rpc.*");
//create service object(proxy) using SMD (generated by the json result)
var service = new dojo.rpc.JsonService("${smdUrl}");
//function called when remote method returns
var callback = function(bean) {
alert("Price for " + bean.type + " is " + bean.price);
};
//parameter
var bean = {type: "Mocca"};
//execute remote method
var defered = service.doSomething(bean, 5);
//attach callback to defered object
defered.addCallback(callback);
</script>
Are you sure you call service.updateRowValueForField(key, value, fieldname) and not something different?
Further, your method returns a void (e.g. doesn't return anything). What did you expect to get?
Answered by: Carlos692 | Posted: 01-03-2022Answer 2
New version fixes my problems.
Answered by: Byron147 | Posted: 01-03-2022Answer 3
I'm guessing that you need to update the smd()
method to actually call updateRowValueForField()
rather than simply return immediately. Looks like the previous developer never actually hooked up the methods.
Similar questions
java - Is there any init method given for struts2 action class?
Is there any init method provided for struts 2 action class that can be called before every method of that action class?
For example, I have an action class for struts 2 as given below
import com.opensymphony.xwork2.ActionSupport;
public class EmployeeAction extends ActionSupport{
private DepartmentDaoService deptService = new DepartmentDaoService() ;
private EmployeeDaoService empServic...
java - method of action class is not getting called in struts2
I am trying to call a method present in action class on click of submit button but method is not getting called.
here is my code---this is jsp page
<body>
<s:form method="POST" >
<a href="<s:url action="goback"/>">click here to go back</a>
<s:submit action="fileUploadAction" value="UploadFile"/>
<s:file name="fileUpload" label="Select a File to upload" size="40"/>
...
java - http post method in struts2
when i try to execute this alfresco webscript [http://localhost:8383/alfresco/service/get-order-info] through Advance REST client (google chrome add-on) then it works smoothly but when i try to execute by following code then it gives error at this line JSONObject jsonObject = (JSONObject) new JSONParser().parse(responseString);
public class ComplainMasterDaoImpl implements ComplainMast...
java - Using Stream Result with Struts2
I am attempting to use a Stream Result to return an image from a struts2 application. I seem to be having problem with configuring the action. Here is the configuration:
<result name="success" type="stream">
<param name="contentType">image/jpeg</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">file...
java - Is there any init method given for struts2 action class?
Is there any init method provided for struts 2 action class that can be called before every method of that action class?
For example, I have an action class for struts 2 as given below
import com.opensymphony.xwork2.ActionSupport;
public class EmployeeAction extends ActionSupport{
private DepartmentDaoService deptService = new DepartmentDaoService() ;
private EmployeeDaoService empServic...
java - how to return excel in Struts2 result?
I am trying to return an Excel sheet from my struts2 action class.
I am not sure what result-type should I be using? Has anyone tried to return an excel from struts2 action class?
I would like the user to be presented with open/save/cancel dialog box
java - Two struts2 webapps fail to start together
I have problems getting two different struts2 webapps to start together in tomcat. But each of the webapps start correctly when placed independently inside webapps folder of tomcat.
I get the following in catalina.out logs-
SEVERE: Error filterStart
Aug 13, 2009 3:17:45 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/admin] startup failed due to previous errors
Environment- Java1...
java - Struts2 doesn't find jsp files
I've been trying to no avail to set up a simple Struts2 application so I can get on with learning the framework. Basically, what I am expecting to happen is that when an action is triggered that isn't defined, then a default page will be displayed.
This app is being developed in Eclipse.
I have a very simple struts.xml file set up in the WEB-INF/classes directory:
<struts>
<!-- Incl...
java - Struts2 + jQuery - Sending regular updates to the client
I am implementing a functionality in my web app such that a client can generate the report by entering some data and clicking on the submit button.
The problem is that report generation takes lot of time and the report might not generate if the user entered data is wrong.
The complete report generation task has many sub-tasks and I want when the client presses submit then just below that page I want to show...
java - Spring & Struts2 REST - junit tests
I have three hierarchical layers injected in Spring - rest, business logic and database operations. Junit tests for BL and DAO are working OK, when rest can inject only business logic ioc layer.
My supper class for junit tests:
import org.springframework.test.AbstractTransactionalSpringContextTests;
public class AbstractTest extends AbstractTransactionalSpringContextTests {
protected static final S...
java - Adding global error on any field error in struts2
I am using Struts2 and a bunch of Validation with Annotations. How do I add a global error message as well on top of field validation errors. Thanks, Fedor
java - In Struts2, how do you share your common html across all pages?
In Struts2, how do you share your common html across all pages?
In Asp.net, you've got Master pages, and in Rails there are Layouts. The idea is that your common html (eg the header, menu, and styles) are all easy to maintain because they are in one place, but for the life of me i can't find the equivalent feature in Struts2.
Is it called something else, or something, is that why i can't find it?
java - Struts2 URL with .action
I want the URL of the below format
http://localhost/users/abc
rather than
http://localhost/users?name=abc
How to achieve this in Struts2?
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)