Are you getting any errors or what is your logging output?

Brandon Goodin

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] Behalf Of sjones
Sent: Monday, June 02, 2003 11:11 AM
To: [EMAIL PROTECTED]
Subject: Trouble decting which button is pressed |
<html:button><html:submit>


detecting which button is clicked.
seems like the jsp page does not send anything to the form-bean
for a <html:button> or an <html:submit>



LogonOK.jsp
----------------------------------------------------------------------------
-----------------
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<html:html locale="true">
<head>
<title></title>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WEBSPHERE STUDIO">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<body>
<center>
<TABLE bgcolor=yellow>
<TR><TD class="ypTitle"> Choose action</TD></TR>
</TABLE>
<br><br><br>
<h1><bean:message key="login.success"/></h1>
<html:errors/>
<html:form method="post" action="/logon.do">
<html:submit property="clicked"><bean:message key="button.logonSearch"/>
</html:submit><html:submit
property="clicked"><bean:message key="button.logonTickets"/>
</html:submit>
</html:form>
</center>
</body>
</html:html>

SubmitLoginOK.java - (form bean)
-----------------------------------------------------------
package com.ubs.directory.yp.formbeans;
import javax.servlet.http.HttpServletRequest;
import com.ubs.directory.yp.core.*;
import org.apache.struts.action.*;
/**
* Form bean for a Struts application.
* Users may access 2 buttons on this form:
* an onclick set the clicked field to the name of the button
* that was last pressed.
* <ul>
* <li>butQuery - [your comment here]
* <li>butTickets - [your comment here]
* </ul>
* @version 1.0
* @author
**/
public class SubmitLoginOK extends ActionForm {
    private String clicked;
    //protected HTMLbutton m_cancel = new HTMLbutton();
    public SubmitLoginOK() {
        super();
    }
    public void reset(ActionMapping mapping, HttpServletRequest request) {
    // Reset values are provided as samples only. Change as appropriate.
        clicked = "";
    }

public ActionErrors validate(
    ActionMapping mapping,
    HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    // Validate the fields in your form, adding
    // adding each error to this.errors as found, e.g.
    // if ((field == null) || (field.length() == 0)) {
    // errors.add("field", new ActionError("error.field.required"));
    // }
        return errors;
    }

    //gets
    public String getClicked() {
        return clicked;
    }
    //sets
    public void setClicked(String butClicked) {
        this.clicked = clicked;
    }
}


LogonOKAction.java  (action )
---------------------------------
package com.ubs.directory.yp.actions;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.ubs.directory.yp.core.*;
import com.ubs.directory.yp.formbeans.SubmitLoginOK;
/**
* @version 1.0
* @author
*/
public class LoginOKAction extends Action {
final int ypSearchYellowPages= 1;
final int ypShowYellowPageTickets = 2;
/**
* Constructor
*/
public LoginOKAction() {
super();
}
public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception {

    ActionErrors errors = new ActionErrors();
    ActionForward forward = new ActionForward();

    // return value
    SubmitLoginOK submitLoginOK = (SubmitLoginOK) form;
    SubmitLoginOK f = submitLoginOK;

    try {
        // if (submitLoginOK.getButSearch().pressed()) {
        // forward = mapping.findForward("search");
        // System.err.println("Search button pressed");
        //
        // } else if (submitLoginOK.getButTickets().pressed()) {
        // forward = mapping.findForward("tickets");
        // System.err.println("Show tickets pressed");
        //

        System.err.println("get value of clicked:"+ f.getClicked());
        if (submitLoginOK.getClicked().equalsIgnoreCase("1")) {
            forward = mapping.findForward("search");
            System.err.println("Search button pressed");
        } else if (submitLoginOK.getClicked().equalsIgnoreCase("2")) {
            forward = mapping.findForward("tickets");
            System.err.println("Show tickets pressed");
        } else {
            System.err.println("No button pressed");
        }
    } catch (Exception e) {
            errors.add("name", new ActionError("id"));
    }

    if (!errors.empty()) {
        saveErrors(request, errors);
    }

        // Write logic determining how the user should be forwarded.
        forward = mapping.findForward("search");
        return (forward);
    }
}




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to