Ayub Khan schrieb:
> Hi,
>  
> I am having a small issue, I am getting
>
> Error testing property 'commenttext' in bean of type null error
> message. I googled and did lot of troubleshooting, however unable to
> resolve it.
>
> I have a managed bean AppointmentBean which has a Map of comments
>  
> Appointment{
>  
> private Map commentitemMap=new HashMap();
>  
> *
>
> public
>
> * Map getCommentItemMap() { *return* *this*.commentItemMap;
>
> }
>
> *public* *void* setCommentItemMap(Map commentItemMap) {
> *this*.commentItemMap = commentItemMap;
>
> }
>
> }
>
> in my jsp I have bound the text area to
> appointment.commentItemMap['Cancellation Reason'].commenttext
>
> CommentItem {
>
> *private* String commenttext="";*
>
> public
>
> * String getCommenttext() { *return* *this*.commenttext;
>
> }
>
> *public* *void* setCommenttext(String commenttext) {
> *this*.commenttext = commenttext;
>
> }
>
> }
>
>  
>
> In my action method I am setting the commentItem value as below:
>
> CommentItem item=
>
> *new* CommentItem();
>
> comentMap.put(
>
> "Cancellation Reason",item);
>
> appointment.setCommentItemMap(comentMap);
>
>  
>
> when the form is submitted, I read
>
> Error testing property 'commenttext' in bean of type null error message.
>
> In the facesConfig.xml I have declared both appointments bean and
> CommentItem as managed beans in session scope.
>
> If I use appointment.commentItemMap['Cancellation Reason'] without the
> .commenttext , the full classpath of CommentItem is being displayed in
> the text area (I assume its the object.toString value here ).
>
> Please let me know where I am doing wrong.
>
When the form is submitted, the posted form-content will include a value
for the "commenttext" html field (this value will be an empty string if
you typed nothing in that field in the html page). During the "update
model" phase, JSF will therefore try to store that value using the EL
expression
   #{appointment.commentItemMap['Cancellation Reason'].commenttext}
so it
 (a) fetches the appointment bean (ok)
 (b) calls getCommentItemMap --> returns an *empty* map
 (c) calls map.get('Cancellation Reason') --> returns null
 (d) tries to call getCommenttext on the null pointer --> error

Only *after* the model-update phase will it try to run the "action"
method associated with whatever button was pressed. So it is too late at
that point to try to add an object to your commentItemMap with key
'Cancellation Reason'; processing has already tried to access the
nonexistent object earlier.

Regards,
Simon

-- 
-- Emails in "mixed" posting style will be ignored
-- (http://en.wikipedia.org/wiki/Posting_style)

Reply via email to