You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by st...@wachovia.com on 2005/03/24 23:53:15 UTC

IPrimaryKeyConvertor() - when object is not found

In the code below, if user clicks back button and resubmits form, the 
getValue method will not find the expected object. I am returning a new 
instance which is incorrect because then I get Binding Exceptions because 
of null properties in the object. How do others handle this scenario? I 
wish at this point where the object was not found I can do something like 
the following: throw new PageRedirectException(this); Isn't this what 
ListEditMap does when it encounters a null? But even that dont work. I 
still get the Binding Exceptions. I'm using TableView with TableFormRows. 
Any suggestions?

 public Home() {
        super();
        // define a IPrimaryKeyConvertor that gets DataItems from the 
original list 
        m_dataItemConvertor = new IPrimaryKeyConvertor()
        {
            public Object getPrimaryKey(Object objValue)
            {
                ModifyMessageRow dataItem = (ModifyMessageRow) objValue;
                return dataItem.getMessage().getSngMsgId();
            }

            public Object getValue(Object objPrimaryKey)
            {
                Integer id = (Integer)objPrimaryKey;
                List list = getMessageList();

                // find the item
                int count = list.size();
                for (int i = 0; i < count; i++)
                {
                        ModifyMessageRow item = (ModifyMessageRow) 
list.get(i);
                    if (item.getMessage().getSngMsgId().equals(id)){
                        return item;
                    }
                }
 
        return new ModifyMessageRow(); //Handle data item not found 
            }
        };
}

Re: IPrimaryKeyConvertor() - when object is not found

Posted by Sebastian Knoerzer <sk...@netlands.de>.
hi,

i had almost the same error. when i clicked in my table on a sortable column 
then i received the same error, because the object was not found.

the line

return new ModifyMessageRow(); //Handle data item not found 

was the cause in my case, because the class (in your case ModifyMessageRow)
had some getters and setters which contained other objects 
(e.g. public Article getArticle()).

so i created an empty object of Article and put it to the class (here
ModifyMessageRow).

Article article = new Article(.....);
ModifyMessageRow row = new ModifyMessageRow();
row.setArticle(article);
return row;

i hope this will help you.

regards

sebastian




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