Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disable button from code???

 
meera rao
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
meera rao
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thru the hidden value, we would know which button the user clicked
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic