You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Khai Wan <ip...@yahoo.com> on 2006/04/18 22:06:59 UTC

Hello,

I have a problem of which I could not figure out why. I am currently using
the following:

(a) jar files

commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.1.jar
commons-dbcp-1.2.1.jar
commons-digester-1.7.jar
commons-el-1.0.jar
commons-lang-2.1.jar
commons-logging-1.0.4.jar
commons-pool-1.2.jar
el-api-1.0.jar
el-ri-1.0.jar
jsf-facelets-1.1.2.jar
jstl-1.1.0.jar
log4j-1.2.13.jar
myfaces-api-1.1.3-SNAPSHOT.jar
myfaces-impl-1.1.3-SNAPSHOT.jar
myfaces-shared-impl-2.0.1-SNAPSHOT.jar
xercesImpl-2.0.2.jar
xml-apis-1.0.b2.jar

(b) test.xhtml
 
      <h:form id="dummy">
            <h:selectOneListbox size="1" 
                                value="#{myform.data}">
              <f:selectItems value="#{myform.dataItems}"/>
            </h:selectOneListbox>
            <h:commandButton action="#{myform.execute}"
                             id="button"
                             value="Press"/>
      </h:form>

(c) faces-config.xml

  <managed-bean>
    <managed-bean-name>myform</managed-bean-name>
    <managed-bean-class>com.arc.MyForm</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>    
  </managed-bean>

(d) MyForm.java

package com.arc;
import javax.faces.model.SelectItem;

public class MyForm
{
  private String data;
  private SelectItem[] dataItems;

  public MyForm()
  {
    dataItems = new SelectItem[2];
    dataItems[0] = new SelectItem("1","one");
    dataItems[1] = new SelectItem("2","two");
  }

  public SelectItem[] getDataItems()
  {
    return dataItems;
  }

  public void setDataItems(SelectItem[] value)
  {
    dataItems = value;
  }

  public String getData()
  {
    return data;
  }

  public void setData(String value)
  {
    data = value;
  }

  public String execute()
  {
    return "success";
  }
}
  
(e) jetty 6

I am using jett 6 and jdk 1.5.

(f) Internet Explorer

When I test out the above code, the browser shows a listing of items. When I
press the button, myfaces throws the following exception:


HTTP ERROR: 500
Value binding '#{myform.dataItems}'of UISelectItems with component-path
{Component-Path : 
[Class: javax.faces.component.UIViewRoot,ViewId: /app/test.xhtml]
[Class: javax.faces.component.html.HtmlForm,Id: dummy]
[Class: javax.faces.component.html.HtmlSelectOneListbox,Id: _id23]
[Class: javax.faces.component.UISelectItems,Id: _id24]} does not reference
an Object of type SelectItem, SelectItem[], Collection or Map but of type :
null


Hope someone seen this before. Would appreciate very much for any help.

Thanks,
Khai Wan

--
View this message in context: http://www.nabble.com/%3Ch%3AselectOneListbox%3E-t1470396.html#a3975697
Sent from the My Faces - Dev forum at Nabble.com.


Re:

Posted by Khai Wan <ip...@yahoo.com>.
Thanks Mike. Your example is very informative. The facelets is really
excellent on top of myfaces. I am porting our struts/tiles based web
application into facelets/myfaces. The jsp pages using facelets/myfaces are
alot cleaner than struts/tiles. It has been an exciting adventure. Later on
down the road, we will incorporate ajax into the project. Thanks again. I am
sure I will have some other related jsf questions along the way of which
will need further of your assistance.
--
View this message in context: http://www.nabble.com/%3Ch%3AselectOneListbox%3E-t1470396.html#a3999401
Sent from the My Faces - Dev forum at Nabble.com.


Re:

Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/19/06, Khai Wan <ip...@yahoo.com> wrote:
> I cannot get the tomahawk work within the framework of
> facelets/myfaces. Perhaps I might be using the wrong jar file etc..

Make sure you've manually specified a tomahawk.taglib.xml file.  
There's an example on the wiki. (something like
"Using_facelets_with_tomahawk")

> Our web application requires the dynamically creation of select items (eg.
> many different types of select items). These items are at times a very long
> listing. So putting it into the session or application is not feasible as it
> will take alot of memory. Instead, I have no other choice but to re-query
> the listing from the database each time the request comes in. In my example,
> I have to repopulate the dataItems again.

Yes, I have the same situation, and I do it by creating *ItemProvider
class beans with methods similar to this.   If the scope of the bean
is request, then the data is fetched once.  If session, once per
session.  If application, once per application.   Or it can be
preserved across requests by using t:saveState.

    private SelectItem[] announcementItems = null;
    public SelectItem[] getAnnouncementItems()
    {
        if (null == announcementItems)
        {
        	announcementList = coreCustomerDataStore.getAnnouncementList();

        	announcementItems = new SelectItem[announcementList.size()];
        	for (int index = 0; index < announcementList.size(); ++index)
        	{
        	    Announcement announcement = (Announcement)
announcementList.get(index);
        	    announcementItems[index] = new SelectItem(announcement,
announcement.getUIDisplayLabel());
        	}
        }

        return announcementItems;
    }

