aspose file tools*
The moose likes Struts and the fly likes Submitting hidden values on the form with onSelect option Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Submitting hidden values on the form with onSelect option" Watch "Submitting hidden values on the form with onSelect option" New topic
Author

Submitting hidden values on the form with onSelect option

anita prat
Greenhorn

Joined: Aug 11, 2011
Posts: 8
I have a jsp pn which I have two drop down lists. I don't have submit button on the form. There is top menu which lists several options, like add User, add Customer which will trigger their respective actions. But before such an action is triggered, the State and Country names from the dropdown need to be selected which will be applied to all the actions . I have tried using hidden values for these state and country values in the dropdown but I am unable to understand how to submit . I have used onSelect option which will trigger a javascript to submit the form. ANd for this form i have written a dummy action which will forward to the same jsp. But not really sure what I am doing is the right way. CAn someone help?
Mkunal badgujar
Greenhorn

Joined: May 18, 2010
Posts: 5
basically you are submitting the form two times with each of the onselect. this is annoying experinence for user . Intead checking the both values on either of the select and passing these values on top menu select will help performance. writing a javascript will be lot of coding instead use jquery.

Regards,
kunal
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

anita prat wrote: But before such an action is triggered, the State and Country names from the dropdown need to be selected which will be applied to all the actions . I have tried using hidden values for these state and country values in the dropdown but I am unable to understand how to submit .


I am not getting the question. The dropdown values get submitted automatically with the form. There is no need to have them as separate parameters to submit. Is it that the drop-downs are in a form different than the one that is getting submitted?


SCJP, SCWCD.
|Asking Good Questions|
anita prat
Greenhorn

Joined: Aug 11, 2011
Posts: 8
No, the two country and state fields are part of the same form which is renedered upon successful login. They have to be available throughtout the session , the actions that get triggered from the top nav on this form need these values. This is what I have now:
HomeForm : countryName,stateName - String values
countryList,stateList - arrayLists

HomeAction.execute(): HomeForm welcomeForm = (HomeForm)form;
String ctryName = welcomeForm.getCountryName();
String stateName = welcomeForm.getStateName();
ArrayList ctryList = welcomeForm.getCountryList();
ctryList.add(ctryName);
ArrayList stateList = welcomeForm.getStateList();
stateList.add(stateName);

request.getSession().setAttribute("welcomeForm",welcomeForm);
return mapping.findForward("homePage");

In LoginAction: execute():
ValueObject vo = new ValueObject();
HomeForm welcomeForm= new HomeForm();
ArrayList<ValueObject> CtryStateLList = DAO.getStateAndCountryList();
Iterator it = CtryStateList.iterator();

ArrayList<String> stateList = new ArrayList();
ArrayList<String> countryList = new ArrayList();
while(it.hasNext()){
vo = (ValueObject)it.next();

stateList.add(vo.getState());
countryList.add(vo.getCountry());
}

welcomeForm.setStateList(stateList);
welcomeForm.setCountryList(countryList);
request.getSession().setAttribute("welcomeForm", welcomeForm);
return mapping.findForward("homePage");


home.jsp:
<script language="JavaScript" type="text/javascript">
function submitForm(fieldValue1,fieldValue2) {
document.welcomeForm.franchiseName.value=fieldValue1;
document.welcomeForm.countryName.value = fieldValue2;
document.welcomeForm.submit;
}
</script>

<html:form method=" post" action="welcome" >
<input type="hidden" name="stateName" >
<input type="hidden" name="countryName">
<input type="submit" onselect="javascript:submitForm('stateName','countryName');">
<br/><br/><br/>
<div class="form-holder">
<b>Select State</b>
<span>
<!--Select Name-->
<h6>Select Participant Name</h6>
<html:select property="stateList">
<htmlptionsCollection name="welcomeForm" property="stateList" label="stateName" />
</html:select>

<!--Select Country-->
<br />
<h6>Select Participant Country</h6>
<select name="" title="Click to select country">
<option value="france">France</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="tour">four</option>
</select>
anita prat
Greenhorn

Joined: Aug 11, 2011
Posts: 8
Can anybody respond to my question? I am still not able to resolve this.
Ravi Khadgi
Greenhorn

Joined: Aug 06, 2010
Posts: 20

anita prat
Greenhorn

Joined: Aug 11, 2011
Posts: 8
Thanks , Rahul. I implemented what you mentioned in your post, now the issue is when i click the target action from the top nav tab to which the two hidden values on the homepage are submitted to, I get a null pointer in that target action when I try to get these values from the request.

In my target action:
String option = request.getparameter("option");
String state = request.getParameter("state");

these values are null. how do I store these values in the request in that jsp. Because in the input tag the value is not specified, it is blank.

<input type="hidden" name="hiddenOption" value="">

I appreciate your help!
Orton K Randy
Ranch Hand

Joined: Aug 12, 2011
Posts: 41

Use JS to set those hidden parameters. Oh wait that's what you did there or did you? I see this usage in your JS.


when there's no input element with attribute 'id'(id="option" or id="state")?

Try this:


Coderanch, best ever forum on the net. Hands down.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Submitting hidden values on the form with onSelect option