on 05-25-2006 8:31 AM
Hi all,
From one of the already existing portal logon screens, I have to invoke a component that I have written (Because a new functionality was added)
I have added the necessary code in the JSP to invoke my controller class -
<hbj:button
id = "Contactus"
text = "SUBMIT" disabled = "false" onClientClick="validateFields()" onClick = "SendMail"
design="STANDARD"/>
In my JSP DynPage Controller class I have the following method:
public void onSendMail(Event event)throws PageException{
//My code
}
But I find that this code is not invoked.
What could be the reason?? Is there any other way by which I can add a button to an already existing portal page and do some processing with it?
Hi Ashwini,
Try giving it as onClick="<b>s</b>endMail" (s in lower case).
Then the event handler name can be
public void <b>s</b>endMail(Event e) throws PageException{
}
or
public void on<b>S</b>endMail(Event e) throws PageException{
}
Regards,
Harini S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi harini,
Tried both your options, but doesn't work..
Infact what is happening is .. the moment I click on "Submit" button, instead of invoking my controller, it automatically goes back to the login page.
If I run my component alone from portal-app.xml, i get javascript.void(0) error on click of "Submit"
Ashwini.
My JSP file is this:
<%@ page session = "true"%>
<%@ page import = "com.sapportals.htmlb.taglib.ButtonTag" %>
<%@ taglib uri="tagLib" prefix="hbj" %>
<%@ page import = "com.sap.security.core.sapmimp.logon.*" %>
<%@ page import = "com.sap.security.core.sapmimp.rendering.Browsers" %>
<%@ page import = "com.enduser.contactus.*" %>
<%@ include file="logon_proxy.txt" %>
<jsp:useBean id="logonLocale" class="com.sap.security.core.sapmimp.logon.LogonLocaleBean" scope="session"></jsp:useBean>
<jsp:useBean id="logonMessage" class="com.sap.security.core.sapmimp.logon.LogonMessageBean" scope="session"></jsp:useBean>
<jsp:useBean id="logonBean" class="com.sap.security.core.sapmimp.logon.LogonBean" scope="session"></jsp:useBean>
<jsp:useBean id="error" class="com.sap.security.core.util.ErrorBean" scope='request'></jsp:useBean>
<jsp:useBean id="ContactBean" scope="application" class="com.enduser.contactus.ContactusBean"></jsp:useBean>
<%if( !inPortal ) { %>
<html>
<head>
<link rel=stylesheet href="<%=webpath%>css/global.css">
<link rel=stylesheet href="<%=webpath%>css/logon.css">
<link rel=stylesheet href="<%=webpath%>css/ur/ur_<%=Browsers.getStyleSheet(request)%>.css">
</head>
<% } %>
<script language="JavaScript" src="<%=webpath%>js/basic.js"></script>
<script language="JavaScript">
function setFocusToFirstField() {
myform = document.helpForm;
for(i=0; i<myform.length; i++) {
elem = myform.elements<i>;
if(elem.readOnly==false && (elem.type=="select" || elem.type=="text")) {
elem.focus();
break;
}
}
}
function resetFields(){
var funName = htmlb_formid+"_getHtmlbElementId";
fun = window[funName];
var inputField1 = eval(fun("contFnameField"));
var inputField2 = eval(fun("contPasswordField"));
var inputField3 = eval(fun("contCompanyField"));
var inputField4 = eval(fun("contEmailField"));
var inputField5 = eval(fun("contContactField"));
var inputString1 = inputField1.getValue().toString();
var inputString2 = inputField2.getValue().toString();
var inputString3 = inputField3.getValue().toString();
var inputString4 = inputField4.getValue().toString();
var inputString5 = inputField5.getValue().toString();
//var inputString6 = inputField6.getValue().toString();
if(inputString1 !=null)
{
inputField1.setValue("");
}
if(inputString2!=null){
inputField2.setValue("");
}
if(inputString3!=null){
inputField3.setValue("");
}
if(inputString4!=null){
inputField4.setValue("");
}
if(inputString5!=null){
inputField5.setValue("");
}
}
//This function is for allowing only numbers in a textfield
function numbersOnly(e){
var flag = true;
if (isNaN(e))
{
flag = false;
}
else if (e.indexOf(".")> -1)
{
flag = false;
}
else
{
flag = true;
}
return flag;
}
function validateFields()
{
var funName = htmlb_formid+"_getHtmlbElementId";
fun = window[funName];
var inputField1 = eval(fun("contFnameField"));
var inputField2 = eval(fun("contPasswordField"));
var inputField3 = eval(fun("contCompanyField"));
var inputField4 = eval(fun("contEmailField"));
var inputField5 = eval(fun("contContactField"));
//var inputField6 = eval(fun("contCommentsField"));
var inputString1 = inputField1.getValue().toString();
var inputString2 = inputField2.getValue().toString();
var inputString3 = inputField3.getValue().toString();
var inputString4 = inputField4.getValue().toString();
var inputString5 = inputField5.getValue().toString();
//var inputString6 = inputField6.getValue().toString();
if (inputString1 == "")
{
alert("Enter Your First Name!");
htmlbevent.cancelSubmit="true";
return false;
}
if (inputString2 == "")
{
alert("Enter a value in the Password field!");
htmlbevent.cancelSubmit="true";
return false;
}
if (inputString3 == "")
{
alert("Enter a Company Name!");
htmlbevent.cancelSubmit="true";
return false;
}
if (inputString4 == "")
{
alert("Enter an Email Address!");
htmlbevent.cancelSubmit="true";
return false;
}
if (inputString5 == "")
{
alert("Enter a Contact Number!");
htmlbevent.cancelSubmit="true";
return false;
}
if (!numbersOnly(inputString5))
{
alert("Enter an Integer in the Contact Number Field!");
htmlbevent.cancelSubmit="true";
return false;
}
}
</script>
<link rel=stylesheet href="<%=webpath%>css/global.css">
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:596px;
top:48px;
width:196px;
height:21px;
z-index:1;
}
-->
</style>
<body bgcolor="#ffffff" vLink="#009900" aLink="#009900" link="#009900" >
<!--<%@ include file="/umLogonTopArea.txt"%>-->
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
<div id="Layer1">
<span class="boxlinks1">
<img src="<%=webpath%>layout/big_arrow_green.gif" width="9" height="7" hspace="0" vspace="0" border="0" />
<a href="#" class="boxlinks1" onMouseOver="status='Contact us'; return true;" onMouseOut="status='';">Contact us
</span>
</div>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1155"><table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="<%=webpath%>layout/spacer.gif" width="20" height="115" /></td>
<td><img src="<%=webpath%>layout/top.GIF" width="734" height="115" /></td>
<td></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="<%=webpath%>layout/spacer.gif" width="300" height="8" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20">
<img src="<%=webpath%>layout/spacer.gif" width="20" height="1" />
</td>
<td width="770" height="1" class="greenHeaderBox"></td>
</tr>
</table>
<img src="<%=webpath%>layout/spacer.gif" width="300" height="30" /></td>
</tr>
<tr>
<td><table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20" valign="top">
<img src="<%=webpath%>layout/spacer.gif" width="20" height="1" /></td>
<td width="772"><table width="553" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="554" height="362" valign="top"><table width="553" height="139" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="27" align="left" valign="middle" class="bpLightGrey2"><span class="siteintro_box">Contact us</span></td>
</tr>
<tr>
<td height="2" align="left" valign="top"><img src="<%=webpath%>layout/spacer_blank.gif" width="1" height="1" hspace="0" vspace="0" border="0" /></td>
</tr>
<tr>
<td height="100" align="left" valign="top" class="bodytext">
<table width="553" height="100" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top" class="bodytext">
<td class="padding10" ><div class="bodytext">
<hbj:formLayout
id="myForm"
marginTop="5px"
marginRight="30px"
marginBottom="5px"
marginLeft="3px"
width="350px">
<hbj:formLayoutRow
id="Row1"
paddingTop="5px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell11"
align="LEFT"
paddingLeft="3"
paddingTop="5"
paddingRight="5"
paddingBottom="0"
width="20%">
<hbj:inputField
id="contFnameField"
type="string"
maxlength="35"
visible="true"
disabled="false"
jsObjectNeeded="true"
size="25"
value="<%=ContactBean.getFName()%>"
/>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row2"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell12"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="1"
width="20%">
<hbj:label
id="lbl_FName"
text="First Name"
design="LABEL"
labelFor="contFnameField"></hbj:label>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row3"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell13"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="0"
width="20%">
<hbj:inputField
id="contPasswordField"
type="string"
maxlength="35"
visible="true"
disabled="false"
jsObjectNeeded="true"
size="25"
value="<%=ContactBean.getPassword()%>"
/>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row4"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell14"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="1"
width="20%">
<hbj:label
id="lbl_Password"
text="Password"
design="LABEL"
labelFor="contPasswordField"></hbj:label>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row5"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell15"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="0"
width="20%">
<hbj:inputField
id="contCompanyField"
type="string"
maxlength="35"
visible="true"
disabled="false"
jsObjectNeeded="true"
size="25"
value="<%=ContactBean.getCompany()%>"
/>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row6"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell16"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="1"
width="20%">
<hbj:label
id="lbl_Company"
text="Company Name"
design="LABEL"
labelFor="contCompanyField"></hbj:label>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row7"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell17"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="0"
width="20%">
<hbj:inputField
id="contEmailField"
type="string"
maxlength="35"
visible="true"
disabled="false"
jsObjectNeeded="true"
size="25"
value="<%=ContactBean.getEmail()%>"
/>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row8"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell18"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="1"
width="20%">
<hbj:label
id="lbl_Email"
text="Email Address"
design="LABEL"
labelFor="contEmailField"></hbj:label>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row9"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell19"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="0"
width="20%">
<hbj:inputField
id="contContactField"
type="string"
maxlength="35"
visible="true"
disabled="false"
jsObjectNeeded="true"
size="25"
value="<%=ContactBean.getContact()%>"
/>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row110"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell110"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="1"
width="20%">
<hbj:label
id="lbl_Contact"
text="Contact Number"
design="LABEL"
labelFor="contContactField"></hbj:label>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row111"
paddingTop="5px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell111"
align="LEFT"
colspan="4"
paddingLeft="3"
paddingTop="15"
paddingRight="50"
paddingBottom="0"
width="80%">
<hbj:textEdit
id="contCommentsField"
text="<%=ContactBean.getComments()%>"
rows="5"
cols="60"
/>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<hbj:formLayoutRow
id="Row112"
paddingTop="0px"
paddingBottom="0px">
<hbj:formLayoutCell
id="Cell112"
align="LEFT"
paddingLeft="3"
paddingTop="0"
paddingRight="5"
paddingBottom="1"
width="20%">
<hbj:label
id="lbl_Comments"
text="Comments"
design="LABEL"
labelFor="contCommentsField"></hbj:label>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
<br/>
<br/>
<hbj:formLayoutRow
id="Row113"
paddingTop="25px"
paddingBottom="5px">
<hbj:formLayoutCell
id="Cell113"
colspan="2"
align="LEFT"
paddingLeft="3"
paddingTop="25"
paddingRight="10"
paddingBottom="5"
width="20%">
<hbj:button
id = "Contactus"
text = "SUBMIT"
disabled = "false"
onClientClick="validateFields()"
onClick = "sendMailToAdmin"
design="STANDARD"></hbj:button>
<hbj:button
id = "reset"
text = "RESET"
disabled = "false"
tooltip = "Click here to Reset fields"
onClientClick="resetFields()"
onClick = "ResetClick"
design="STANDARD"></hbj:button>
</hbj:formLayoutCell>
</hbj:formLayoutRow>
</hbj:formLayout>
</div>
</span></div>
<img src="<%=webpath%>layout/spacer_blank.gif" width="1" height="1" hspace="0" vspace="0" border="0" /></td>
</tr>
<tr>
<table>
<tr>
<td>
<img src="<%=webpath%>layout/spacer.gif" width="20" height="1" />
</td>
</tr>
</table>
</tr>
</table></td>
</tr>
<tr>
<td height="5" align="left" valign="top"><img src="<%=webpath%>layout/spacer_blank.gif" width="1" height="1" hspace="0" vspace="0" border="0" /></td>
</tr>
<tr>
<td height="5" align="left" valign="top"><p class="bodytext"><br/>
</p>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<td height="10"><tr>
<td><table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><img src="<%=webpath%>layout/spacer.gif" width="20" height="23" /></td>
<td><hr size="1" color="#CCCCCC" noshade="noshade"/></td>
</tr>
<tr>
<td><img src="<%=webpath%>layout/spacer.gif" width="20" height="20" /></td>
<td></td>
</tr>
<tr>
<td><img src="<%=webpath%>layout/spacer.gif" width="20" height="20" /></td>
</span></td>
</tr>
</table></td>
</tr>
</table>
<p class="mainartsbhead"> </p>
</hbj:form>
</hbj:page>
</hbj:content>
<!--<%@ include file="/umLogonBotArea.txt"%>-->
<% proxy.sessionInvalidate(); %>
<%if(inPortal) { %>
</span>
<% } else { %>
</body>
</html>
<% } %>
My Controller class is this :
package com.enduser.contactus;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.print.attribute.standard.Severity;
import com.sapportals.htmlb.InputField;
import com.sapportals.htmlb.TextEdit;
import com.sapportals.htmlb.event.Event;
import com.sapportals.htmlb.page.DynPage;
import com.sapportals.htmlb.page.PageException;
import com.sapportals.htmlb.rendering.IPageContext;
import com.sapportals.htmlb.rendering.PageContextFactory;
import com.sapportals.portal.htmlb.page.JSPDynPage;
import com.sapportals.portal.htmlb.page.PageProcessorComponent;
import com.sapportals.portal.prt.component.IPortalComponentContext;
import com.sapportals.portal.prt.component.IPortalComponentProfile;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;
public class ContactusController extends PageProcessorComponent {
public DynPage getPage(){
return new ContactusControllerDynPage();
}
public static class ContactusControllerDynPage extends JSPDynPage{
IPortalComponentRequest request;
IPortalComponentResponse response;
IPortalComponentContext context;
IPortalComponentProfile profile;
IPageContext myContext;
int flag = 0;
private ContactusBean contactBean = null;
public void doInitialization(){
request = (IPortalComponentRequest)this.getRequest();
response = (IPortalComponentResponse)this.getResponse();
context = request.getComponentContext();
profile = context.getProfile();
Object o = context.getValue("ContactusBean");
if(o==null || !(o instanceof ContactusBean)){
contactBean = new ContactusBean();
context.putValue("ContactusBean",contactBean);
} else {
contactBean = (ContactusBean) o;
}
response.write("Exiting doInit()");
}
public void doProcessAfterInput() throws PageException {
request = (IPortalComponentRequest)this.getRequest();
response = (IPortalComponentResponse)this.getResponse();
context = request.getComponentContext();
profile = context.getProfile();
myContext = PageContextFactory.createPageContext(request,response);
Object o = context.getValue("ContactusBean");
if(o==null || !(o instanceof ContactusBean)){
contactBean = new ContactusBean();
context.putValue("ContactusBean",contactBean);
} else {
contactBean = (ContactusBean) o;
}
response.write("exit doPAI()");
}
public void doProcessBeforeOutput() throws PageException {
response.write("inside doProcessBeforeOutput()");
if(flag == 0){
this.setJspName("umHelpPage.jsp");
}
if(flag == 2){
this.setJspName("umHelpPage.jsp");
}
}
public void onResetClick(Event e) throws PageException{
response.write("Inside reset");
contactBean=(ContactusBean) context.getValue("ContactusBean");
InputField ifield=null;
TextEdit textedit = null;
ifield=(InputField)myContext.getComponentForId("contFnameField");
String FName=(ifield.getString()).getValue();
if(FName !=null){
contactBean.setFName("");
}
ifield=(InputField)myContext.getComponentForId("contPasswordField");
String Pwd=(ifield.getString()).getValue();
if(Pwd !=null){
contactBean.setPassword("");
}
ifield=(InputField)myContext.getComponentForId("contCompanyField");
String Company=(ifield.getString()).getValue();
if(Company !=null){
contactBean.setCompany("");
}
ifield=(InputField)myContext.getComponentForId("contEmailField");
String Email=(ifield.getString()).getValue();
if(Email != null){
contactBean.setEmail("");
}
ifield=(InputField)myContext.getComponentForId("contContactField");
String ContactNo=(ifield.getString()).getValue();
if(ContactNo != null){
contactBean.setContact("");
}
textedit=(TextEdit)myContext.getComponentForId("contCommentsField");
String Comments=textedit.getText();
if(Comments != null){
contactBean.setComments("");
}
flag = 2;
}
public void onsendMailToAdmin(Event event)throws PageException{
try
{
response.write("Inside send Mail method");
contactBean=(ContactusBean) context.getValue("ContactusBean");
InputField ifield=null;
TextEdit textedit = null;
ifield=(InputField)myContext.getComponentForId("contFnameField");
String FName=(ifield.getString()).getValue();
contactBean.setFName(FName);
ifield=(InputField)myContext.getComponentForId("contPasswordField");
String Pwd=(ifield.getString()).getValue();
contactBean.setPassword(Pwd);
ifield=(InputField)myContext.getComponentForId("contCompanyField");
String Company=(ifield.getString()).getValue();
contactBean.setCompany(Company);
ifield=(InputField)myContext.getComponentForId("contEmailField");
String Email=(ifield.getString()).getValue();
contactBean.setEmail(Email);
ifield=(InputField)myContext.getComponentForId("contContactField");
String ContactNo=(ifield.getString()).getValue();
contactBean.setContact(ContactNo);
textedit=(TextEdit)myContext.getComponentForId("contCommentsField");
String Comments=textedit.getText();
contactBean.setComments(Comments);
//String host=IConstants.Mail_Host;
//String From_email=IConstants.Mail_From;
//String to=EMail;
//String subject=IConstants.Mail_Subject_End_User+IssueId;
String messageText= "First Name" +contactBean.getFName()+"n"+
"Password" +contactBean.getPassword()+"n"+
"Company" +contactBean.getCompany()+"n"+
"Email Address"+contactBean.getEmail()+"n"+
"Contact Number"+contactBean.getContact()+"n"+
"Comments"+contactBean.getComments()+"n";
/* boolean sessionDebug=true;
Properties props=System.getProperties();
//props.put("mail.host",host);
props.put("mail.transport.protocol","smtp");
Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg=new MimeMessage(mailSession);
//msg.setFrom(new InternetAddress(From_email));
/*msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(messageText,"text/html");*/
//Transport.send(msg);
}
catch(Exception ex){
}
}
}
}
You must have realised that I have modified one of the existing pages in the logon par to my requirements. In the customised page of mine, i have 2 buttons. To do the processing on click of button submit, I have written a new JSP Dynpage component class, which is not getting invoked.
-Ashwini.
Hi Ashwini,
I find the case doesn't match the event handler.
For onClick="<u>s</u>endMailToAdmin", event handler should be
<b><u>s</u>endMailToAdmin</b>() or <b>on<u>S</u>endMailToAdmin</b>(). Note Java is case sensitive. If u r using just the method name directly, use the name as such. If u r prefixing by 'on', then the letter following it should be in uppercase.
Regards,
Harini S
Hi Ashwini,
You have not defined the onClick property of button,
This is the code for defining the button to invoke the controller class called onSendMail.
<hbj:button id="Contactus"
text="SUBMIT"
tooltip="Click me to contact us"
disabled="false"
onClick="SendMail"
design="STANDARD"
/>
This should work.
PS: If helpful award points
--Deepak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.