aspose file tools*
The moose likes Struts and the fly likes Struts2 Datetime Picker focus is not set using javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Datetime Picker focus is not set using javascript" Watch "Struts2 Datetime Picker focus is not set using javascript" New topic
Author

Struts2 Datetime Picker focus is not set using javascript

Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
Hi all,

In my Struts2 application, I used Datetime picker, while entering fields of a form, focus need to be set when a user performs an action for date fields.

So, I need to set the focus using javascript in one or more date fields in the forms.

While setting focus to these date fields,it does not set the focus on the fields

this is the code fragment that i used in my application


sales.jsp:-

<s:datetimepicker id="shipdate%{#statusB.index}"
name="salesshipmentvoList[%{#statusB.index}].shipdate"
theme="simple" value="%{#B.shipdate}" required="true"
cssClass="LoginTextBox"></s:datetimepicker>


java application code:-

public String salesShipment(){

setFocus("shipdate");
setFocusIndex("shipdate");

}


<script type="text/javascript">

function focusNextField(focus,focusIndex){
//focusIndex is the index of a list element of the date field
document.getElementById("shipdate"+focusIndex).focus();
}

</script>

the javascript fucntion is called as follows in sales.jsp


<body onload=focusNextField('<s:property value="focus"/>','<s:property value="focusIndex"/>')>

the above code had no effect on focusing the date field 'shipdate0' or 'shipdate1' and so on
candid java
Greenhorn

Joined: Jan 13, 2012
Posts: 14
Here is the Better way to Resolve your problem refer this link http://candidjava.com/struts-tutorail
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts2 Datetime Picker focus is not set using javascript