2 Replies Latest reply on Dec 8, 2009 2:03 PM by Markus Venghaus

    JSF with Ajax4JSF and RichFaces

    Markus Venghaus Newbie

      Hello i have a problem.

      I´m new in Ajax.

      i would to rerender the id="BigPic" but it dosn´t.
      The bigpic is the pic what it is in the dataTable when i click it.

      Here the source Code.

      data.jsp

      <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
      <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
      <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
      <!-- RichFaces tag library declaration -->
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      
      
      
      
      <html>
      <body>
      <f:view>
       <a4f:form ajaxSubmit="true">
       <rich:dataTable value="#{tableBean.perInfoAll }" var="dataItem"
       id="taskList">
       <rich:column>
       <h:graphicImage value="#{dataItem.absolutePath}" width="70"
       height="50" />
       </rich:column>
       <rich:column>
       <a4j:commandLink id="link" ajaxSingle="true"
       action="#{showPic.processAction}" reRender="BigPic">
       <h:outputText value="#{dataItem.picName }"></h:outputText>
       <f:attribute name="picURL" value="#{dataItem.absolutePath }" />
       </a4j:commandLink>
       </rich:column>
       </rich:dataTable>
       </a4f:form>
       <h:panelGroup id="BigPic">
       <h:graphicImage value="#{showPic.picShowURL }"
       rendered="#{not empty showPic.picShowURL }" />
       </h:panelGroup>
      </f:view>
      </body>
      
      </html>
      


      showPic.java
      package roseindia1;
      
      import javax.faces.component.UIParameter;
      import javax.faces.event.*;
      
      public class ShowPic implements ActionListener {
       private String picShowURL;
      
       public void processAction(ActionEvent event)
       throws AbortProcessingException {
       UIParameter component = (UIParameter) event.getComponent()
       .findComponent("picURL");
       String strValue = component.getValue().toString();
       System.out.println(strValue);
       new showPicURl(strValue);
       picShowURL = strValue;
       }
      
       public String getPicShowURL() {
       return picShowURL;
       }
      
       public void setPicShowURL(String picShowURL) {
       this.picShowURL = picShowURL;
       }
      
       public class showPicURl {
       private String showPicURl;
      
       public showPicURl(String showPicURL) {
       this.showPicURl = showPicURL;
       }
      
       public String getShowPicURL() {
       return showPicURl;
       }
      
       public void setShowPicURL(String showPicName) {
       this.showPicURl = showPicName;
       }
       }
      }
      


      TableBean.java
      package roseindia1;
      
      import java.util.*;
      import java.io.*;
      import java.lang.reflect.Array;
      
      public class TableBean {
       private List perInfoAll = new ArrayList();
      
       public void setPerInfoAll(List perInfoAll) {
       this.perInfoAll = perInfoAll;
       }
      
       public List getPerInfoAll() {
       try {
      
       File thumbFile = new File("D:\\PIC");
       File[] files = thumbFile.listFiles();
      
       for (File file : files) {
      
       if (file.getName().toLowerCase().endsWith(".jpg")) {
      
       perInfoAll.add(new TableData(file.getAbsolutePath(), file
       .getName()));
       }
       }
      
       } catch (Exception e) {
       System.out.println("Error Data : " + e.getMessage());
       }
       return perInfoAll;
       }
      
       public class TableData {
       private String absolutePath;
       private String picName;
      
       public TableData(String absolutePath, String picName) {
       this.absolutePath = absolutePath;
       this.picName = picName;
       }
      
       public String getAbsolutePath() {
       return absolutePath;
       }
      
       public void setAbsolutePath(String absolutePath) {
       this.absolutePath = absolutePath;
       }
      
       public String getPicName() {
       return picName;
       }
      
       public void setPicName(String picName) {
       this.picName = picName;
       }
      
       }
      }


      web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.5" 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_2_5.xsd">
       <display-name>WebAplication1</display-name>
      
       <!-- Plugging the "Blue Sky" skin into the project -->
       <context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>blueSky</param-value>
       </context-param>
      
       <!-- Making the RichFaces skin spread to standard HTML controls -->
       <context-param>
       <param-name>org.richfaces.CONTROL_SKINNING</param-name>
       <param-value>enable</param-value>
       </context-param>
      
       <filter>
       <display-name>RichFaces Filter</display-name>
       <filter-name>richfaces</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
       </filter>
      
       <filter-mapping>
       <filter-name>richfaces</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       </filter-mapping>
      
       <listener>
       <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
       </listener>
      
       <!-- Faces Servlet -->
       <servlet>
       <servlet-name>Faces Servlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       </servlet>
      
       <!-- Faces Servlet Mapping -->
       <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>*.jsf</url-pattern>
       </servlet-mapping>
      
       <login-config>
       <auth-method>BASIC</auth-method>
       </login-config>
      </web-app>


      faces-config.xml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <faces-config 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-facesconfig_1_2.xsd"
       version="1.2">
      
       <managed-bean>
       <managed-bean-name>tableBean</managed-bean-name>
       <managed-bean-class>roseindia1.TableBean</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>showPic</managed-bean-name>
       <managed-bean-class>roseindia1.ShowPic</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>bigPic</managed-bean-name>
       <managed-bean-class>roseindia1.BigPic</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
      </faces-config>
      


        • 1. Re: JSF with Ajax4JSF and RichFaces
          Ilya Shaikovsky Master

          it seems for me that this

           <f:attribute name="picURL" value="#{dataItem.absolutePath }" />
          


          should not be get like there
           UIParameter component = (UIParameter) event.getComponent()
           .findComponent("picURL");


          visit our dataTable editing sample at richfacesdemo to check how it could be simply handled with parameters.

          • 2. Re: JSF with Ajax4JSF and RichFaces
            Markus Venghaus Newbie

            Oke. What do u say to this.


            <a4j:commandLink id="link" ajaxSingle="true" action="#{Action.processAction}" reRender="BigPic">
             <h:outputText value="#{dataItem.picName }"></h:outputText>
             </a4j:commandLink>
            



            bean.java
             public class Action {
            
             private String picName;
            
            
             public void picName() {
             picName = picName;
             }
            
             public String getAccount() {
             return picName;
             }
            
             public void setAccount(String picName) {
             this.picName = picName;
             }}


            Sorry i am at home.
            I cant test it yet