Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Reset Hidden fields

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a dynamic list of objects(with properties) displayed in the jsp.
Whenever a property is edited i create a hidden field(thru javascript) and retrieve it in the Action class and do my business logic.
If i update property1, the logic is fine but if i go and update property 2 after property1 has been updated, the hidden field created for property1 is still present in the request object although javascript call has not been made for property1.

Is there any way of deleting/ resetting these hidden fields???

Any pointers/ suggestions???
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just have your action class reset the hidden field associated with property1 when it does its update.
 
Suzi Cooper
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both fields(property1& property2) are not properties of the formBean. The hidden fields are created in the DOM and then i retrieve them through request.getParameter().

Apologies if i am being silly here, but how can i reset these?

Here's my code:

JSP

// looping thru a list of objects

<input name="<%=benefitType.getName()%>_<%=cField.getName()%>" onChange="javascript:createHiddenField('actionForm', this.value,'<%=benefitType.getName()%>_<%=cField.getName()%>','<%=benefitType.getName()%>')" type="text" value="<%=cValue%>" />

// Javascript function


function createHiddenField(formName, updatedValue, fieldName, benefitType)
{
var thisForm = document.getElementById(formName);
var hiddenField = document.createElement("input");
var hiddenField2 = document.createElement("input");

hiddenField.type = "hidden";
hiddenField2.type = "hidden";

hiddenField.name = fieldName;
hiddenField2.name = "benefitType";

hiddenField.value = updatedValue;
hiddenField2.value = benefitType;

thisForm.appendChild(hiddenField);
thisForm.appendChild(hiddenField2);
}

// Action class


for(int k=0;k< form.getBike4WorkEditableFields().size(); k++ )
{
String fieldValue = benefitTypeName+"_"+form.getBike4WorkEditableFields().get(k);
String value = getRequest().getParameter(fieldValue);

if(!value.equals(""))
benefit_asset.setExtendedAssetValue("New "+form.getBike4WorkEditableFields().get(k), value);

}


// FormBean

public void reset(HttpServletRequest req, HttpServletResponse res)
{
errors = new ArrayList<String>();
messages = new ArrayList<String>();
}
[ June 19, 2008: Message edited by: Suzi Cooper ]
 
Ranch Hand
Posts: 137
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever hidden field you create through javascript with a name, declare the property in thr form bean. The reset method would resetting the values. Or else try declaring an attribute "redirect=true" in the forward tag of your action.
 
Suzi Cooper
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The properties can be added dynamically through another application and therefore i can't declare them in the form.

Is there any work -around this(apart from redirect=true) ?
 
Suzi Cooper
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorted....it was a silly javascript mistake.

Thanks for the help guys!!!
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic