aspose file tools*
The moose likes Struts and the fly likes Disable button from code??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Disable button from code???" Watch "Disable button from code???" New topic
Author

Disable button from code???

meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
I have 2 buttons,
the first one when clicked calls the javascript to enable the other button, it is calling the javascript but not returning the hidden value to the code.
If i take out the onclick attribute, it sends the value, but refreshes the page, hence at a time i am having either the first button value or the second.

Can i disable the button from the code( is it a good practice)?

Can somebody help me out?
<html:form action="startVerification.do" styleId ="AccVina" method="post">
<html:hidden property="apprCode" value="1"/>
<html:submit styleId="btnVina" property="action" onklick="return DisabDlr()" > Accept Data</html:submit>
</html:form>


<html:form action="startVerification.do" styleId ="ApprDeal" method="post">
<html:hidden property="apprCode" value="4"/>
<html:submit styleId="btnApprove" property="action" > Approve Deal</html:submit>
</html:form>
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I believe the common practice is to make a separate page for verification buttons.

Also, make sure the verification is really necessary. Sometimes verifying data becomes frustrating to users when they hit it 99% of the time.


A good workman is known by his tools.
meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
these are not "verification" buttons. these buttons will be accpeted by the user.

1)Whenever these buttons are clicked the page gets refreshed, is it possible not to refresh the page .

2) for the first button, i am executing a javascript to enable the second button, it does that but doesn't pass the hidden value to the code. I need to do that.

Any kind of help is appreciated.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

1) Make the button an html:button, not an html:submit.

2) The hidden value concept doesn't make much sense to me. What are you using it for?
meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
thru the hidden value, we would know which button the user clicked
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

But each button HAS a value of its own. It gets submitted as a parameter like all the other fields from the form. This is how LookupDispatchAction works.
OR if you aren't using DispatchActions you can still tell from your Action class which button was clicked.
With your current code, the below line will give you the text displayed in the button (ie "Approve Deal"):
String buttonClicked = (String)request.getParameter("action");
meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
I am trying to use LookUpDispatchAction . I have a button , which when clicked doesn't execute the appropriate methos.

my struts-config is as follows:

<form-bean name="verificationForm" type="com.odps.eta.verification.forms.VerificationActionForm" />

<action name="verificationForm"
parameter="action1"
path="/rejectDeal"
scope="session" type="com.odps.eta.verification.action.VerificationAction"
input="/startVerification.jsp"
validate="false">
<forward name="rejectDeal" path="/pages/ErrorMessagePopUp.jsp" />
</action>


my action class is as follows:

public class VerificationAction extends LookupDispatchAction {

protected Map getKeyMethodMap() {
log.info("In side map");
Map map = new HashMap();
map.put("rejectDeal","rejectDeal");
return map;
}

public ActionForward rejectDeal(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response ) throws Exception{

return mapping.findForward("rejectDeal");

}

Do you have any idea what is the mistake here?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

The javadoc for LookupDispatchAction is pretty good.

Here's what is wrong. Your buttons needs to get their text from your ApplicationResources.properties file. Most of the other needed changes are in bold. If any of this is not clear to you, the javadoc should be of good use.

ApplicationResources:
button.accept = Accept Data
button.approve = Approve Deal

JSP:
<html:form action="startVerification.do" styleId ="AccVina" method="post">
<html:hidden property="apprCode" value="1"/>
<html:submit styleId="btnVina" property="action" onklick="return DisabDlr()" ><bean:message key="button.accept"/></html:submit>
</html:form>


<html:form action="startVerification.do" styleId ="ApprDeal" method="post">
<html:hidden property="apprCode" value="4"/>
<html:submit styleId="btnApprove" property="action" ><bean:message key="button.approve"/></html:submit>
</html:form>
DispatchAction:
protected Map getKeyMethodMap() {
log.info("In side map");
Map map = new HashMap();
map.put("button.accept","accept");
map.put("button.approve","approve");

return map;
}

public ActionForward accept(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response ) throws Exception{
// code to accept here
return mapping.findForward("accepted");

}
public ActionForward approve(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response ) throws Exception{
// code to approve here
return mapping.findForward("approved");
}

struts-config:
<action name="verificationForm"
parameter="action1"
path="/startVerification"
scope="session" type="com.odps.eta.verification.action.VerificationAction"
input="/startVerification.jsp"
validate="false">
<!-- forwards here -->
</action>

You should be able to take this and figure out how to also add reject or other buttons/methods to your code.
meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
can we also enable or disable buttons from code, or from jsp .

in jsp i wrote a javascript to disable the button, it does disable , but the code doesn't get executed
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

The code does get executed by the looks of it. What happens, though is that the page gets submitted in addition to the button becoming disabled. When the new page returns, the button is no longer disabled because it is a brand new page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disable button from code???