I want to learn about the reverse of ajax, I found a gadget called ICEPush, and I thought this might be a good starting point. I'm having trouble implementing a very simple application. I follow this tutorial , but instead of Tomcat I use Glassfish 3.1, and instead of Eclipse I use NetBeans 7.1
I did exactly as the tutorial says, see my code. This is the page that will be the target of clicking Ajax:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Easy Ajax Push - Color</title>
</h:head>
<h:body>
<h:dataTable value="#{messageBean.textList}" var="current">
<h:column>
<h:outputText value="#{current.text}"
style="color: #{current.color};"/>
</h:column>
</h:dataTable>
<hr width="100%"/>
<h:form>
<h:panelGrid columns="4">
Choose a Color:
<h:commandButton value="Red"
action="#{colorBean.chooseColor}"
style="color: white; background-color: red;">
<f:setPropertyActionListener target="#{colorBean.color}" value="red"/>
</h:commandButton>
<h:commandButton value="Blue"
action="#{colorBean.chooseColor}"
style="color: white; background-color: blue;">
<f:setPropertyActionListener target="#{colorBean.color}" value="blue"/>
</h:commandButton>
<h:commandButton value="Green"
action="#{colorBean.chooseColor}"
style="color: white; background-color: green;">
<f:setPropertyActionListener target="#{colorBean.color}" value="green"/>
</h:commandButton>
</h:panelGrid>
</h:form>
</h:body>
</html>
Here are 2 managed beans that are needed:
ColorBean.java
@ManagedBean(name="colorBean")
@ViewScoped
public class ColorBean implements Serializable {
private static final String PUSH_GROUP = "colorPage";
@ManagedProperty(value="#{messageBean}")
private MessageBean messageBean;
private String color = "black";
private String sessionId;
public ColorBean() {
PushRenderer.addCurrentSession(PUSH_GROUP);
FacesContext fcontext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)fcontext.getExternalContext().getSession(false);
sessionId = session.getId();
}
public void setMessageBean(MessageBean messageBean) {
this.messageBean = messageBean;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String chooseColor() {
messageBean.addToList(sessionId, color);
PushRenderer.render(PUSH_GROUP);
return null;
}
}
MessageBean.java
@ManagedBean(name="messageBean")
@ApplicationScoped
public class MessageBean implements Serializable {
private static final int MAX_SIZE = 25;
private List<TextModel> textList = new ArrayList<TextModel>(0);
public MessageBean() {
}
public List<TextModel> getTextList() {
return textList;
}
public void setTextList(List<TextModel> textList) {
this.textList = textList;
}
public void addToList(String sessionId, String color) {
textList.add(makeTextModel(sessionId, color));
if (textList.size() > MAX_SIZE) {
textList.clear();
}
}
private TextModel makeTextModel(String sessionId, String color) {
return new TextModel("User with session ID of " + sessionId + " selected color \"" + color + "\".",
color);
}
}
There is also a simple pojo to represent the presented text.
TextModel.java
public class TextModel implements Serializable {
private String text;
private String color;
public TextModel() {
}
public TextModel(String text, String color) {
this.text = text;
this.color = color;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String toString() {
return text;
}
}
I am using IceFaces version 3.0.1, and here is what my web.xml looks like :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.icefaces.mandatoryResourceConfiguration</param-name>
<param-value/>
</context-param>
<context-param>
<param-name>org.icefaces.ace.theme</param-name>
<param-value>sam</param-value>
</context-param>
<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.gmapKey</param-name>
<param-value>ABQIAAAADlu0ZiSTam64EKaCQr9eTRTOTuQNzJNXRlYRLknj4cQ89tFfpxTEqxQnVWL4k55OPICgF5_SOZE06A</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/icefaces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
This code gives me 3 problems:
1 - , , , , bean , :
: javax.faces.FacesException: w810 Bean. : - , # {messageBean}, , , beans (colorBean)
2 - , :
: PWC4011: UTF-8 /ReverseAjaxExample, , ServletRequest.getReader()
3 - @ApplicationScope @ViewScope @ViewScope @ApplicationScope beans, , , , ajax , . PWC4011
Ajax, . , , .