You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bruce James <ja...@pomegranate.ltd.uk> on 2003/09/17 11:53:59 UTC

Problem recognising button property in action

Hi, 

I'm having a particularly frustrating time trying to get my struts app to
recognise which button has been pressed.
I've stripped it down a bit to only one submit button with one property
and getter & setters for it.
The problem I have is that the property specified in the html:submit tag
doesn't seem to have its setter method called.

I know the ReportForm is having other setters called, as I can see them in
the log, but the setButtonCreate setter never gets called.

I know about DispatchAction etc, but would prefer not to use them right
now, as this should work (so I've read elsewhere).

Any ideas?

Thanks,

Bruce

Code snippets follow.

jsp snippet
<html:submit property="buttonCreate" 
titleKey="help.CreateReport"><bean:message
key="text.CreateReport"/></html:submit>

struts-config snippet
                <action path="/loginProcess"
type="com.comtelco.central.reporting.web.action.LoginAction"
name="loginForm" input="/templates/login.jsp" scope="request"
validate="true">
                        <exception
type="com.comtelco.central.reporting.exception.AuthorisationException"
key="err.authorisation" scope="request" path="/action/login" />
                        <exception
type="com.comtelco.central.reporting.exception.InvalidLoginException"
key="err.invalidlogin" path="/action/login" scope="request" />
                        <forward name="Success" redirect="true"
path="/action/mainmenu" />
                        <forward name="Failure" redirect="true"
path="/action/login" />
                </action>



ReportForm snippet
       // Buttons
        public void setButtonCreate( java.lang.String buttonCreate ) {
                LOG.debug( "setBCreate" );
                this.buttonCreate = buttonCreate;
        }
        public String getButtonCreate( ) {
                LOG.debug( "getBCreate" );
                return buttonCreate;
        }
        public boolean isButtonCreate() {
                // buttonCreate
                return (buttonCreate != null);
        }


Report Action snippet
                if (((ReportForm) form).isButtonCreate() ) {
                        LOG.debug( "createReport" );
                        serviceRequest( form );
                        forward=mapping.findForward(
IConstants.SUCCESS_KEY );
                } else {
                        // No buttons pressed
                        // Fill in all the data needed for the view
                        // in the ActionForm.
                        initialiseForm( (ReportForm) form );
                        forward=mapping.findForward(
IConstants.SUCCESS_KEY );
                }






--
Bruce James
mailto: bruce@pomegranate.ltd.uk
07973 114881


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Problem recognising button property in action

Posted by Bruce James <ja...@pomegranate.ltd.uk>.
Thanks for your help
The problem is that the setter for setButtonCreate never gets called in
the form bean even if I have a value set.

I have now found a workround for this problem, as follows:

In the action execute 
		...
                if (isButton( request, "buttonCreate" ) ) {
                        LOG.debug( "createReport" );
                        serviceRequest( form );
                        forward=mapping.findForward(
IConstants.SUCCESS_KEY );
                } else {
                        // No buttons pressed
                        // Fill in all the data needed for the view
                        // in the ActionForm.
                        initialiseForm( (ReportForm) form );
                        forward=mapping.findForward(
IConstants.SUCCESS_KEY );
                }
		'''

And new method...

      public boolean isButton( HttpServletRequest request, String name ) {
                // True if the request parameter name is not null
                boolean state = (request.getParameter( name ) != null);
                if (state) LOG.debug( "Button "+name+" pressed." );
                return state;
        }

This basically reads the parameter directly from the request, bypassing
struts, it's a bit manual, but that's fine by me because it works.

Cheers.

Bruce




On Thu, 18 Sep 2003, hari_s wrote:

> You can try give your html:submit a value <html:submit value="submit"
> property="buttonCreate" />,<html:submit value="cancel"
> property="buttonCreate" />
> 
> 
> And in your action class put code to arrange mapping for every submit
> value 
> You you can try something like this
> 
> yourFormBean frm=( yourFormBean)form;
> 
> if(frm.getButtonCreate().equals("submit")) return
> mapping.findForward(.....and so on)
> 
> of course you have to make setter and getter method for your submit
> property...
> 
> 
> -----Original Message-----
> From: jamesb@indica [mailto:jamesb@indica] On Behalf Of Bruce James
> Sent: Wednesday, September 17, 2003 4:54 PM
> To: struts-user@jakarta.apache.org
> Subject: Problem recognising button property in action
> 
> 
> Hi, 
> 
> I'm having a particularly frustrating time trying to get my struts app
> to
> recognise which button has been pressed.
> I've stripped it down a bit to only one submit button with one property
> and getter & setters for it.
> The problem I have is that the property specified in the html:submit tag
> doesn't seem to have its setter method called.
> 
> I know the ReportForm is having other setters called, as I can see them
> in
> the log, but the setButtonCreate setter never gets called.
> 
> I know about DispatchAction etc, but would prefer not to use them right
> now, as this should work (so I've read elsewhere).
> 
> Any ideas?
> 
> Thanks,
> 
> Bruce
> 
> Code snippets follow.
> 
> jsp snippet
> <html:submit property="buttonCreate" 
> titleKey="help.CreateReport"><bean:message
> key="text.CreateReport"/></html:submit>
> 
> struts-config snippet
>                 <action path="/loginProcess"
> type="com.comtelco.central.reporting.web.action.LoginAction"
> name="loginForm" input="/templates/login.jsp" scope="request"
> validate="true">
>                         <exception
> type="com.comtelco.central.reporting.exception.AuthorisationException"
> key="err.authorisation" scope="request" path="/action/login" />
>                         <exception
> type="com.comtelco.central.reporting.exception.InvalidLoginException"
> key="err.invalidlogin" path="/action/login" scope="request" />
>                         <forward name="Success" redirect="true"
> path="/action/mainmenu" />
>                         <forward name="Failure" redirect="true"
> path="/action/login" />
>                 </action>
> 
> 
> 
> ReportForm snippet
>        // Buttons
>         public void setButtonCreate( java.lang.String buttonCreate ) {
>                 LOG.debug( "setBCreate" );
>                 this.buttonCreate = buttonCreate;
>         }
>         public String getButtonCreate( ) {
>                 LOG.debug( "getBCreate" );
>                 return buttonCreate;
>         }
>         public boolean isButtonCreate() {
>                 // buttonCreate
>                 return (buttonCreate != null);
>         }
> 
> 
> Report Action snippet
>                 if (((ReportForm) form).isButtonCreate() ) {
>                         LOG.debug( "createReport" );
>                         serviceRequest( form );
>                         forward=mapping.findForward(
> IConstants.SUCCESS_KEY );
>                 } else {
>                         // No buttons pressed
>                         // Fill in all the data needed for the view
>                         // in the ActionForm.
>                         initialiseForm( (ReportForm) form );
>                         forward=mapping.findForward(
> IConstants.SUCCESS_KEY );
>                 }
> 
> 
> 
> 
> 
> 
> --
> Bruce James
> mailto: bruce@pomegranate.ltd.uk
> 07973 114881
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

--
Bruce James
mailto: bruce@pomegranate.ltd.uk
07973 114881


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Problem recognising button property in action

Posted by hari_s <ha...@indonesian-aerospace.com>.
You can try give your html:submit a value <html:submit value="submit"
property="buttonCreate" />,<html:submit value="cancel"
property="buttonCreate" />


And in your action class put code to arrange mapping for every submit
value 
You you can try something like this

yourFormBean frm=( yourFormBean)form;

if(frm.getButtonCreate().equals("submit")) return
mapping.findForward(.....and so on)

of course you have to make setter and getter method for your submit
property...


-----Original Message-----
From: jamesb@indica [mailto:jamesb@indica] On Behalf Of Bruce James
Sent: Wednesday, September 17, 2003 4:54 PM
To: struts-user@jakarta.apache.org
Subject: Problem recognising button property in action


Hi, 

I'm having a particularly frustrating time trying to get my struts app
to
recognise which button has been pressed.
I've stripped it down a bit to only one submit button with one property
and getter & setters for it.
The problem I have is that the property specified in the html:submit tag
doesn't seem to have its setter method called.

I know the ReportForm is having other setters called, as I can see them
in
the log, but the setButtonCreate setter never gets called.

I know about DispatchAction etc, but would prefer not to use them right
now, as this should work (so I've read elsewhere).

Any ideas?

Thanks,

Bruce

Code snippets follow.

jsp snippet
<html:submit property="buttonCreate" 
titleKey="help.CreateReport"><bean:message
key="text.CreateReport"/></html:submit>

struts-config snippet
                <action path="/loginProcess"
type="com.comtelco.central.reporting.web.action.LoginAction"
name="loginForm" input="/templates/login.jsp" scope="request"
validate="true">
                        <exception
type="com.comtelco.central.reporting.exception.AuthorisationException"
key="err.authorisation" scope="request" path="/action/login" />
                        <exception
type="com.comtelco.central.reporting.exception.InvalidLoginException"
key="err.invalidlogin" path="/action/login" scope="request" />
                        <forward name="Success" redirect="true"
path="/action/mainmenu" />
                        <forward name="Failure" redirect="true"
path="/action/login" />
                </action>



ReportForm snippet
       // Buttons
        public void setButtonCreate( java.lang.String buttonCreate ) {
                LOG.debug( "setBCreate" );
                this.buttonCreate = buttonCreate;
        }
        public String getButtonCreate( ) {
                LOG.debug( "getBCreate" );
                return buttonCreate;
        }
        public boolean isButtonCreate() {
                // buttonCreate
                return (buttonCreate != null);
        }


Report Action snippet
                if (((ReportForm) form).isButtonCreate() ) {
                        LOG.debug( "createReport" );
                        serviceRequest( form );
                        forward=mapping.findForward(
IConstants.SUCCESS_KEY );
                } else {
                        // No buttons pressed
                        // Fill in all the data needed for the view
                        // in the ActionForm.
                        initialiseForm( (ReportForm) form );
                        forward=mapping.findForward(
IConstants.SUCCESS_KEY );
                }






--
Bruce James
mailto: bruce@pomegranate.ltd.uk
07973 114881


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org