Re:

Posted by Khai Wan <ip...@yahoo.com>.
Thanks for the tips. After reading your comment, I just begin to realize that
the backing bean, in my example, the dataItems need to be delcared as
static. In other words,
private static SelectItem[] dataItems;

Either declared it as static or just use your suggestion by putting it into
the session or application or using <t:saveState> tomahawk. For some
reasons, I cannot get the tomahawk work within the framework of
facelets/myfaces. Perhaps I might be using the wrong jar file etc.. 

Our web application requires the dynamically creation of select items (eg.
many different types of select items). These items are at times a very long
listing. So putting it into the session or application is not feasible as it
will take alot of memory. Instead, I have no other choice but to re-query
the listing from the database each time the request comes in. In my example,
I have to repopulate the dataItems again.

--
View this message in context: http://www.nabble.com/%3Ch%3AselectOneListbox%3E-t1470396.html#a3994323
Sent from the My Faces - Dev forum at Nabble.com.


Re:

Posted by Mike Kienenberger <mk...@gmail.com>.
myForm is a new bean on the second request.

You can either make the bean session or application-scoped or you can
use <t:saveState> from Tomahawk to persist your managed request-scope
bean values to the next request cycle.   Most of us use the second
option.

On 4/18/06, Khai Wan <ip...@yahoo.com> wrote:
>
> Hello,
>
> I have a problem of which I could not figure out why. I am currently using
> the following:
>
> (a) jar files
>
> commons-beanutils-1.7.0.jar
> commons-codec-1.3.jar
> commons-collections-3.1.jar
> commons-dbcp-1.2.1.jar
> commons-digester-1.7.jar
> commons-el-1.0.jar
> commons-lang-2.1.jar
> commons-logging-1.0.4.jar
> commons-pool-1.2.jar
> el-api-1.0.jar
> el-ri-1.0.jar
> jsf-facelets-1.1.2.jar
> jstl-1.1.0.jar
> log4j-1.2.13.jar
> myfaces-api-1.1.3-SNAPSHOT.jar
> myfaces-impl-1.1.3-SNAPSHOT.jar
> myfaces-shared-impl-2.0.1-SNAPSHOT.jar
> xercesImpl-2.0.2.jar
> xml-apis-1.0.b2.jar
>
> (b) test.xhtml
>
>       <h:form id="dummy">
>             <h:selectOneListbox size="1"
>                                 value="#{myform.data}">
>               <f:selectItems value="#{myform.dataItems}"/>
>             </h:selectOneListbox>
>             <h:commandButton action="#{myform.execute}"
>                              id="button"
>                              value="Press"/>
>       </h:form>
>
> (c) faces-config.xml
>
>   <managed-bean>
>     <managed-bean-name>myform</managed-bean-name>
>     <managed-bean-class>com.arc.MyForm</managed-bean-class>
>     <managed-bean-scope>request</managed-bean-scope>
>     <managed-property>
>   </managed-bean>
>
> (d) MyForm.java
>
> package com.arc;
> import javax.faces.model.SelectItem;
>
> public class MyForm
> {
>   private String data;
>   private SelectItem[] dataItems;
>
>   public MyForm()
>   {
>     dataItems = new SelectItem[2];
>     dataItems[0] = new SelectItem("1","one");
>     dataItems[1] = new SelectItem("2","two");
>   }
>
>   public SelectItem[] getDataItems()
>   {
>     return dataItems;
>   }
>
>   public void setDataItems(SelectItem[] value)
>   {
>     dataItems = value;
>   }
>
>   public String getData()
>   {
>     return data;
>   }
>
>   public void setData(String value)
>   {
>     data = value;
>   }
>
>   public String execute()
>   {
>     return "success";
>   }
> }
>
> (e) jetty 6
>
> I am using jett 6 and jdk 1.5.
>
> (f) Internet Explorer
>
> When I test out the above code, the browser shows a listing of items. When I
> press the button, myfaces throws the following exception:
>
>
> HTTP ERROR: 500
> Value binding '#{myform.dataItems}'of UISelectItems with component-path
> {Component-Path :
> [Class: javax.faces.component.UIViewRoot,ViewId: /app/test.xhtml]
> [Class: javax.faces.component.html.HtmlForm,Id: dummy]
> [Class: javax.faces.component.html.HtmlSelectOneListbox,Id: _id23]
> [Class: javax.faces.component.UISelectItems,Id: _id24]} does not reference
> an Object of type SelectItem, SelectItem[], Collection or Map but of type :
> null
>
>
> Hope someone seen this before. Would appreciate very much for any help.
>
> Thanks,
> Khai Wan
>
> --
> View this message in context: http://www.nabble.com/%3Ch%3AselectOneListbox%3E-t1470396.html#a3975697
> Sent from the My Faces - Dev forum at Nabble.com.
>
>