Valter Silva
Valter Silva

Reputation: 16656

Java Web: How use JSP with JSF and Ajax?

i'm working in a project with jsp, i need to start to use ajax too. i'm enjoying jsf , is possible work with these together (JSP, JSF and AJAX) ?

I'm asking this cause i could run jsf with ajax

<h:commandButton id="bt_save" value="Save" title="Save" action="#personMBean.clickSave()}">
    <f:ajax execute="@form" render="lblMessage" />
</h:commandButton>
<br/>

<h:outputLabel id="lblMessage" value="#{personMBean.message}" />

But when i try input this code in my jsp page it doesn't work, even if i insert on my jsp page:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

Any ideas ?

Upvotes: 1

Views: 2710

Answers (3)

BalusC
BalusC

Reputation: 1108632

Ensure that you're using JSF 2.x (the <f:ajax> doesn't exist in JSF 1.x) and that you've a <h:head> instead of <head> in the master template (so that JSF can auto-include necessary Ajax JavaScripts).

Said that, you should really consider Facelets as replacement of JSP. JSP is an outdated view technology and ill suited for templating and has been replaced by Facelets as per JSF 2.0 / Java EE 6.

Upvotes: 2

maple_shaft
maple_shaft

Reputation: 10463

I don't see why you couldn't do this but certainly not on the same page.

To do this you need to map the *.jsp extension to the JSP servlet while mapping the *.jsf or *.xhtml to FacesServlet.

Upvotes: 0

Bozho
Bozho

Reputation: 597026

Yes - try richfaces or primefaces

Upvotes: 0

Related Questions