cancel
Showing results for 
Search instead for 
Did you mean: 

JSP Error:non-static method getBukrs() cannot be referenced from a static c

Former Member
0 Kudos

HI All,

Im building a JSPDynpage that calls a RFC and renders data on a JSP. When I deploy my PAR on the portal server and run my application, it throws the following error.



Caused by: com.sapportals.portal.prt.servlets_jsp.server.compiler.CompilingException: /usr/sap/PSA/JC40/j2ee/cluster/server0/apps/sap.com/irj/servlet_jsp/irj/root/WEB-INF/portal/portalapps/NewJcoTest/work/pagelet/_sapportalsjsp_JcoJsp.java:201: *non-static method getBukrs() cannot be referenced from a static context*
*			tv03.setText(class44bean.getBukrs());	*		
                                                ^
1 error

This is my JSP :



<%@ taglib uri="tagLib" prefix="hbj" %>
<%@ page import="com.sapportals.htmlb.*" %>
<%@ page import="com.sapportals.htmlb.enum.*" %>
<%@ page import="com.xxx.class44bean" %>
<%@ page import="com.sapportals.htmlb.htmlcontainer.*"%>
<%@ page import="com.sapportals.portal.prt.resource.IResource"  %>
<jsp:useBean id="myBean" scope="session" class="com.xxx.class44bean" />

<hbj:content 
id="myContext">

<hbj:page 
title="PageTitle">

<hbj:form 
id="myFormId">

<%
			FormLayout f01 = new FormLayout();
			myFormId.addComponent(f01);
			f01.setWidth("600px");
			f01.setDebugMode(false);
			
			FormLayoutRow row01 = f01.addRow();
			row01.setPaddingTop("10px");
			row01.setPaddingBottom("5px");
			
        	                                TextView tv01 = new TextView ("tv01");
			tv01.setEncode(false);
			tv01.setText("<font size=\"+1\"><b>Cmmon Man....</b></font>");
			
			
			TextView tv02 = new TextView ("tv02");
			tv02.setEncode(false);
			tv02.setText("<font size=\"+1\"><b>Now Show up</b></font>");			
			

			TextView tv03 = new TextView ("tv03");
			tv03.setEncode(false);
			tv03.setText(class44bean.getBukrs());			
			

			TextView tv04 = new TextView ("tv04");
			tv04.setEncode(false);
			tv04.setText("<font size=\"+1\"><b>Now Show up</b></font>");			
			
			
			
			
			FormLayoutCell cell01 = f01.addComponent(1,1, tv01);
			cell01.setHorizontalAlignment(CellHAlign.LEFT);
			cell01.setPaddingLeft("5px");
			FormLayoutCell cell02 = f01.addComponent(1,2, tv02);
			cell02.setHorizontalAlignment(CellHAlign.RIGHT);
			cell02.setPaddingLeft("5px");
			
%>

this is a test
</hbj:form>
</hbj:page>
</hbj:content>


This is my Bean


package com.xxx;
import com.sapportals.htmlb.table.DefaultTableViewModel;

import java.io.Serializable;

public class class44bean implements Serializable {

public DefaultTableViewModel model;
public String fieldName;
public String fieldValue;

public String bukrs;
public String belnr;
public String gjahr;
public String blart;
public String bldat;

public DefaultTableViewModel getModel() {
return model;
}


public void setModel(DefaultTableViewModel model) {
//this.model = model;
}

	/**
	 * @return
	 */
	public String getFieldName() {
		return fieldName;
	}

	/**
	 * @return
	 */
	public String getFieldValue() {
		return fieldValue;
	}

	/**
	 * @param string
	 */
	public void setFieldName(String string) {
		fieldName = string;
	}

	/**
	 * @param string
	 */
	public void setFieldValue(String string) {
		fieldValue = string;
	}

/**
 * @return
 */
public String getBelnr() {
	return belnr;
}

/**
 * @return
 */
public String getBlart() {
	return blart;
}

/**
 * @return
 */
public String getBldat() {
	return bldat;
}

/**
 * @return
 */
public String getBukrs() {
	return bukrs;
}

/**
 * @return
 */
public String getGjahr() {
	return gjahr;
}

/**
 * @param string
 */
public void setBelnr(String string) {
	belnr = string;
}

/**
 * @param string
 */
public void setBlart(String string) {
	blart = string;
}

/**
 * @param string
 */
public void setBldat(String string) {
	bldat = string;
}

/**
 * @param string
 */
public void setBukrs(String string) {
	bukrs = string;
}

/**
 * @param string
 */
public void setGjahr(String string) {
	gjahr = string;
}

}


Now in my bean if I make my variable BUKRS and the method getBukrs() as STATIC the error goes off. But thats not the way it should be done.

Any Ideas ?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi S.B,

In Your JSP page replace line

tv03.setText(class44bean.getBukrs());

by

tv03.setText(myBean.getBukrs());

where myBean is the object name of ur class(i.e Bean)

Regards,

Yogesh

Former Member
0 Kudos

Hi Yogesh,

Thanks, It does not give that error anymore. But the problem now is that it doesnt fetch data from the backend system. I mean the screen is loaded without any erors but its blank.

Any suggestions?

Former Member
0 Kudos

Hi S.B,

a few more suggestions:

1) Make the variables as private and not public, in your bean class.

2) Try using <jsp:getProperty name="myBean" property="bukrs" />

3) Your JSP page shows that Textview tv03 and tv04 are not added to

the form. Add them.

4) OR You can also try to use TextView tv03 = getTextView(msg);

where msg = myBean.getBukrs(); And then add this tv03 to the

form.

Let me know if any of these or their combination work for you.

Thanks,

Yogesh...

Former Member
0 Kudos

Hi Yogesh,

Herez what I get,

1) changed the variables to private and from public, in bean class -- No change

2) Try using <jsp:getProperty name="myBean" property="bukrs" />

3) Your JSP page shows that Textview tv03 and tv04 are not added to

the form. Add them. --- Added them, no change.

4) OR You can also try to use TextView tv03 = getTextView(msg);

where msg = myBean.getBukrs(); And then add this tv03 to the

form.--- did this, get the following error

Caused by: com.sapportals.portal.prt.servlets_jsp.server.compiler.CompilingException: /usr/sap/PSA/JC40/j2ee/cluster/server0/apps/sap.com/irj/servlet_jsp/irj/root/web-inf/portal/portalapps/newjcotest/work/pagelet/_sapportalsjsp_jcojsp.java:201: getText() in com.sapportals.htmlb.TextView cannot be applied to (java.lang.String)

tv03.getText(myBean.getName());

^

I think im messing up on the session somewhere. Any Ideas?

Former Member
0 Kudos

Hi Yogesh,

would you like to tale a look at the par ?

Former Member
0 Kudos

Instead of



tv03.setText(myBean.getName());	

If I give this :



tv03.setText(class44bean.getName());

and change the functions setName() /getName() and the variable "name" as Static then the value is displayed on the JSP.

But that should not be the way it should behave.

But if I do not do the above, the bean object is not being stored in the session and the JSP is not able to refer it. It shows a "Null" on the JSP without any error while rendering.

Any Ideas experts?