You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by ba...@liga.net on 2006/08/03 17:41:44 UTC

"Could not find a strategy instance for class RubricSelectionModel" when working with PropertySelection component

Good day!

I'm developing portlet using Tapestry portlet technology (4.0.2). I've
created page with PropertySelection component. But it displays error "Could
not find a strategy instance for class
net.mycompany.portal.news.newslist.RubricSelectionModel".

How can I run my portlet successfully?

Please, help me!

Thanks!

My sources:
Edit.html:
<form jwcid="stockQuoteForm">
<input type="text" jwcid="stockId"/>
<select jwcid="rubricSelection"></select>
<input type="submit" value="OK"/>
</form>

Edit.page:
<?xml version="1.0"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<page-specification
class="net.mycompany.portal.news.newslist.NewsListEditPage">
      <component id="stockQuoteForm" type="Form">
            <binding name="listener" value="listener:onOk"/>
      </component>
      <component id="stockId" type="TextField">
            <binding name="value" value="ognl:stockId"/>
      </component>
      <component id="rubricSelection" type="PropertySelection">
            <binding name="model" value="ognl:rubricSelectionModel"/>
            <binding name="value" value="ognl:currentRubric"/>
      </component>
</page-specification>



NewListEditPage.java:
package net.mycompany.portal.news.newslist;

import java.io.IOException;

import javax.portlet.PortletPreferences;
import javax.portlet.ReadOnlyException;
import javax.portlet.ValidatorException;

import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.html.BasePage;

import net.mycompany.common.CommonRegistry;

public abstract class NewsListEditPage extends BasePage {

      @InjectObject("service:tapestry.portlet.PortletRequest")
      public abstract javax.portlet.PortletRequest getPortletRequest();

      public abstract String getStockId();

      public abstract Rubric getCurrentRubric();

      public static RubricSelectionModel getRubricSelectionModel(){
            return new
RubricSelectionModel(CommonRegistry.getRubricList());
      }

      public void onOk() {
            System.out.println("Listener called. Stock id is: " +
getStockId());
            PortletPreferences prefs =
getPortletRequest().getPreferences();
            try {
                  prefs.setValue("DocCount", getStockId());
                  prefs.setValue("RubricId",
getCurrentRubric().getId().toString());
                  prefs.store();
            } catch (ReadOnlyException e) {
                  e.printStackTrace();
            } catch (ValidatorException e) {
                  e.printStackTrace();
            } catch (IOException e) {
                  e.printStackTrace();
            }
      }
}



RubricSelectionModel.java:
package net.mycompany.portal.news.newslist;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

public class RubricSelectionModel implements Serializable{
      private static final long serialVersionUID = 1L;

      private List rubricList;

        public RubricSelectionModel(List itemList) {
            this.rubricList = itemList;
        }

        public int getOptionCount() { return rubricList.size(); }

        public Object getOption(int index) {
            return rubricList.get(index);
        }

        public String getLabel(int index) {
            return ((Rubric) rubricList.get(index)).getName();
        }

        public String getValue(int index) {
              return ((Rubric) rubricList.get(index)).getId().toString();
        }

        public Object translateValue(String value) {
              Iterator e = rubricList.iterator();
              while(e.hasNext()){
                    Rubric rubric = (Rubric)e.next();
                    if(rubric.getId().toString() == value){
                          return rubric;
                    }
              }
              return null;
        }
}



Rubric.java:
package net.mycompany.portal.news.newslist;

import java.io.Serializable;

public class Rubric implements Serializable{
      private static final long serialVersionUID = 1L;

      private Integer id;
      private String code;
      private String name;

      public String getCode() {
            return code;
      }
      public void setCode(String code) {
            this.code = code;
      }
      public Integer getId() {
            return id;
      }
      public void setId(Integer id) {
            this.id = id;
      }
      public String getName() {
            return name;
      }
      public void setName(String name) {
            this.name = name;
      }

      public Rubric(Integer id, String code, String name) {
            super();
            this.id = id;
            this.code = code;
            this.name = name;
      }
}



