Problem with rendering of the Palette component

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

Problem with rendering of the Palette component

Jelena Jovanovic
Hello,

I have a problem with the Palette component. I keep receiving
NullPointerException and the stack trace as follows:

*
org.apache.tapestry.contrib.palette.Palette.handleSubmission(Palette.java:48
9)

*
org.apache.tapestry.contrib.palette.Palette.renderComponent(Palette.java:285
)

*
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)

*
org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)


*
org.apache.tapestry.form.Form.renderComponent(Form.java:362)

*
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)

*                       org.apache.tapestry.form.Form.rewind(Form.java:568)

.

 

I checked I don't even know how many times the specification of the
component but I can't spot the mistakes. Here it is:

 

<property-specification name="subTopicsOfInterest" type="java.util.List"
persistent="yes"/>

<property-specification name="topicsModel"
type="org.apache.tapestry.form.IPropertySelectionModel"/>

 

<component id="selectTopics" type="contrib:Palette">

      <binding
name="sort">@org.apache.tapestry.contrib.palette.SortMode@USER</binding>

      <binding name="model" expression="topicsModel"/>

      <binding name="selected" expression="subTopicsOfInterest"/>

      <binding name="selectedTitleBlock"
expression="components.selectedTitleBlock"/>

      <binding name="availableTitleBlock"
expression="components.availableTitleBlock"/>

</component>

 

I did not make the model persistent since it should be filed with a new set
of values each time the page is presented to the user.

 

If I try to submit the form without making any selection in the Palette
component, everything is fine. However, if I make a selection and then
submit the page I get the exception and the stack trace presented above.

 

Can anyone give some advice? I really do not have ideas how to solve this
problem.

Thanks in advance!

Jelena

Reply | Threaded
Open this post in threaded view
|

Re: Problem with rendering of the Palette component

Robert Zeigler
Jelena Jovanovic wrote:
> Hello,
>
> I have a problem with the Palette component. I keep receiving
> NullPointerException and the stack trace as follows:
<edited />

>
> I did not make the model persistent since it should be filed with a new set
> of values each time the page is presented to the user.
>  
>
> If I try to submit the form without making any selection in the Palette
> component, everything is fine. However, if I make a selection and then
> submit the page I get the exception and the stack trace presented above.
>
>  
>
> Can anyone give some advice? I really do not have ideas how to solve this
> problem.

Sounds like your model is null after you submit. How/when is your model
being instantiated? If, for example, you are setting the topicsModel
from a listener method before activating the page, then when you submit
the form, the model is not re-instantiated, and since it isn't
persistent, the property is null (hence your null pointer exception).
The reason it works fine when you don't select anything is because,
since nothing is selected, the model is never accessed.
You mentioned that the available selections should be regenerated on
each view of the page, since it changes. One possibility is that if your
model is serializable, you could store it in a @Hidden field before the
palette component reference, which would ensure that the property is
available before render.  Otherwise, you could store the criterion used
to generate the model in a hidden field, and then define a listener
method for the @Hidden component to call that re-instantiates the model.
There are various other possibilities.

Robert
>
> Thanks in advance!
>
> Jelena
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Problem with rendering of the Palette component

Jelena Jovanovic


Thanks for advice! However, I still do not manage to make it work -:(

> Sounds like your model is null after you submit. How/when is your model
> being instantiated?
It is instantiated in the activate method. If I understood properly page
rendering sequence this method is supposed to be called before each page
rendering - or I'm wrong?

> One possibility is that if your model is serializable, you could store it
>in a @Hidden field before the palette component reference, which would
>ensure that the property is available before render.
I tried this but again receive NullPointerException with the following stack
trace:
org.apache.tapestry.contrib.palette.PaletteColumn.render(PaletteColumn.java:
112)
org.apache.tapestry.components.Delegator.renderComponent(Delegator.java:45)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)

org.apache.tapestry.components.Any.renderComponent(Any.java:53)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118)
org.apache.tapestry.contrib.palette.Palette.renderComponent(Palette.java:310
)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)

org.apache.tapestry.form.Form.renderComponent(Form.java:362)

Here is the implementation of the model that I'm using:

public class ConceptSelectionModel implements IPropertySelectionModel,
Serializable {

    private List concepts = new ArrayList();

    public void add(String uri, String label) {        
        SKOSConcept entry = new SKOSConcept(uri, label);
        concepts.add(entry);
    }

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

    private SKOSConcept get(int index) {
        return (SKOSConcept) concepts.get(index);
    }

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

    public String getLabel(int index){
        return get(index).getPrefLabel();
    }

    public String getValue(int index) {
     
    String uri = get(index).getUri();

        if (uri == null)
            return "";
       
        return uri;
    }

    public Object translateValue(String value)
    {
        if (value.equals(""))
            return null;

        ListIterator li = concepts.listIterator();
        while ( li.hasNext() ) {
        SKOSConcept c = (SKOSConcept)li.next();
        if ( c.getUri().equals(value) )
        return c;
        }
       
        return null;
    }
}

Where class SKOSConcept has only two properties: uri and label and their
setters and getters and implements Serializable.

Regards,
Jelena

-----Original Message-----
From: Robert Zeigler [mailto:[hidden email]]
Sent: Monday, May 16, 2005 2:32 AM
To: Tapestry users
Subject: Re: Problem with rendering of the Palette component

Jelena Jovanovic wrote:
> Hello,
>
> I have a problem with the Palette component. I keep receiving
> NullPointerException and the stack trace as follows:
<edited />
>
> I did not make the model persistent since it should be filed with a new
set

> of values each time the page is presented to the user.
>  
>
> If I try to submit the form without making any selection in the Palette
> component, everything is fine. However, if I make a selection and then
> submit the page I get the exception and the stack trace presented above.
>
>  
>
> Can anyone give some advice? I really do not have ideas how to solve this
> problem.

Sounds like your model is null after you submit. How/when is your model
being instantiated? If, for example, you are setting the topicsModel
from a listener method before activating the page, then when you submit
the form, the model is not re-instantiated, and since it isn't
persistent, the property is null (hence your null pointer exception).
The reason it works fine when you don't select anything is because,
since nothing is selected, the model is never accessed.
You mentioned that the available selections should be regenerated on
each view of the page, since it changes. One possibility is that if your
model is serializable, you could store it in a @Hidden field before the
palette component reference, which would ensure that the property is
available before render.  Otherwise, you could store the criterion used
to generate the model in a hidden field, and then define a listener
method for the @Hidden component to call that re-instantiates the model.
There are various other possibilities.

Robert
>
> Thanks in advance!
>
> Jelena
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]