cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

jsp bean problem

Former Member
0 Likes
879

Hi all,

i have a problem with two jsp pages.

Each jsp page is made using "Create new portal application object."

They use bean to communicate.

In the first one is selected something from a listbox, and the second one have to show what has been selected.

This doesn't work. I mean, i select something, but it is not shown in the other jsp page.

There are located in a Portal page.

If someone can help me with advice? why this doesn't work.

I will give more information if necessary.

Thank you very much in advance.

BR

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Hi,

Make the scope of the bean as "request" and change your object creation of the bean in the java component accordingly. scope "application" will not work between two different components.Hope it helps!

Thanks,

Beevin

Answers (3)

Answers (3)

Former Member
0 Likes

Hi,

i am new on jsp , as u probably has realised

I found one pdf file here in the forum where very nice is described everything,

so maybe it will help me. I saw that there are some minor things, that weren't decribed in the other book, which i read before.

Thank you very much for your help.

Best regards

Diana

Former Member
0 Likes

hi, strange, i tested this yesterday, but it didn't work for me.

I will try again, to see if it will work this time. Maybe i haven't done something correct yesterday. That is why i thought that i am not doing it correct.

I will test the two variants and will write back here.

Thank you very much both of you for help.

Best regards.

Diana

Former Member
0 Likes

hi

still no result

BR

Diana

Former Member
0 Likes

Hi,

Is this not working with one portal component also?

Regards,

Pooja.

Former Member
0 Likes

hi,

not working with one portal component too.

I tried it.

hm, maybe i am missing something, but i executed the description very exact.

thank you

BR

Former Member
0 Likes

Hi,

Can you paste your code? Mayb its a prob with the code.

Regards,

Pooja.

Former Member
0 Likes

hi,

here is the code:

<b><u>listboxbean.java</u></b>

package Exercise4;
import java.io.Serializable;
import com.sapportals.htmlb.DefaultListModel;
public class listboxbean implements Serializable {

	public DefaultListModel model;
	public String selected;
	
	public DefaultListModel getModel() {
		return model;
	}
	public void setModel(DefaultListModel model) {
		this.model = model;
	}
//	   constructor
	public listboxbean() {
		this.model = new DefaultListModel();
		model.addItem("SAP R/3", "SAP R/3");
		model.addItem("SAP Portal", "SAP Portal");
		model.addItem("SAP BW", "SAP BW");
		this.model.setSingleSelection(true);
	}
}

<u><b>

listdisplay.java</b></u>


package Exercise4;

import Exercise4.listboxbean;
import com.sapportals.htmlb.*;
import com.sapportals.htmlb.enum.*;
import com.sapportals.htmlb.event.*;
import com.sapportals.htmlb.page.*;
import com.sapportals.portal.htmlb.page.*;
import com.sapportals.portal.prt.component.*;

public class listdisplay extends PageProcessorComponent {

  public DynPage getPage(){
    return new listdisplayDynPage();
  }

  public static class listdisplayDynPage extends JSPDynPage{
  
    public listboxbean myBeanName = null;
	private final static String BEAN_KEY = "myBeanName";
	private final static int INITIAL_STATE = 0;
	private final static int DISPLAY_SELECT = 1;
	private int state = INITIAL_STATE;
  
    public void doInitialization(){
		state = INITIAL_STATE;
	  	IPortalComponentContext ctxt = ((IPortalComponentRequest)getRequest()).getComponentContext();
	  Object o = ctxt.getValue(BEAN_KEY);
	  if(o==null || !(o instanceof listboxbean)){
	  myBeanName = new listboxbean();
	  ctxt.putValue(BEAN_KEY,myBeanName);
	  } else {
	  myBeanName = (listboxbean) o;
	  }
    }

    public void doProcessAfterInput() throws PageException {
		IPortalComponentContext ctxt =
		((IPortalComponentRequest)getRequest()).getComponentContext();
		myBeanName = (listboxbean) ctxt.getValue(BEAN_KEY);
		/* get the listbox by name. */
		ListBox lb = (ListBox) this.getComponentByName("SAP_Products");
		/* retrieve the selected item*/
		myBeanName.selected = lb.getSingleSelection();

    }

    public void doProcessBeforeOutput() throws PageException {
		switch (state) {
		  case INITIAL_STATE:
		     this.setJspName("listdisplay.jsp");
		     break;
		  case DISPLAY_SELECT:
		     this.setJspName("displayselect.jsp");
		     break;
		}
    }
    
	public void Select (Event event) throws PageException {
	/* Handles event from the listbox */
	state = DISPLAY_SELECT;
	}
  }
}

<u><b>listdisplay.jsp</b></u>
<%@ taglib uri= "tagLib" prefix="hbj" %>
<jsp:useBean id="myBeanName" scope="application" class="Exercise4.listboxbean" />
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
	<hbj:textView
		id="Products"
		text="SAP's software product"
		design="EMPHASIZED"
		/>
	<br>
	<hbj:listBox
		id="SAP_Products"
		tooltip="Select any SAP Products"
		size="3"
		width="100"
		model="myBeanName.model"
		onSelect="Select" >
	</hbj:listBox>
</hbj:form>
</hbj:page>
</hbj:content>

the page that display the slected from the previous page.

<u><b>displayselect.jsp</b></u>


<%@ taglib uri= "tagLib" prefix="hbj" %>
<jsp:useBean id="myBeanName" scope="application" class="Exercise4.listboxbean" />
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
<hbj:textView
	id="Products"
	text="You have selected:"
	design="EMPHASIZED"
	/>
<br>
<hbj:textView
	id="Products"
	text="<%=myBeanName.selected%>"
	design="EMPHASIZED"
	/>
<br>
</hbj:form>
</hbj:page>
</hbj:content>

And there is no code located for this jsp file in his java file

Thank you.

BR

Former Member
0 Likes

Hi,

I think its because you havent set state=DISPLAY_SELECT as the last line in your doProcessAfterInput() method. Try and see if it works.

Regards,

Pooja.

Former Member
0 Likes

hi, i tested it, but it doesn't work still.

The two jsp are in different iViews, is it possible this to be the reason?

thank you

Former Member
0 Likes

Hi,

Since you have created one portal component you'll need to create a single iview only. Try this and see if it works.

Regards,

Pooja.

Former Member
0 Likes

Hi,

Just a little correction of my explaination above:

there are 2 portal components in one par file.

BR

Diana

Former Member
0 Likes

Hi,

If you are using 2 iviews then you need to use portal eventing to pass data from one iview to another. Refer this link for more info:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/enterpris...

Why are you using 2 components? The easier way is to include both your jsp pages in a single portal component and create one iview out of it.

Regards,

Pooja.

Former Member
0 Likes

Hi,

I wanted to do just the second as u say: the two jsp files to be in one component, but for some reason, i couldn't do it?

I will ber gratefull if u can tell me, what the step are , so the two jsp files to be in one component?

BR

Diana

Former Member
0 Likes

Hi,

If you want only one component, then create a JSPDynPage application. You have option to include bean. A JSP file will be created in pagelet folder. To include another JSP file right click on pagelet folder and select New->Other->J2EE->Web->JSP File. If this doesnt work you can create a .jsp file in your system and copy paste it to your pagelet folder in NDS.

Hope this helps.

Regards,

Pooja.