Trouble With Type Converters ---> Model Class

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble With Type Converters ---> Model Class

Wade Marshall
I am trying to copy the example in Chapter 5 of the Stripes book (Daoud) for Type Converters and Model Classes, but it doesn't work.

My model class is called ProductGroup, their model class is called Contact.

The good news (I think) is that my app logs seem to indicate the formatter is being picked up by the configuration done in web.xml   (see logs below)

The bad news is that my generated HTML (wrong) looks like this.....
<a href="/imgweb/PreCardOrder.action?productGroup=com.yff.db.model.ProductGroup%40201adc">
and theirs (correct) looks like....
<a href="/email_07/ContactForm.action?contact=2">

If I'm right the configuration of the formatter being ok.....how might I go about debugging this problem from here ?

Or if there's something else I should look, let me know too. 

Thanks all,
Wade.

==========================================================

Email_07 Application Log

[16:08:00] DEBUG net.sourceforge.stripes.config.RuntimeConfiguration  - Adding auto-discovered Formatter [class stripesbook.ext.ContactFormatter] for [class stripesbook.model.Contact] (from type parameter)

Email_07 Formatter

package stripesbook.ext;

import java.util.Locale;
import net.sourceforge.stripes.format.Formatter;
import stripesbook.model.Contact;

public class ContactFormatter implements Formatter<Contact> {
    public String format(Contact contact) {
        return String.valueOf(contact.getId());
    }
    public void init() { }
    public void setLocale(Locale locale) { }
    public void setFormatType(String type) { }
    public void setFormatPattern(String pattern) { }
}

Email_07 Model Class

package stripesbook.model;

import java.util.Date;

public class Contact {
...
    private Integer id;
}

==========================================================

My Application Log

16:33:56,047 DEBUG net.sourceforge.stripes.config.RuntimeConfiguration:194 - Found Formatter [class com.yff.web.ext.ProductGroupFormatter] - type parameters: [class com.yff.db.model.ProductGroup]

My Formatter

package com.yff.web.ext;

import java.util.Locale;
import com.yff.db.model.ProductGroup;
import net.sourceforge.stripes.format.Formatter;

public class ProductGroupFormatter implements Formatter <ProductGroup>{

    @Override
    public String format(ProductGroup productGroup) {
        return productGroup.getId();
    }

    @Override
    public void init() {}

    @Override
    public void setFormatPattern(String pattern) {}

    @Override
    public void setFormatType(String type) {}

    @Override
    public void setLocale(Locale locale) {}
   
}

My ProductGroup Model Class

package com.yff.db.model;
...

public class ProductGroup implements Serializable
{
    ....
    private String id;
   
    @Id
    public String getId()
    {
        return id;
    }
...
}


My JSP

<stripes:link beanclass="com.yff.web.action.PreCardOrderActionBean" >
  <stripes:param name="productGroup">${productgroup}</stripes:param>
   Create
</stripes:link>


------------------------------------------------------------------------------

_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Trouble With Type Converters ---> Model Class

Aaron Porter-3
Wade,
Stripes is finding your formatter but unless you omitted some lines from the log it looks like it isn't associating the formatter with your class. In the log you posted from the book's example it says "Adding auto-discovered Formatter" but that is missing in your log output.

Are you using the Stripes 1.5 jar file or did you build your own from source? The line number from your log doesn't match up with the Stripes source.

I don't see anything obvious wrong with your code but your formatter is definitely not being used. I'm not sure what to suggest beyond making your source available somewhere to test with.

Aaron

Wade Marshall wrote:
I am trying to copy the example in Chapter 5 of the Stripes book (Daoud) for Type Converters and Model Classes, but it doesn't work.

My model class is called ProductGroup, their model class is called Contact.

The good news (I think) is that my app logs seem to indicate the formatter is being picked up by the configuration done in web.xml   (see logs below)

The bad news is that my generated HTML (wrong) looks like this.....
<a href="/imgweb/PreCardOrder.action?productGroup=com.yff.db.model.ProductGroup%40201adc">
and theirs (correct) looks like....
<a href="/email_07/ContactForm.action?contact=2">

If I'm right the configuration of the formatter being ok.....how might I go about debugging this problem from here ?

Or if there's something else I should look, let me know too. 

Thanks all,
Wade.

==========================================================

Email_07 Application Log

