Foros de discusión
Ajax-Portlet
souhaib ben ghrib, modificado hace 16 años.
Ajax-Portlet
New Member Mensajes: 2 Fecha de incorporación: 4/04/08 Mensajes recientes
Hello, I developed a struts portlet witch i integrate AJAX but the server throws an exception :
java.lang.ClassCastException: com.ext.portlet.AjaxPort.action.salem cannot be cast to javax.portlet.Portlet
This is view.jsp:
and this is my class:
and this is my struts-config.xml:
Please Help me.
Thanks for any suggestions!
java.lang.ClassCastException: com.ext.portlet.AjaxPort.action.salem cannot be cast to javax.portlet.Portlet
This is view.jsp:
<script type="text/JavaScript">
function getXhr()
{
var xhr = null;
if(window.XMLHttpRequest) // Firefox et autres
xhr = new XMLHttpRequest();
else
if(window.ActiveXObject)
{ // Internet Explorer
try
{
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else
{ // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objetsXMLHTTPRequest...");
xhr = false;
}
return xhr
}
/**
* Méthode qui sera appelée sur le click du bouton
*/
function go()
{
var xhr = getXhr()
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyState == 4 && xhr.status == 200)
{
alert(xhr.responseText);
}
}
var url = "<portlet:actionURL windowState="<%= WindowState.MAXIMIZED.toString() %>"><portlet:param name="struts_action" value="/ext/AjaxPort/valid" /></portlet:actionURL>";
xhr.open("GET",url,true);
xhr.send(null);
}
</script>
<form onsubmit="go()">
<input type="text" name="my_text" value="">
<input type="button" name="btn" value="Dis quelque chose !">
</form>
and this is my class:
package com.ext.portlet.AjaxPort.action;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.liferay.portal.struts.PortletAction;
public class salem extends PortletAction {
public void processAction(
ActionMapping mapping, ActionForm form, PortletConfig config,
ActionRequest req, ActionResponse res)
throws Exception{
System.out.println("bonjour ! ");
String txt = req.getParameter("my_text");
System.out.println("TEXT: " + txt);
}
}
and this is my struts-config.xml:
<struts-config>
<action-mappings>
<!-- Ajax Portlet -->
<action path="/ext/AjaxPort/valid" type="com.ext.portlet.AjaxPort.action.salem">
<forward name="portlet.ext.AjaxPort.view" path="portlet.ext.AjaxPort.view" />
</action>
</action-mappings>
</struts-config>
Please Help me.
Thanks for any suggestions!