Forums de discussion

Why page is reloaded after using ajax?

PortletFaces Community Member, modifié il y a 12 années.

Why page is reloaded after using ajax?

Regular Member Publications: 199 Date d'inscription: 03/04/12 Publications récentes
I see that page is reloaded after using Ajax. How to make my portlet asynchronous?

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;


@ManagedBean(name = "count")
@RequestScoped
public class Count implements Serializable {
Integer count = 0;

public Integer getCount() {
return count++;
}

public void reset(ActionEvent ae) {
count = 0;
}
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Ajax</title>
</h:head>
<h:body>
<h:form id="form1" prependId="false">
<h:outputScript name="ajax.js" library="javax.faces" target="head"/>
<h:outputText id="out1" value="#{count.count}"/>
<br/>
<!-- Increment the counter on the server, and the client -->
<h:commandButton id="button1" value="Count"
onclick="javax.faces.Ajax.ajaxRequest(this, event, {execute: this.id, render: 'out1'}); return false;"/>
<br/>
<!-- Resets the counter -->
<h:commandButton id="reset" value="reset"
onclick="javax.faces.Ajax.ajaxRequest(this, event, {execute:'reset', render: 'out1'}); return false;"
actionListener="#{count.reset}"/>
</h:form>
</h:body>
</html>


<portlet>
<portlet-name>1</portlet-name>
<instanceable>false</instanceable>
<render-weight>1</render-weight>
<ajaxable>true</ajaxable>
</portlet>
thumbnail
Neil Griffin, modifié il y a 11 années.

RE: Why page is reloaded after using ajax?

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Try something like this:
<h:commandbutton action="#{backingBean.submit}" value="Submit&quot;">
	<f:ajax execute="@form" render="@form" />
</h:commandbutton>