[16:08:00] DEBUG net.sourceforge.stripes.config.RuntimeConfiguration  - Adding auto-discovered Formatter [class stripesbook.ext.ContactFormatter] for [class stripesbook.model.Contact] (from type parameter)

Email_07 Formatter

package stripesbook.ext;

import java.util.Locale;
import net.sourceforge.stripes.format.Formatter;
import stripesbook.model.Contact;

public class ContactFormatter implements Formatter<Contact> {
    public String format(Contact contact) {
        return String.valueOf(contact.getId());
    }
    public void init() { }
    public void setLocale(Locale locale) { }
    public void setFormatType(String type) { }
    public void setFormatPattern(String pattern) { }
}

Email_07 Model Class

package stripesbook.model;

import java.util.Date;

public class Contact {
...
    private Integer id;
}

==========================================================

My Application Log

16:33:56,047 DEBUG net.sourceforge.stripes.config.RuntimeConfiguration:194 - Found Formatter [class com.yff.web.ext.ProductGroupFormatter] - type parameters: [class com.yff.db.model.ProductGroup]

My Formatter

package com.yff.web.ext;

import java.util.Locale;
import com.yff.db.model.ProductGroup;
import net.sourceforge.stripes.format.Formatter;

public class ProductGroupFormatter implements Formatter <ProductGroup>{

    @Override
    public String format(ProductGroup productGroup) {
        return productGroup.getId();
    }

    @Override
    public void init() {}

    @Override
    public void setFormatPattern(String pattern) {}

    @Override
    public void setFormatType(String type) {}

    @Override
    public void setLocale(Locale locale) {}
   
}

My ProductGroup Model Class

package com.yff.db.model;
...

public class ProductGroup implements Serializable
{
    ....
    private String id;
   
    @Id
    public String getId()
    {
        return id;
    }
...
}


My JSP

<stripes:link beanclass="com.yff.web.action.PreCardOrderActionBean" >
  <stripes:param name="productGroup">${productgroup}</stripes:param>
   Create
</stripes:link>


------------------------------------------------------------------------------

_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------

_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Trouble With Type Converters ---> Model Class

Freddy D.
In reply to this post by Wade Marshall
Hi Wade,

The problem is that you are using:

  <stripes:param name="productGroup">${productgroup}</stripes:param>

Here, ${productgroup} is just regular EL - you are not giving Stripes
a chance to use your formatter. Instead, use the following (this is
also what I use in the example from the book):

  <stripes:param name="productGroup" value="${productgroup}"/>

This gives the Stripes param tag the opportunity to use your Formatter
to format the ProductGroup.

Let me know if that helps.

Cheers,
Freddy
http://www.stripesbook.com


On Tue, 23 Dec 2008 17:19:39 -0500, "Wade Marshall" <[hidden email]>
said:

> I am trying to copy the example in Chapter 5 of the Stripes book (Daoud)
> for
> Type Converters and Model Classes, but it doesn't work.
>
> My model class is called ProductGroup, their model class is called
> Contact.
>
> The good news (I think) is that my app logs seem to indicate the
> formatter
> is being picked up by the configuration done in web.xml   (see logs
> below)
>
> The bad news is that my generated HTML (wrong) looks like this.....
>
> <a
> href="/imgweb/PreCardOrder.action?productGroup=com.yff.db.model.ProductGroup%40201adc">
>
> and theirs (correct) looks like....
>
> <a href="/email_07/ContactForm.action?contact=2">
>
>
> If I'm right the configuration of the formatter being ok.....how might I
> go
> about debugging this problem from here ?
>
> Or if there's something else I should look, let me know too.
>
> Thanks all,
> Wade.
>
> ==========================================================
>
> Email_07 Application Log
>
> [16:08:00] DEBUG net.sourceforge.stripes.config.RuntimeConfiguration  -
> Adding auto-discovered Formatter [class stripesbook.ext.ContactFormatter]
> for [class stripesbook.model.Contact] (from type parameter)
>
> Email_07 Formatter
>
> package stripesbook.ext;
>
> import java.util.Locale;
> import net.sourceforge.stripes.format.Formatter;
> import stripesbook.model.Contact;
>
> public class ContactFormatter implements Formatter<Contact> {
>     public String format(Contact contact) {
>         return String.valueOf(contact.getId());
>     }
>     public void init() { }
>     public void setLocale(Locale locale) { }
>     public void setFormatType(String type) { }
>     public void setFormatPattern(String pattern) { }
> }
>
> Email_07 Model Class
>
> package stripesbook.model;
>
> import java.util.Date;
>
> public class Contact {
> ...
>     private Integer id;
> }
>
> ==========================================================
>
> My Application Log
>
> 16:33:56,047 DEBUG
> net.sourceforge.stripes.config.RuntimeConfiguration:194 -
> Found Formatter [class com.yff.web.ext.ProductGroupFormatter] - type
> parameters: [class com.yff.db.model.ProductGroup]
>
> My Formatter
>
> package com.yff.web.ext;
>
> import java.util.Locale;
> import com.yff.db.model.ProductGroup;
> import net.sourceforge.stripes.format.Formatter;
>
> public class ProductGroupFormatter implements Formatter <ProductGroup>{
>
>     @Override
>     public String format(ProductGroup productGroup) {
>         return productGroup.getId();
>     }
>
>     @Override
>     public void init() {}
>
>     @Override
>     public void setFormatPattern(String pattern) {}
>
>     @Override
>     public void setFormatType(String type) {}
>
>     @Override
>     public void setLocale(Locale locale) {}
>
> }
>
> My ProductGroup Model Class
>
> package com.yff.db.model;
> ...
>
> public class ProductGroup implements Serializable
> {
>     ....
>     private String id;
>
>     @Id
>     public String getId()
>     {
>         return id;
>     }
> ...
> }
>
>
> My JSP
>
> <stripes:link beanclass="com.yff.web.action.PreCardOrderActionBean" >
>   <stripes:param name="productGroup">${productgroup}</stripes:param>
>    Create
> </stripes:link>

