SUBMIT button and VALUE clause

I have a jsp screen like below.It shows in a tabular form all the employee data.

--

EMPLOYEE DETAILS

EmpId_ProcessEmpSalary__ProcessEmpLeave

1

2

3

4

5

6

7

8

NEXTPREV_LAST_FIRST

Under ProcessEmpSalary ,ProcessEmpLeave of each employee I have a submit button and clicking on it the particular employee id has to be processed (for salary or leave).Now I want the employee id to be passed when the submit button of that particular employee is pressed.

So what I am doing is I put the emp id in the value clause and achieve my purpose.But this results in the display of the emp id over each submit button.It looks ugly and so

I dont want to use the VALUE clause of the SUBMIT button.........

So friends please tell me how to achieve it.Someone suggested me to use IMAGE but it doesn't work.Some suggested I use hidden varaible ,but I just don;t understand how is that possible.Some suggested me use javascript to pass the value and throw the form...this make sense but problem is I don't have time to learn javascript now.So please help with some code example how to achieve this result.

[1191 byte] By [manohar2a] at [2007-9-19]
# 1
If you are asking how to write your HTML, which is what it looks like to me, you could use a hidden field.
DrClapa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2

You use a hidden field to pass, for example, the current record number.

Then you use some logic to figure out the appropriate recordset window.

E.g. (assuming you have 10 records in your window)

recNum = request.getParameter("currRecNum");

if (request.getParameter("submit").equals("Next")) {

recNum += 10;

}

if (request.getParameter("submit").equals("Prev")) {

recNum -= 10;

}

Then display all records in the range [ recNum ... recNum + 10 ]

a_developera at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3

But then how will I know wether the button pressed was ProcessEmpSalary or ProcessEmpLeave.

(Remember for each employee two SUBMIT buttons are there, one for Processing emp salary and another for leave.)

That was the reason I said earlier that hidden variable can't be used in this case.Please correct me if I am wrong.

manohar2a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4

A hidden value is exactly what you need, along with a programmatic submit.

<SCRIPT>

function doSubmit(val){

document.all.val_hidden.value=val;

document.FORM_NAME.submit();

}

</SCRIPT>

...

<INPUT TYPE=BUTTON onclick="doSubmit('1');">

<INPUT TYPE=HIDDEN NAME="val_hidden" VALUE="">

cafala at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5

Do not use submit, use button; I assume you use html form named mainForm, and the page that is being called when the button is pressed is ProcessingPage.jsp. Replace you submits with the following code:

<input type="button" onClick="mainForm.action='ProcessingPage.jsp@submitType=EmpSalary&id=<_25=employeeID_25>';mainForm.submit();">

submitType should be set at EmpSalary or EmpLeave depending on the column the button is in.

In the ProcessingPage.jsp just use

String submitType = request.getAttribute("submitType ");

Sting id = request.getAttribute("id");

Now you know the employee ID as well as type of the button that was pressed...

It's JavaScript, I don't see a way around it...

Hope this helps

deniskeza at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6

I am actually lost.May be because I don't know javascript.Second let me show u what I am doing now.In the FORM ACTION clause of my Employee.jsp I call the same Employee.jsp

Employee.jsp

-

<FORM ACTION = 'Employee.jsp' method='post'>

<%

.

.

.

.

if (request.getParameter("ProcessSalary") != null )

{

Emp_Id= request.getParameter("ProcessSalary");

SomeEmpObject.ProcessEmpSalary(Emp_Id);

}

else

if (request.getParameter("ProcessLeave") != null )

{

Emp_Id= request.getParameter("ProcessLeave");

SomeEmpObject.ProcessEmpLeave(Emp_Id);

}

...

.

.

.

%>

Now taking into consideration my requirement can some one please help me out.

Even if some one can tell me how to set a java variable to the employee id thru javascript.

I mean is there anything like ONCLICK=........set a java variable to emp id.

manohar2a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 7

> But then how will I know wether the button pressed was

> ProcessEmpSalary or ProcessEmpLeave.

> (Remember for each employee two SUBMIT buttons are

> there, one for Processing emp salary and another for

> leave.)

>

>

>

> That was the reason I said earlier that hidden

> variable can't be used in this case.Please correct me

> if I am wrong.

>

