Skip to Content
0
Former Member
Feb 18, 2009 at 10:59 PM

Get logged user in PAR JSPDynPage with session bean

116 Views

Hi! I've an iView linked to a role. This iView is from a PAR, which contains a JSPDynPro and a bean. I'm trying to get the logged user to display it on the page, but every time I just get nulls. This is my code:

Bean

package com.myenterprise.portal;

import java.io.Serializable;


public class frijolito implements Serializable {
	private String uid = null;
	private String uniqueid = null;
	private String ncomponentes = null;

	public void setUid(String s) {
		uid = s;
	}

	public void setUniqueid(String s) {
		uniqueid = s;
	}
	
	public String getUid(){
		return uid;
	}
	
	public String getUniqueid(){
		return uniqueid;
	}
	
	public void setNcomponentes(String s){
		ncomponentes = s;
	}
	
	public String getNcomponentes(){
		return ncomponentes;
	}
	
}

The jsp:


<jsp:useBean id="myBean" scope="session" class="com.myenterprise.portal.frijolito" />
<hbj:content id="myContext" >
  <hbj:page title="PageTitle">
   <hbj:form id="myFormId" >
	<%="El usuarios: " + myBean.getUid() + " - unique: " + myBean.getUniqueid()%>
   </hbj:form>
  </hbj:page>
</hbj:content>

And finally, the java code for the jsp (in src.core)

import com.myenterprise.portal.frijolito;
import com.sapportals.htmlb.page.DynPage;
import com.sapportals.htmlb.page.PageException;
import com.sapportals.portal.htmlb.page.JSPDynPage;
import com.sapportals.portal.htmlb.page.PageProcessorComponent;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.session.IUserContext;

public class TestUsuarios extends PageProcessorComponent {

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

	public static class TestUsuariosDynPage extends JSPDynPage {

		public void doInitialization() {
			
			

		}

		public void doProcessAfterInput() throws PageException {
		}

		public void doProcessBeforeOutput() throws PageException {

                         frijolito myBean = new frijolito();
			((IPortalComponentRequest) getRequest())
				.getServletRequest()
				.setAttribute(
				"myBean",
				myBean);
			// fill your bean with data here...
			IPortalComponentRequest req =
				(IPortalComponentRequest) getRequest();

			IUserContext iu = req.getUser();

			if (iu == null)
				myBean.setUniqueid("El iu es nulo<br>");
			else {
				if (iu.getLogonUid() == null)
					myBean.setUniqueid("El iu getLogonUid es nulo<br>");
				else
					myBean.setUniqueid(iu.getLogonUid() + "<br>");
			}
			myBean.setUid("PRUEBA UID");

			this.setJspName("testusuarios.jsp");
		}
	}
}

When I see the page (with preview or from the user menu where the iview is linked) I always get "El usuarios: null - unique: null"

It appears that I'm not initializing and/or using properly the bean, because as you can see, one property of the bean is initialized with some text, but that text is not shown in the jsp.

Also, I don't know if that is the correct way for getting the logged user, since my bean is not working, I can't test this.

What am I doing wrong?

Thanks a lot!