myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Aranda <brunoara...@gmail.com>
Subject Re: NullPointerException when trying to access bean values
Date Tue, 12 Jul 2005 14:19:37 GMT
Well, you are getting a null because you are trying to get the cname
when it is not applied yet. If you want to get the new value of the
input test using a valueChangeListener you have to do it like this:

String newCname = (String) vce.getNewValue();

What I recommend you is not to use a valueChangeListener in this case,
as you can get the whole Customer object from the method invoked when
the commandButton is pressed. I see that you invoke the same method
for the action and the actionListener, and this is not ok. You can
invoke a method (void, and that accepts ActionEvent as parameter)
using the actionListener, and this method can do some logic with your
Customer object (with Cname set already), as you are trying to do now
in the valueChanged method. The action is used for navigation
purposes, and the invoked method have to return a String an accept no
parameters,

HTH,

Bruno

2005/7/12, Srikanth Madarapu <srikanthm@senior-systems.com>:
> 
> log.info(getCustomer().getCname().toString());
> 
> I think the getCname is returning a NULL value, or the log is NULL.
> 
> HTH
> Srikanth
> 
> -----Original Message-----
> From: Johannes Hiemer [mailto:jhiemer@web.de]
> Sent: Tuesday, July 12, 2005 8:51 AM
> To: users@myfaces.apache.org
> Subject: NullPointerException when trying to access bean values
> 
> 
> 
> Hi all,
> I am currently trying to retrieve some form-values using the normal way provided in the
documentation. But everytime I try to access these I get a nullpointerexception. Here is my
jsp file extract:
> <tr id="customer" class="visible">
>         <td align="right" style="height: 32px; width: 150px;"></f:verbatim>
>                 <h:panelGroup>
>                         <h:outputLabel value="#{bundle.searchCustomer}" for="customer"
/>
>         <f:verbatim></td>
>         <td style="width: 180px; height: 32px"></f:verbatim> <h:inputText
>                         id="customer" value="#{searchSpringBean.customer.cname}"
>                         valueChangeListener="#{searchSpringBean.valueChanged}"
>                         required="true">
>                         </h:inputText> <x:message for="customer" showDetail="true"
>                         showSummary="false" styleClass="error" /> </h:panelGroup>
<f:verbatim>
>         </td>
> </tr>
> 
> My managed beans looks like this:
> <managed-bean>
>                 <managed-bean-name>searchSpringBean</managed-bean-name>
>                 <managed-bean-class>
>                         itecon.web.controller.SearchHandler
>                 </managed-bean-class>
>                 <managed-bean-scope>request</managed-bean-scope>
> </managed-bean>
> 
> And the bean itself:
> public class SearchHandler extends BaseController implements Serializable {
> 
>         //TODO add a model Database.
>         private Customer customer = new Customer();
>         private System system;
>         private Systemerror systemerror;
>         private Employee employee = new Employee();
>         private List searchSystemtype;
> 
>         public String valueChanged(ValueChangeEvent event) {
>                 log.info(event.getComponent().getId());
>                 log.info(getCustomer().getCname().toString());
> 
>                 return "woscht";
>         }
> 
>         /**
>          * @return Returns the customer.
>          */
>         public Customer getCustomer() {
>                 return customer;
>         }
>         /**
>          * @param customer The customer to set.
>          */
>         public void setCustomer(Customer customer) {
>                 this.customer = customer;
>         }
> 
> }
> 
> Stacktrace:
> Caused by: java.lang.NullPointerException
>         at itecon.web.controller.SearchHandler.valueChanged(SearchHandler.java:39)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:138)
>         ... 44 more
> 
> Did I miss something? Is this the "best practise" way?
> 
> Thanks a lot for your help!
> 
> Regards Johannes
> __________________________________________________________
> Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
> weltweit telefonieren! http://freephone.web.de/?mc=021201
> 
>

Mime
View raw message