Give the buttons names: <INPUT TYPE="submit" VALUE="Process Salary" NAME="Salary">

Then the name of the button that was clicked will be passed as a parameter. Something like Salary=Salary, but I don't recall exactly.

DrClapa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 8
Can you show your code for sumbit button generation. I am assuming you are creating them dynamically. If you show me the code I can show how to change it exactly...
deniskeza at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 9

I also developed a similar kind of page in which a lost of all Orders is shown & 2 buttons, View Details & Delete/ Cancel button were there . On Click of "View Details" Button i'd to trcak for which Order it was being Pressed. I used JSP for this with EJB's ie All Product Details were coming from EJB in HashMap/ HashTable.

I guess ur requirements is simliar to it. If that's so, do mail me at smart_women@rediffmail.com. I'll defintely help u out on this.

preeti_ka at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 10

Here is my jsp as it is .Employee id was used for example.In my application it is Submission_Id

which is used as the key.

Note:

The method is given below after the end of this JSP code.

SubmissionList.jsp

<%@ page contentType="text/html;charset=WINDOWS-1252"%>

<%@page import = "oracle.portal.provider.v1.*, oracle.portal.provider.v1.http.*, oracle.portal.utils.v1.*, java.sql.*, ccrspackage.*" %>

<HTML>

<HEAD>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=WINDOWS-1252">

<META NAME="GENERATOR" CONTENT="Oracle JDeveloper">

<TITLE>

</TITLE>

</HEAD>

<BODY BGCOLOR = #FFCC00 FONT SIZE = "+2" >

<FORM ACTION = 'SubmissionList.jsp' method='post'>

<%

//retrieve the existing session

HttpSession Session= request.getSession(true);

CCRS OCCRS = null;

ConnectOConnect= null;

try

{

if (request.getMethod().equals("POST"))

{

if ( request.getParameter("Exit") != null)

{

response.sendRedirect("Default.jsp");

}

else

{

OCCRS= (CCRS)Session.getValue("OCCRS");

if (request.getParameter("Search") != null)

{

OCCRS.InitialSettingForSubmissionList();

}

else

{

OCCRS.CreatePageOfSubmissionList(request);

}

}

}

else

{

OConnect = (Connect)Session.getValue("OConnect");

OCCRS = new CCRS(OConnect);

OCCRS.InitialSettingForSubmissionList();

}

Session.putValue("OCCRS",OCCRS);

}

catch (Exception e)

{

OCCRS.ProcessError(e);

}

//MESSAGE (IF ANY)

out.println("<TABLE ALIGN=CENTER>");

out.println("<TR>");

out.println("<TD>");

out.println("<FONT COLOR = RED>");

out.println("<B>");

out.println(OCCRS.GetDisplayMessage());

out.println("</B>");

out.println("</FONT>");

out.println("</TD>");

out.println("</TR>");

out.println("</TABLE>");

if (OCCRS.GetShowRecord() == false)

