0

i have a cascading dropdown which works fine on one system but fails to work on another system. pls refer to the code below: xhtml:

<p:selectOneMenu style="width: 150px" value="#{reportBean.exchange}">
                <f:selectItem itemLabel="NSE" itemValue="nse"/>
                <f:selectItem itemLabel="BSE" itemValue="bse"/> 
                <p:ajax update="sym" listener="#{reportBean.wow()}"/>
            </p:selectOneMenu>             
        <h:outputText value="Scrip Symbol :"/>
        <p:selectOneMenu value="#{reportBean.scripID}" id="sym" style="width: 100px">
            <f:selectItem itemLabel="All" itemValue="0"/>
            <f:selectItems var="scrip" value="#{reportBean.sl}" itemLabel="#{scrip.scripSymbol}" itemValue="#{scrip.scripID}"/>
        </p:selectOneMenu>

the wow() method is not called, following is the bean code:

 @javax.faces.bean.ManagedBean
@javax.faces.bean.ViewScoped
 public class reportBean implements Serializable {
    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
     transient  private StatelessWebService_Service  service ;
    private java.util.List<service.MasterScrip> getAllScripByExchange(java.lang.String exchange) {
        service.StatelessWebService port = service.getStatelessWebServicePort();
        return port.getAllScripByExchange(exchange);
    }
        public void wow()
    {    
            sl=getAllScripByExchange(exchange);
    }

i debugged and found that the debug point comes on the line

service.StatelessWebService port = service.getStatelessWebServicePort(); 

and goes into InvocationTargetException.java and goes tofollowing method:

public InvocationTargetException(Throwable target) {
super((Throwable)null);  // Disallow initCause
    this.target = target;
}

and finally in glassfish the error returned is:

    WARNING: /ClientTemplate/tradeReport.xhtml @17,74 listener="#{reportBean.wow()}": java.lang.NullPointerException
javax.el.ELException: /ClientTemplate/tradeReport.xhtml @17,74 listener="#{reportBean.wow()}": java.lang.NullPointerException

in managd bean if i dont implement serializable or if i dont make the service as transient, then i get NotSerializable exception. what is the cause of this error? how do i solve it? edited:

serviceBean:

    @ManagedBean
@javax.faces.bean.RequestScoped
public class serviceBean{
    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
    private StatelessWebService_Service service;
@ManagedProperty("#{reportBean}")
    private reportBean reportBean;

    public beans.reportBean getReportBean() {
        return reportBean;
    }

    public void setReportBean(beans.reportBean reportBean) {
        this.reportBean = reportBean;
    } //other props
    public String getExchange() {
        return exchange;
    }

    public void setExchange(String exchange) {
        this.exchange = exchange;
    }
     public void wow()
{    
        reportBean.setSl(getAllScripByExchange(reportBean.getExchange()));
}

reportBean:

  @javax.faces.bean.ManagedBean
@javax.faces.bean.ViewScoped
 public class reportBean implements Serializable {
     private Integer scripID;
     private String exchange;
     private List<service.TradeStock> tradeList;
     private List<MasterScrip> sl; //get set

now i get the following error:

 SEVERE: Error Rendering View[/ClientTemplate/tradeReport.xhtml]
javax.faces.FacesException: java.io.NotSerializableException: service.MasterScrip
z22
  • 10,013
  • 17
  • 70
  • 126

1 Answers1

0

Split the service call and action method into a different request scoped bean class. Keep the remaining in the view scoped bean. Finally inject the view scoped one in the request scoped one by @ManagedProperty.

@ManagedBean
@RequestScoped
public class ReportActionBean {

    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
    private StatelessWebService_Service service;

    @ManagedProperty("#{reportDataBean}")
    private ReportDataBean reportDataBean;

    // ...
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • so where do i write the wow() method? in my current code, i am calling the service method in the wow() method(see it in the code) – z22 Jun 03 '12 at 13:21
  • The `wow()` method is the action method as mentioned in my answer, so put it in the request scoped bean. – BalusC Jun 03 '12 at 13:23
  • so are you saying that my viewScoped bean should contain only getter and setter? – z22 Jun 03 '12 at 13:27
  • Uh, no only the properties which needs to be stored in the view scope (along with the obvious getters/setters yes). Such as `exchange` and `scripID` in your code. I'm not sure where `sl` comes from, but if it comes from the web service, put it in the request scoped one. – BalusC Jun 03 '12 at 13:28
  • By the way, if the webservice returns the same data everytime and rarely changes, you might want to consider storing it in an application scoped bean instead and eventually introduce a scheduler which reloads it midnight or so. – BalusC Jun 03 '12 at 13:29
  • i made the following changes, now i get the error shown in my edited code. pls referto the edited question. – z22 Jun 03 '12 at 14:24
  • Just let the model classes implement `Serializable` as well. – BalusC Jun 03 '12 at 15:58