You are on page 1of 2

The JSP Bean class below called “Resobean” was developed and written by Mr.Samuel A.

Marchant of

www.nicephotog-jvm.net nicephotog@www.nicephotog-jvm.net late April 2006.

Below is the source code for a JSP Java-Bean I wrote to assist element construction relating to HTML GUI elements

During page loading.

1. The class file sits in a JSP Server type-: JSP2.0 Web Application container in a directory called “guicontrols”

inside the container deault package directory “classes”.

2. The Bean is called from a jsp page by a <jsp:setProperty> element after the <jsp:useBean> element sets

the Bean active.

3. The Calculation parts for the co-efficient are set by a <jsp:setProperty> by taking a page parameter on

page loading from the url address as with CGI “method=GET” system. The parameter value must be

previously appended to the entry url link by a javascript using window.screen.width().

4. The calls for the element width or height are done inside the HTML elements by JSP EL(Expression

Language) e.g.

<jsp:useBean id="resobean" class="guicontrols.Resobean" scope="session"/>

<jsp:setProperty name="resobean" property="resol" value="1600"/><%-- resolution test value only --%>

<jsp:setProperty name="resobean" property="widthElm" value="500"/>

<jsp:setProperty name="resobean" property="heightElm" value="400"/>

<td width="${resobean.widthElm}" height="${resobean.widthElm}"> ……

====== Resobean.java source code Below (tested in a Tomcat5.0) [modified] =======

===

package guicontrols;

public class Resobean{

protected java.lang.String wstres,hstres,susrs;

public Resobean(){

this.susrs="1024"; // initval, fed screen resolution url? param

this.wstres="100"; // initval, for the assigned standard width at 1024

this.hstres="100" ; // initval, for the assigned standard height at 1024

} //enconstrct NOTE: screen width determines the resizing set this at begining of page (resolution co-eff denominator)

public void setResol(java.lang.String susrs){this.susrs=susrs;} //enset

public void setHeightElm(java.lang.String hstres){

this.hstres=hstres; //calcs moved to set for consistency

float fEmVal=(float)new java.lang.Float(hstres).floatValue();

fEmVal*=makeCoeff(susrs);

this.hstres=(java.lang.String)new java.lang.Integer(((int)new java.lang.Float(fEmVal).intValue())).toString();


} //enset

public void setWidthElm(java.lang.String wstres){

this.wstres=wstres; //calcs moved to set for consistency

float wEmVal=(float)new java.lang.Float(wstres).floatValue();

wEmVal*=makeCoeff(susrs);

this.wstres=(java.lang.String)new java.lang.Integer(((int)new java.lang.Float(wEmVal).intValue())).toString();

} //enset

public java.lang.String getResol(){

return this.susrs;

}//enget

public java.lang.String getHeightElm(){

return this.hstres;

}//enget

public java.lang.String getWidthElm(){

return this.wstres;

}//enget

public float makeCoeff(java.lang.String nusrs){

float a=1599.0000F;

float b=1279.0000F;

float c=1151.0000F;

float busrs=(float)new java.lang.Float(nusrs).floatValue();

float usrs=0.0000F;

if(busrs>a){

usrs=1600.0000F/1024.0000F;

}else if(busrs>b){

usrs=1280.0000F/1024.0000F;

}else if(busrs>c){

usrs=1152.0000F/1024.0000F;

}else{

usrs=1024.0000F/1024.0000F; // for completeness and less thought about java.lang.nullpointerexception 's

} //enifels

return usrs;

} //enmke

} //enclss

You might also like