Seam web remoting not working within a javascript funtion
enikozsido Aug 1, 2008 2:49 PMHi all,
Please take a look at following source!
The interface is:
@Local public interface IMessageServices { @WebRemote public String addMessage(String key); }
then the implementation:
@Scope(ScopeType.SESSION) @Name("messageService") public class MessageService implements IMessageServices { @WebRemote public String addMessage(String key) { FacesMessages.instance().addFromResourceBundle(FacesMessage.SEVERITY_ERROR, key); return "success"; } }
the xhtml :
... <script type="text/javascript" src="seam/resource/remoting/resource/remote.js"></script> <script type="text/javascript" src="seam/resource/remoting/interface.js?messageService"></script> ... <script type="text/javascript"> //<![CDATA[ ... Seam.Remoting.setDebug(true); var str = "message" Seam.Component.getInstance("messageService").addMessage(str,success); function success(result){ alert(result); } //]]> </script>
The debug info is:
Fri Aug 01 2008 15:27:52 GMT+0300: Request packet: <envelope><header><context></context></header><body><call component="messageService" method="addMessage" id="0"> <params><param><str>message</str></param></params><refs></refs></call></body></envelope> Fri Aug 01 2008 15:27:52 GMT+0300: Response packet: <envelope><header><context><conversationId>27</conversationId></context></header><body><result id="0"><value><str>success</str></value><refs></refs></result></body></envelope>
This works as expected: alerts(succeess
).
I'm trying to remotely invoke my method inside a javascript function:
function addMessage(str){ Seam.Component.getInstance("messageService").addMessage(str,success); } .... <h:commandButton value="Add" onclick="addMessage('message');"/>
This time I get an error alert There was an error processing your request. Error code: 0
.
The Debug info is:
Fri Aug 01 2008 15:40:49 GMT+0300: Request packet: <envelope><header><context></context></header><body><call component="messageService" method="addMessage" id="0"> <params><param><str>message</str></param></params><refs></refs></call></body></envelope>
As you can see there is no response.
Do you have any idea why this happens?