------------------------------------------------------------------------------
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Trouble With Type Converters ---> Model Class

Wade Marshall
In reply to this post by Wade Marshall
Hi Aaron,

Thanks for your reply.  I am actually seeing the same "auto-discovered Formatter" in my logs.  It's just not picking it up when the JSP is rendered.

Adding auto-discovered Formatter [class com.yff.web.ext.ProductGroupFormatter] for [class com.yff.db.model.ProductGroup] (from type parameter)
Adding auto-discovered TypeConverter [class com.yff.web.ext.ProductGroupConverter] for [class com.yff.db.model.ProductGroup] (from type parameter)

I'll consider posting source if I have no luck over the next couple of days.

Thanks,
Wade.
 
Date: Tue, 23 Dec 2008 16:42:37 -0700
From: Aaron Porter <[hidden email]>
Subject: Re: [Stripes-users] Trouble With Type Converters ---> Model
       Class
To: Stripes Users List <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="iso-8859-1"

Wade,
Stripes is finding your formatter but unless you omitted some lines from
the log it looks like it isn't associating the formatter with your
class. In the log you posted from the book's example it says "Adding
auto-discovered Formatter" but that is missing in your log output.

Are you using the Stripes 1.5 jar file or did you build your own from
source? The line number from your log doesn't match up with the Stripes
source.

I don't see anything obvious wrong with your code but your formatter is
definitely not being used. I'm not sure what to suggest beyond making
your source available somewhere to test with.

Aaron

------------------------------------------------------------------------------

_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Trouble With Type Converters ---> Model Class