DBUtils.java:
package net.mycompany.portal.utils;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class DBUtils {

      private static DataSource ds;

      private static SessionFactory sessionFactory = new
Configuration().configure()
                  .buildSessionFactory();

      public static SessionFactory getSessionFactory() {
            return sessionFactory;
      }

}




portlet.xml:
<portlet-app version="1.0"
  xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation=
"http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
  <portlet>
    <description xml:lang="EN"></description>
    <portlet-name>myportlet</portlet-name>
    <display-name xml:lang="EN">My Tapestry Portlet</display-name>
    <portlet-class>org.apache.tapestry.portlet.ApplicationPortlet</
portlet-class>
    <expiration-cache>-1</expiration-cache>
    <supports>
      <mime-type>text/html</mime-type>
      <portlet-mode>view</portlet-mode>
      <portlet-mode>help</portlet-mode>
    </supports>
    <supported-locale>en</supported-locale>
    <portlet-info>
      <title>My Tapestry Portlet</title>
      <short-title>tapestry-portlet</short-title>
      <keywords></keywords>
    </portlet-info>
  </portlet>
</portlet-app>



web.xml:
<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>app</display-name>
  <servlet>
    <servlet-name>ApplicationServlet</servlet-name>
    <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ApplicationServlet</servlet-name>
    <url-pattern>/app</url-pattern>
  </servlet-mapping>
</web-app>



hivemodule.xml:
doesn't exists


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: "Could not find a strategy instance for class RubricSelectionModel" when working with PropertySelection component

Posted by nobody <da...@budweiser.com>.
 
#mypost3265 pre { 
  font-size: 140%;
  border-style: outset;
  border-color: red;
}



I'm sure this post is useless for you, but I figured I should correct this
anyway for others' reference.

To be serializable,  you should implement these 2 methods:
   private void writeObject(java.io.ObjectOutputStream out)
     throws IOException
   private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException;

It is explained in the JavaDoc for j2se: 
   http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html 
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html 
   

With what you had, my guess was that rubricList would just be null after
deserialization, not the exception you got, but this is what you should do
anyway.


Here is the class with those methods implemented:


import java.io.*;

public class RubricSelectionModel implements Serializable{
      private static final long serialVersionUID = 1L;

      private List rubricList;

        public RubricSelectionModel(List itemList) {
            this.rubricList = itemList;
        }

        public int getOptionCount() { return rubricList.size(); }

        public Object getOption(int index) {
            return rubricList.get(index);
        }

        public String getLabel(int index) {
            return ((Rubric) rubricList.get(index)).getName();
        }

        public String getValue(int index) {
              return ((Rubric) rubricList.get(index)).getId().toString();
        }

        public Object translateValue(String value) {
              Iterator e = rubricList.iterator();
              while(e.hasNext()){
                    Rubric rubric = (Rubric)e.next();
                    if(rubric.getId().toString() == value){
                          return rubric;
                    }
              }
              return null;
        }

        private void writeObject(java.io.ObjectOutputStream out)  throws
IOException {
                out.writeObject( rubricList );
        }
        private void readObject(java.io.ObjectInputStream in) throws
IOException, ClassNotFoundException {
                rubricList = (List)in.readObject();
        }

} 

-- 
View this message in context: http://www.nabble.com/%22Could-not-find-a-strategy-instance-for-class-RubricSelectionModel%22-when-working-with-PropertySelection-component-tf2046393.html#a10025753
Sent from the Tapestry - User mailing list archive at Nabble.com.

Re: "Could not find a strategy instance for class RubricSelectionModel" when working with PropertySelection component

Posted by Norbert Sándor <de...@erinors.com>.
- Are you sure it's serializable? Try to write a simple unit test to 
serialize the object to a ByteArrayOutputStream for example.
- In your preferred IDE set a breakpoint to NotSerializableException to 
check the the location/context of the exception, so you can manually 
find the cause of the error.

Regards,
Norbi

