using jsp:setProperty on non-simple types.

E

Emmanuel Doute

Hi,

I'm currently having a small problem with my application. I'm using
some simple classes that wraps simple types to help me provide multiple
representation. For example, a DateCBO calls wraps the Date type and
gives me the oportunity to have various 'getters' like
getDateShortFormat(), getHtml(), getDateLongFormat() and so on.

My beans are using this kind of wrappers as their properties.

I have already made a custom tag to retrieve information that i use
instead of the standard jsp:getProperty
Now, i'm trying to use the jsp:setProperty to initialise the bean
property, but i have 'Could not coerce String to non-primitive type
StringCBO without bean property editor (JSP 1.2: 2.13.2.1) at line 13'
error.

Is there an interface that i can use to allow direct usage of
'jsp:setProperty', or should i create a custom tag as well.

thanks.
 
R

Ryan Stewart

Emmanuel Doute said:
Hi,

I'm currently having a small problem with my application. I'm using
some simple classes that wraps simple types to help me provide multiple
representation. For example, a DateCBO calls wraps the Date type and
gives me the oportunity to have various 'getters' like
getDateShortFormat(), getHtml(), getDateLongFormat() and so on.

My beans are using this kind of wrappers as their properties.

I have already made a custom tag to retrieve information that i use
instead of the standard jsp:getProperty
Now, i'm trying to use the jsp:setProperty to initialise the bean
property, but i have 'Could not coerce String to non-primitive type
StringCBO without bean property editor (JSP 1.2: 2.13.2.1) at line 13'
error.

Is there an interface that i can use to allow direct usage of
'jsp:setProperty', or should i create a custom tag as well.
You could create a setter on your bean that accepts a String.
 
J

John C. Bollinger

Emmanuel said:
Hi,

I'm currently having a small problem with my application. I'm using
some simple classes that wraps simple types to help me provide multiple
representation. For example, a DateCBO calls wraps the Date type and
gives me the oportunity to have various 'getters' like
getDateShortFormat(), getHtml(), getDateLongFormat() and so on.

My beans are using this kind of wrappers as their properties.

I have already made a custom tag to retrieve information that i use
instead of the standard jsp:getProperty
Now, i'm trying to use the jsp:setProperty to initialise the bean
property, but i have 'Could not coerce String to non-primitive type
StringCBO without bean property editor (JSP 1.2: 2.13.2.1) at line 13'
error.

Is there an interface that i can use to allow direct usage of
'jsp:setProperty', or should i create a custom tag as well.

You can do as the message suggests and create a property editor for that
bean property, but it is probably at least as much work as writing a
custom tag to do the job. If you prefer, you could write a bit of
scriptlet code to do the job, or if you are using JSP 2 you could do it
with JSP expression language.


John Bollinger
(e-mail address removed)
 
E

Emmanuel Doute

Thanks for your answers.

I will probably use a scriptlet, as i seldom have to set property from
within the JSP.

I tried to add just a setter method with a String, but it still
complains.

It finally worked by adding a 'real' String property and using it's
setter to update my non-basic property as well. But this is causing
quite a mess in all the bean properties, so i gave it up.
 
R

Ryan Stewart

Emmanuel Doute said:
Thanks for your answers.

I will probably use a scriptlet, as i seldom have to set property from
within the JSP.

I tried to add just a setter method with a String, but it still
complains.

It finally worked by adding a 'real' String property and using it's
setter to update my non-basic property as well. But this is causing
quite a mess in all the bean properties, so i gave it up.
It shouldn't be all that messy:

public class SomeBean {
private String value;
// Other properties

public void setValue(String value) {
this.value = value;
this.parse();
}

private void parse() {
// Do stuff to populate from the String whatever properties you need
}

// Other methods
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top