You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Johannes Hiemer <jh...@web.de> on 2005/07/12 14:51:08 UTC
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
Re: NullPointerException when trying to access bean values
Posted by Bruno Aranda <br...@gmail.com>.
Hi Johannes,
Have you included the surrounding <h:form> tags? This is a common
mistake. Can you post the code of the h:commandLink or h:commandButton
used to submit the form?
Moreover, the valueChange method should be 'void' (althought I think
this won't be the cause of the exception). Finally, it is more
recommendable to use h:panelGrid and css styles instead of direct HTML
code....
Regards,
Bruno
2005/7/12, Johannes Hiemer <jh...@web.de>:
>
> 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
>
>