Vitaly Baranovsky wrote:
> I can't find when I can serialize or persisting RubricSelectionModel. And
> RubricSelectionModel implements Serializable. And Rubric class implements
> serializable too.
>
> I doo same code as servlet, but result is still the same :(
>
> What can I doo?
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: "Could not find a strategy instance for class RubricSelectionModel" when working with PropertySelection component

Posted by Vitaly Baranovsky <ba...@liga.net>.
I can't find when I can serialize or persisting RubricSelectionModel. And
RubricSelectionModel implements Serializable. And Rubric class implements
serializable too.

I doo same code as servlet, but result is still the same :(

What can I doo?
-- 
View this message in context: http://www.nabble.com/%22Could-not-find-a-strategy-instance-for-class-RubricSelectionModel%22-when-working-with-PropertySelection-component-tf2046393.html#a5639314
Sent from the Tapestry - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: "Could not find a strategy instance for class RubricSelectionModel" when working with PropertySelection component

Posted by Ron Piterman <rp...@gmx.net>.
you probably serialize it in some way (usually by persisting it) but it 
is not serializeable.
either make it serializeable or remove the persisting code.
Cheers,
Ron



baranovsky@liga.net wrote:
> Good day!
> 
> I'm developing portlet using Tapestry portlet technology (4.0.2). I've
> created page with PropertySelection component. But it displays error "Could
> not find a strategy instance for class
> net.mycompany.portal.news.newslist.RubricSelectionModel".
> 
> How can I run my portlet successfully?
> 
> Please, help me!
> 
> Thanks!
> 
> My sources:
> Edit.html:
> <form jwcid="stockQuoteForm">
> <input type="text" jwcid="stockId"/>
> <select jwcid="rubricSelection"></select>
> <input type="submit" value="OK"/>
> </form>
> 
> Edit.page:
> <?xml version="1.0"?>
> <!DOCTYPE page-specification PUBLIC
> "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
> <page-specification
> class="net.mycompany.portal.news.newslist.NewsListEditPage">
>       <component id="stockQuoteForm" type="Form">
>             <binding name="listener" value="listener:onOk"/>
>       </component>
>       <component id="stockId" type="TextField">
>             <binding name="value" value="ognl:stockId"/>
>       </component>
>       <component id="rubricSelection" type="PropertySelection">
>             <binding name="model" value="ognl:rubricSelectionModel"/>
>             <binding name="value" value="ognl:currentRubric"/>
>       </component>
> </page-specification>
> 
> 
> 
> NewListEditPage.java:
> package net.mycompany.portal.news.newslist;
> 
> import java.io.IOException;
> 
> import javax.portlet.PortletPreferences;
> import javax.portlet.ReadOnlyException;
> import javax.portlet.ValidatorException;
> 
> import org.apache.tapestry.annotations.InjectObject;
> import org.apache.tapestry.html.BasePage;
> 
> import net.mycompany.common.CommonRegistry;
> 
> public abstract class NewsListEditPage extends BasePage {
> 
>       @InjectObject("service:tapestry.portlet.PortletRequest")
>       public abstract javax.portlet.PortletRequest getPortletRequest();
> 
>       public abstract String getStockId();
> 
>       public abstract Rubric getCurrentRubric();
> 
>       public static RubricSelectionModel getRubricSelectionModel(){
>             return new
> RubricSelectionModel(CommonRegistry.getRubricList());
>       }
> 
>       public void onOk() {
>             System.out.println("Listener called. Stock id is: " +
> getStockId());
>             PortletPreferences prefs =
> getPortletRequest().getPreferences();
>             try {
>                   prefs.setValue("DocCount", getStockId());
>                   prefs.setValue("RubricId",
> getCurrentRubric().getId().toString());
>                   prefs.store();
>             } catch (ReadOnlyException e) {
>                   e.printStackTrace();
>             } catch (ValidatorException e) {
>                   e.printStackTrace();
>             } catch (IOException e) {
>                   e.printStackTrace();
>             }
>       }
> }
> 
> 
> 
> RubricSelectionModel.java:
> package net.mycompany.portal.news.newslist;
> 
> import java.io.Serializable;
> import java.util.Iterator;
> import java.util.List;
> 
> public class RubricSelectionModel implements Serializable{
>       private static final long serialVersionUID = 1L;
> 
>       private List rubricList;
> 
>         public RubricSelectionModel(List itemList) {
>             this.rubricList = itemList;
>         }
> 
>         public int getOptionCount() { return rubricList.size(); }
> 
>         public Object getOption(int index) {
>             return rubricList.get(index);
>         }
> 
>         public String getLabel(int index) {
>             return ((Rubric) rubricList.get(index)).getName();
>         }
> 
>         public String getValue(int index) {
>               return ((Rubric) rubricList.get(index)).getId().toString();
>         }
> 
>         public Object translateValue(String value) {
>               Iterator e = rubricList.iterator();
>               while(e.hasNext()){
>                     Rubric rubric = (Rubric)e.next();
>                     if(rubric.getId().toString() == value){
>                           return rubric;
>                     }
>               }
>               return null;
>         }
> }
> 
> 
> 
> Rubric.java:
> package net.mycompany.portal.news.newslist;
> 
> import java.io.Serializable;
> 
> public class Rubric implements Serializable{
>       private static final long serialVersionUID = 1L;
> 
>       private Integer id;
>       private String code;
>       private String name;
> 
>       public String getCode() {
>             return code;
>       }
>       public void setCode(String code) {
>             this.code = code;
>       }
>       public Integer getId() {
>             return id;
>       }
>       public void setId(Integer id) {
>             this.id = id;
>       }
>       public String getName() {
>             return name;
>       }
>       public void setName(String name) {
>             this.name = name;
>       }
> 
>       public Rubric(Integer id, String code, String name) {
>             super();
>             this.id = id;
>             this.code = code;
>             this.name = name;
>       }
> }
> 
> 
> 
> DBUtils.java:
> package net.mycompany.portal.utils;
> 
> import java.sql.Connection;
> import java.sql.DatabaseMetaData;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> import java.sql.Timestamp;
> import java.text.ParseException;
> import java.text.SimpleDateFormat;
> 
> import javax.naming.InitialContext;
> import javax.naming.NamingException;
> import javax.sql.DataSource;
> 
> import org.hibernate.SessionFactory;
> import org.hibernate.cfg.Configuration;
> 
> public class DBUtils {
> 
>       private static DataSource ds;
> 
>       private static SessionFactory sessionFactory = new
> Configuration().configure()
>                   .buildSessionFactory();
> 
>       public static SessionFactory getSessionFactory() {
>             return sessionFactory;
>       }
> 
> }
> 
> 
> 
> 
> portlet.xml:
> <portlet-app version="1.0"
>   xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation=
> "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
> http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
>   <portlet>
>     <description xml:lang="EN"></description>
>     <portlet-name>myportlet</portlet-name>
>     <display-name xml:lang="EN">My Tapestry Portlet</display-name>
>     <portlet-class>org.apache.tapestry.portlet.ApplicationPortlet</
> portlet-class>
>     <expiration-cache>-1</expiration-cache>
>     <supports>
>       <mime-type>text/html</mime-type>
>       <portlet-mode>view</portlet-mode>
>       <portlet-mode>help</portlet-mode>
>     </supports>
>     <supported-locale>en</supported-locale>
>     <portlet-info>
>       <title>My Tapestry Portlet</title>
>       <short-title>tapestry-portlet</short-title>
>       <keywords></keywords>
>     </portlet-info>
>   </portlet>
> </portlet-app>
> 
> 
> 
> web.xml:
> <!DOCTYPE web-app
>   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>   "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
>   <display-name>app</display-name>
>   <servlet>
>     <servlet-name>ApplicationServlet</servlet-name>
>     <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
>   </servlet>
>   <servlet-mapping>
>     <servlet-name>ApplicationServlet</servlet-name>
>     <url-pattern>/app</url-pattern>
>   </servlet-mapping>
> </web-app>
> 
> 
> 
> hivemodule.xml:
> doesn't exists
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org