amagha
In reply to this post by Wade Marshall
Wade Marshall <wadexyz@...> writes:
>
>
> I am trying to copy the example in Chapter 5 of the Stripes book (Daoud) for
Type Converters and Model Classes, but it doesn't work.My model class is called
ProductGroup, their model class is called Contact.The good news (I think) is
that my app logs seem to indicate the formatter is being picked up by the
configuration done in web.xml   (see logs below)The bad news is that my
generated HTML (wrong) looks like this.....<a href="/imgweb/PreCardOrder.action?
productGroup=com.yff.db.model.ProductGroup%40201adc">
> and theirs (correct) looks like....<a href="/email_07/ContactForm.action?
contact=2">
> If I'm right the configuration of the formatter being ok.....how might I go
about debugging this problem from here ?Or if there's something else I should
look, let me know too.  Thanks all,
> Wade.==========================================================Email_07
Application Log[16:08:00] DEBUG
net.sourceforge.stripes.config.RuntimeConfiguration  - Adding auto-discovered
Formatter [class stripesbook.ext.ContactFormatter] for [class
stripesbook.model.Contact] (from type parameter)Email_07 Formatterpackage
stripesbook.ext;import java.util.Locale;import
net.sourceforge.stripes.format.Formatter;import
stripesbook.model.Contact;public class ContactFormatter implements
Formatter<Contact> {
>     public String format(Contact contact) {        return String.valueOf
(contact.getId());    }    public void init() { }    public void setLocale
(Locale locale) { }    public void setFormatType(String type) { }
>     public void setFormatPattern(String pattern) { }}Email_07 Model
Classpackage stripesbook.model;import java.util.Date;public class Contact
{...    private Integer
id;}==========================================================My Application
Log16:33:56,047 DEBUG net.sourceforge.stripes.config.RuntimeConfiguration:194 -
Found Formatter [class com.yff.web.ext.ProductGroupFormatter] - type
parameters: [class com.yff.db.model.ProductGroup]My Formatterpackage
com.yff.web.ext;import java.util.Locale;import
com.yff.db.model.ProductGroup;import
net.sourceforge.stripes.format.Formatter;public class ProductGroupFormatter
implements Formatter <ProductGroup>{     <at> Override    public String format
(ProductGroup productGroup) {        return productGroup.getId();    }     <at>
Override    public void init() {}     <at> Override    public void
setFormatPattern(String pattern) {}     <at> Override    public void
setFormatType(String type) {}     <at> Override    public void setLocale(Locale
locale) {}    }My ProductGroup Model Classpackage com.yff.db.model;...public
class ProductGroup implements Serializable {    ....    private String id;   
     <at> Id    public String getId()    {        return id;    }...}My JSP
> <stripes:link beanclass="com.yff.web.action.PreCardOrderActionBean" > 
<stripes:param name="productGroup">${productgroup}</stripes:param>   Create</
stripes:link>

>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@...
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>

Hi Wade (and Stripes Users) --

This is my first ever post as I just got Freddy's book last week and am working
through the examples as well.

Coincidentally, I too am in Ch. 5 and ran into a little bit of trouble in this
section here as well.  My problem was w/ the PhoneNumberFormatter and the issue
I was having was that after having applied the formatter, I wasn't seeing:

    555-123-4567

In my view or updated forms.  Instead, I was seeing:

    org.stripesbook.quickstart.model.PhoneNumber@69a4cb

After quite a bit of searching around, I found my problem to be that I am using
Stripes QuickStart, which sets one of the default extension directories to be:

    org.stripesbook.quickstart.extension

But my package (as per the source code in the book) is:

    org.stripesbook.quickstart.ext

My problem was that Stripes wasn't finding my formatter.

I just thought I'd mention this for anyone else that is going through the
(excellent) Stripes book and stumbles in this section.




------------------------------------------------------------------------------
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Trouble With Type Converters ---> Model Class

Girish Shekhar
Alamgir Kahn <ama-list@...> writes:

> > Stripes-users mailing list
> > Stripes-users@...
> > https://lists.sourceforge.net/lists/listinfo/stripes-users
> >
>
> Hi Wade (and Stripes Users) --
>
> This is my first ever post as I just got Freddy's book last week and am
working
> through the examples as well.
>
> Coincidentally, I too am in Ch. 5 and ran into a little bit of trouble in this
> section here as well.  My problem was w/ the PhoneNumberFormatter and the
issue
> I was having was that after having applied the formatter, I wasn't seeing:
>
>     555-123-4567
>
> In my view or updated forms.  Instead, I was seeing:
>
>     org.stripesbook.quickstart.model.PhoneNumber <at> 69a4cb
>
> After quite a bit of searching around, I found my problem to be that I am
using

> Stripes QuickStart, which sets one of the default extension directories to be:
>
>     org.stripesbook.quickstart.extension
>
> But my package (as per the source code in the book) is:
>
>     org.stripesbook.quickstart.ext
>
> My problem was that Stripes wasn't finding my formatter.
>
> I just thought I'd mention this for anyone else that is going through the
> (excellent) Stripes book and stumbles in this section.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Stripes-users mailing list
> Stripes-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>

--------------------------------------------------------------------------
Hi Alamgir Kahn / Stripes Users

Can you elaborate on using Stripes QuickStart.
I've also stumbled upon the same error stripesbook.model.PhoneNumber [at] b2377c
I cant figure out whats wrong.
My package name is stripesbook.ext wherein I've kept the formatter and
typeConverter.
I tried renaming the package to extension, but it did not work either.
Is there some config file associated which is to be rectified ?

Thanks in advance
Girish Shekhar
-------------------------------------------------------------------------




------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users