Access backing bean variables from JSP directly
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   SVGK_Raju
Posted On:   Sunday, March 30, 2008 09:39 AM

Find Record Hi, I need to access backing bean variables directly from the JSP. Not able to figure out how to do it. I created a Hashtable (details) and String[] (header) variables in the backing bean and initialized both in the corresponding backing bean constructor. Now I want to access those two variables from the JSP and apply some logic to format them properly. How can I do it? Backing bean code package com.itools.vs.view.backing.General; import com.itools.vs.model.exception.UnknownException; import com.itools.vs.model.exception.WarningException; import com.itools.vs.model.session.DefaultSession; import com.itools.vs.model.util.CatalogH   More>>
Find Record

Hi,
I need to access backing bean variables directly from the JSP. Not able to figure out how to do it.

I created a Hashtable (details) and String[] (header) variables in the backing bean and initialized both in the corresponding backing bean constructor. Now I want to access those two variables from the JSP and apply some logic to format them properly. How can I do it?

Backing bean code

			
				
package com.itools.vs.view.backing.General;

import com.itools.vs.model.exception.UnknownException;
import com.itools.vs.model.exception.WarningException;
import com.itools.vs.model.session.DefaultSession;
import com.itools.vs.model.util.CatalogHelper;
import com.itools.vs.view.exception.ViewException;

import com.itools.vs.view.util.ViewUtil;

import java.util.Hashtable;

import javax.faces.component.html.HtmlForm;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Find {
private HtmlForm recordFound;

private DefaultSession ds = null;
private HttpSession session = null;
private Hashtable details;
private String[] header;

public Find() throws ViewException {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) context.getRequest();
session = request.getSession(true);
ds = (DefaultSession)session.getAttribute("DefaultSession");
if (ds == null) {
ViewUtil.addMessage("", "Fatal", "login.jsp", "_top");
throw new ViewException (new CatalogHelper("ITOOLS_900026"));
}
String recid = request.getParameter("top:recordid");
Long recordid;
try {
recordid = new Long(recid);
} catch (NumberFormatException nfe) {
throw new ViewException (new CatalogHelper("ITOLLS_900028", recid));
}
String rectype = request.getParameter("top:selectRecord");

String fields[];
if (rectype.equalsIgnoreCase("user")) {
fields = new String[5];
header = new String[5];
fields[0] = "iuser__userid";
header[0] = "User id";
fields[1] = "iuser__userhandle";
header[1] = "Handle";
fields[2] = "iuser__userfname";
header[2] = "First name";
fields[3] = "iuser__userlname";
header[3] = "Last name";
fields[4] = "iuser__supervisor";
header[4] = "Supervisor";
try {
details = ds.getIuserDetails(recordid, fields);
} catch (WarningException we) {
throw new ViewException (we.getCatalogHelper());
} catch (UnknownException ue) {
throw new ViewException (ue.getCatalogHelper());
} catch (Exception ex) {
throw new ViewException (new CatalogHelper("ITOOLS_900025", new Object[]{"user details", ex.getMessage()}));
}
} else if (rectype.equalsIgnoreCase("product")) {
fields = new String[3];
header = new String[3];
fields[0] = "iproduct__productid";
header[0] = "Product id";
fields[1] = "iproduct__productname";
header[1] = "Product name";
fields[2] = "iproduct__isactive";
header[2] = "Is active?";
try {
details = ds.getIproductDetails(recordid, fields);
} catch (WarningException we) {
throw new ViewException (we.getCatalogHelper());
} catch (UnknownException ue) {
throw new ViewException (ue.getCatalogHelper());
} catch (Exception ex) {
throw new ViewException (new CatalogHelper("ITOOLS_900025", new Object[]{"product details", ex.getMessage()}));
}
} else {

}
}

public void setRecordFound(HtmlForm recordFound) {
this.recordFound = recordFound;
}

public HtmlForm getRecordFound() {
return recordFound;
}

public Hashtable getDetails() {
return details;
}

public void setDetails(Hashtable details) {
this.details = details;
}

public String[] getHeader() {
return header;
}

public void setHeader(String[] header) {
this.header = header;
}
}



find.jsp JSP code:

			
				

<%@ page contentType="text/html;charset=windows-1252" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<%
// details variable from the backing bean will be stored in itemDetails
Hashtable itemDetails;
Enumeration env = itemDetails.keys();
..................
%>




content="text/html; charset=windows-1252"/>












faces-config.xml

			
				

backing_General_top
com.itools.vs.view.backing.General.Top
session

   <<Less
About | Sitemap | Contact