{

String TempValue= "";

String TempSelected= "";

String TempText= "";

out.println("<TABLE ALIGN=CENTER>");

//Show all the drop down list

out.println("<TR>");

out.println("<TD>");

out.println("<FONT COLOR = BLACK>");

out.println("<B>");

out.println("Fiscal Year");

out.println("</B>");

out.println("</FONT>");

out.println("</TD>");

out.println("<TD>");

out.println("<SELECT name = 'Fiscal_Year' >");

while (OCCRS.NextItrScrFiscal_Year())

{

TempValue= OCCRS.GetItrScrFiscal_Year();

TempSelected= OCCRS.GetItrSelectedScrFiscal_Year();

out.println("<OPTION value = '" + TempValue + "' " + TempSelected + " >" + TempValue + "</OPTION>");

}

out.println("</SELECT>");

out.println("</TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>");

out.println("<FONT COLOR = BLACK>");

out.println("<B>");

out.println("Fiscal Period");

out.println("</B>");

out.println("</FONT>");

out.println("</TD>");

out.println("<TD>");

out.println("<SELECT name = 'Fiscal_Period' >");

while (OCCRS.NextItrScrFiscal_Period())

{

TempValue= OCCRS.GetItrScrFiscal_Period();

TempSelected= OCCRS.GetItrSelectedScrFiscal_Period();

out.println("<OPTION value = '" + TempValue + "' " + TempSelected + " >" + TempValue + "</OPTION>");

}

out.println("</SELECT>");

out.println("</TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>");

out.println("<FONT COLOR = BLACK>");

out.println("<B>");

out.println("Province");

out.println("</B>");

out.println("</FONT>");

out.println("</TD>");

out.println("<TD>");

out.println("<SELECT name = 'Province_Code' >");

while (OCCRS.NextItrScrProvince_Code())

{

TempValue= OCCRS.GetItrScrProvince_Code();

TempSelected= OCCRS.GetItrSelectedScrProvince_Code();

TempText= OCCRS.GetItrScrProvince_Desc();

out.println("<OPTION value = '" + TempValue + "' " + TempSelected + " >" + TempText + "</OPTION>");

}

out.println("</SELECT>");

out.println("</TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>");

out.println("<FONT COLOR = BLACK>");

out.println("<B>");

out.println("Facility");

out.println("</B>");

out.println("</FONT>");

out.println("</TD>");

out.println("<TD>");

out.println("<SELECT name = 'Facility_Code' >");

while (OCCRS.NextItrScrFacility_Code())

{

TempValue= OCCRS.GetItrScrFacility_Code();

TempSelected= OCCRS.GetItrSelectedScrFacility_Code();

TempText= OCCRS.GetItrScrFacility_Name();

out.println("<OPTION value = '" + TempValue + "' " + TempSelected + " >" + TempText + " " + TempValue + "</OPTION>");

}

out.println("</SELECT>");

out.println("</TD>");

out.println("</TR>");

out.println("<TR>");

out.println("<TD>");

out.println("<FONT COLOR = BLACK>");

out.println("<B>");

out.println("Status Code");

out.println("</B>");

out.println("</FONT>");

out.println("</TD>");

out.println("<TD>");

out.println("<SELECT name = 'Status_Code' >");

while (OCCRS.NextItrScrStatus_Code())

{

TempValue= OCCRS.GetItrScrStatus_Code();

TempSelected= OCCRS.GetItrSelectedScrStatus_Code();

TempText= OCCRS.GetItrScrStatusDesc();

out.println("<OPTION value = '" + TempValue + "' " + TempSelected + " >" + TempText + "</OPTION>");

}

out.println("</SELECT>");

out.println("</TD>");

out.println("</TR>");

out.println("</TABLE>");

// SHOW 2 SUBMIT BUTTONS ,"Next" and "Close"

out.println("<TABLE ALIGN = 'CENTER'>");

out.println("<TR>");

out.println("<TD ALIGN=CENTER>");

out.println("<INPUT TYPE = 'SUBMIT' NAME = 'ShowRecord' value ='ShowRecord'>");

out.println("</INPUT>");

out.println("</TD>");

out.println("<TD>");

out.println("<INPUT TYPE = 'Submit' NAME = 'Exit' value ='Exit'>");

out.println("</INPUT>");

out.println("</TD>");

out.println("</TR>");

out.println("</TABLE>");

}

else

{

out.println("<TABLE ALIGN=CENTER>");

//THE COLUMN NAME IS SHOWN

for(int Row = 0;Row <= OCCRS.GetFilledRow();Row++)

{

if (Row == 0)

{

out.println("<TR BGCOLOR = 'Black' >");

}

else

{

out.println("<TR BGCOLOR = 'Teal' >");

}

for(int Col = 0;Col <= OCCRS.GetFilledCol();Col++)

{

out.println("<TD>");

out.println("<B>");

out.println("<FONT COLOR = WHITE >");

out.println(OCCRS.ReturnNewPageElement(Row,Col));

out.println("</FONT>");

out.println("</B>");

out.println("</TD>");

}

out.println("</TR >");

}

out.println("</TABLE>");

out.println("<TABLE ALIGN = 'CENTER'>");

out.println("<TR>");

if (OCCRS.GetMoreRecExist())

{

out.println("<TD>");

out.println("<INPUT TYPE = 'Submit' NAME = 'Next' value ='Next'>");

out.println("</INPUT>");

out.println("</TD>");

}

if (OCCRS.GetPageNumber() > 0)

{

out.println("<TD>");

out.println("<INPUT TYPE = 'Submit' NAME = 'Prev' value ='Prev'>");

out.println("</INPUT>");

out.println("</TD>");

out.println("<TD>");

out.println("<INPUT TYPE = 'Submit' NAME = 'First' value ='First'>");

out.println("</INPUT>");

out.println("</TD>");

}

out.println("<TD>");

out.println("<INPUT TYPE = 'Submit' NAME = 'Search' value ='Search'>");

out.println("</INPUT>");

out.println("</TD>");

out.println("<TD>");

out.println("<INPUT TYPE = 'Submit' NAME = 'Exit' value = 'Exit'>");

out.println("</INPUT>");

out.println("</TD>");

out.println("</TR>");

out.println("</TABLE>");

}

%>

</FORM>

</BODY>

</HTML>

Here is my method in CCRS class

/*

This method create a multidimensional array of fixed row

and column .This array is populated with all the data that has to

be displayed ,and also satisfies the condition specified by the user.

This array is subsequently used in the JSP (which calls this method)

and displays all the row.

*/

publicvoidCreatePageOfSubmissionList(HttpServletRequest request) throws Exception

{

ResultSet ResSet;

ShowRecord = true;

DisplayMessage = "";

if (request.getParameter("ShowRecord") != null )

{

ScrProvince_Code= request.getParameter("Province_Code").trim();

ScrFacility_Code= request.getParameter("Facility_Code").trim();

ScrFiscal_Year = request.getParameter("Fiscal_Year").trim();

ScrFiscal_Period= request.getParameter("Fiscal_Period").trim();

ScrStatus_Code = request.getParameter("Status_Code").trim();

LastSubmission_Id= 999999999;

MathematicalSign= "<";

}

else

if (request.getParameter("Release") != null )

{

ScrSubmission_Id= request.getParameter("Release").trim();

Submission_Id= ScrSubmission_Id;

ReleaseSubmission();

LastSubmission_Id =FirstSubmission_Id;

MathematicalSign= "<=";

}

else

if (request.getParameter("Process") != null )

{

ScrSubmission_Id= request.getParameter("Process").trim();

Submission_Id= ScrSubmission_Id;

ProcessSubmission();

LastSubmission_Id =FirstSubmission_Id;

MathematicalSign= "<=";

}

else

if (request.getParameter("Remove") != null )

{

ScrSubmission_Id = request.getParameter("Remove").trim();

Submission_Id= ScrSubmission_Id;

RemoveSubmission();

LastSubmission_Id=FirstSubmission_Id;

MathematicalSign = "<=";

}

else

if (request.getParameter("Prev") != null )

{

PageNumber = PageNumber - 1;

Long Temp = (Long) VecPrevSubmission_Id.elementAt(PageNumber);

LastSubmission_Id = Temp.longValue();

MathematicalSign = "<=";

}

else

if (request.getParameter("First") != null )

{

Long Temp = (Long) VecPrevSubmission_Id.elementAt(0);

LastSubmission_Id = Temp.longValue();

PageNumber = 0;

MathematicalSign = "<=";

}

else

if (request.getParameter("Next") != null )

{

PageNumber = PageNumber + 1;

VecPrevSubmission_Id.addElement(new Long(FirstSubmission_Id));

MathematicalSign = "<";

}

//initialize the page array

for(int Row = 0;Row <= MaxPageRow;Row++)

{

for(int Col = 0; Col <= MaxPageCol;Col++)

{

NewPage[Row][Col]= "";

}

}

Submission_Id = LastSubmission_Id + "";

Province_Code = ScrProvince_Code;

Facility_Code = ScrFacility_Code;

Fiscal_Year= ScrFiscal_Year;

Fiscal_Period = ScrFiscal_Period;

Status_Code= ScrStatus_Code;

BuildQueryForSubmissionList();

ResSet =Stmt.executeQuery (Query);

ResSetMetaData =ResSet.getMetaData();

//remember NumOfFields is O is java variable which starts with 0 and not 1,

//that is the reason I am subtracting 1 from oracle returned value.

int NumOfFields=ResSetMetaData.getColumnCount() - 1;

FilledCol = -1;

for(int Col = 0; Col <= NumOfFields;Col++)

{

//1 is added because JDBC subscripts starts with 1 and not 0

NewPage[0][Col] = ReturnChangedColumnName(Col + 1,ResSetMetaData);

FilledCol = FilledCol + 1;

}

FilledCol = FilledCol + 1;

NewPage[0][FilledCol] = "Remove";

FilledCol = FilledCol + 1;

NewPage[0][FilledCol] = "Process";

FilledCol = FilledCol + 1;

NewPage[0][FilledCol] = "Release";

FilledCol = FilledCol + 1;

NewPage[0][FilledCol] = "Preview";

//Note at this point row number 0 of the array is having the field names

//Remaining rows (i.e 1,2...etc) will now be populated with field data

FilledRow = 0;

MoreRecExist = false;

while(ResSet.next())

{

if (FilledRow == MaxPageRow)

{

MoreRecExist = true;

break;

}

FilledRow = FilledRow + 1;

if(FilledRow==1)

{

FirstSubmission_Id=Long.parseLong(ReturnColumnData(1,ResSet));

}

FilledCol = -1;

for(int Col= 0; Col <= NumOfFields;Col++)

{

//1 is added because JDBC subscripts starts with 1 and not 0

NewPage[FilledRow][Col] = ReturnColumnData(Col + 1,ResSet);

FilledCol = FilledCol + 1;

}

LastSubmission_Id = Long.parseLong(ReturnColumnData(1,ResSet));

Status_Code = ResSet.getString("Status_Code");

if (Status_Code == null)

{

Status_Code = "";

}

else

{

Status_Code = Status_Code.toUpperCase().trim();

}

FilledCol = FilledCol + 1;

//IF SUBMISSION HAS ONLY BEEN REGISTERED THEN SHOW A REMOVE BUTTON

if (Status_Code.equals("R"))

{

NewPage[FilledRow][FilledCol] = "<INPUT TYPE = 'Submit' NAME = 'Remove' value ='" + LastSubmission_Id + "'></INPUT>";

}

FilledCol = FilledCol + 1;

//SHOW THE PROCESS BUTTON IF SUBMISSION HAS BEEN BEEN REGISTERED

if (Status_Code.equals("R"))

{

NewPage[FilledRow][FilledCol] = "<INPUT TYPE = 'Submit' Name = 'Process' value ='" + LastSubmission_Id + "'></INPUT>";

}

FilledCol = FilledCol + 1;

//SHOW THE RELEASE BUTTON IF THE SUBMISSION HAS BEEN BEEN PROCESSED

if (Status_Code.equals("P"))

{

NewPage[FilledRow][FilledCol] = "<INPUT TYPE = 'Submit' NAME = 'Release' value ='" + LastSubmission_Id + "'></INPUT>";

}

FilledCol = FilledCol + 1;

//SHOW THE PREVIEW BUTTON IF THE SUBMISSION HAS BEEN PROCESSED

if (Status_Code.equals("P") ||

Status_Code.equals("C") )

{

NewPage[FilledRow][FilledCol] =

"<img src=\"pdf.gif\" border=\"0\" onClick=\" javascript:window.open('" + StringUtil.replaceString(Preview_URL,"%Submission_Id%",new Long(LastSubmission_Id).toString()) + "', 'SubmissionReport','location=no,menubar=no,toolbar=no,scrollbars=yes,left=' + window.screen.availWidth*1.2/8 + ',top='+window.screen.availHeight*1.2/14 + ',width=' + window.screen.availWidth*3/4 + ',height=' + window.screen.availHeight*6/7 + '')\" style=\"cursor:hand\" >";

//"<img src=\"/appl/development/ccrs/images/pdf.gif\" border=\"0\" onClick=\" javascript:window.open('" + StringUtil.replaceString(Preview_URL,"%Submission_Id%",new Long(LastSubmission_Id).toString()) + "', 'SubmissionReport','location=no,menubar=no,toolbar=no,scrollbars=yes,left=' + window.screen.availWidth*1.2/8 + ',top='+window.screen.availHeight*1.2/14 + ',width=' + window.screen.availWidth*3/4 + ',height=' + window.screen.availHeight*6/7 + '')\" style=\"cursor:hand\" >";

}

}

}

manohar2a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 11
use button and add javascript on click go to the respective URL with the id passed into it.MohanS
mohanshenoya at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...