PDA

View Full Version : Textfield Value Persistence


rajyalakshmi.suman
Sep 13th, 2007, 08:04 AM
Hi,

Value in TextField should persist after button click.
After button click page gets refreshed & value is not persisting in textfiled
Have tried using form:tags ,spring:bind tags ...
If am using "Spring :bind ":value is persisting but results are not getting displayed after onclick :button .

Kindly let me know is it possible in spring+portletjsr168 ?



<h3>Search Entries</h3>

<%BDCompanyFilterCommand bdcomp1;

bdcomp1 =
(BDCompanyFilterCommand) renderRequest.getPortletSession().getAttribute("bd CompanyFilter");

if (bdcomp1 == null){
bdcomp1 = new BDCompanyFilterCommand();
}

String strFname=null;
String strBusinNr = null;
String strActive = null;

if (renderRequest.getPortletSession().getAttribute("F IRMENAME")!=null) {
strFname= (String)renderRequest.getPortletSession().getAttri bute("FIRMENAME");
}

if (renderRequest.getPortletSession().getAttribute("B U_NR")!=null) {
strBusinNr= renderRequest.getPortletSession().getAttribute("BU _NR").toString();
}

if (renderRequest.getPortletSession().getAttribute("A CTIVE")!=null ) {
strActive= renderRequest.getPortletSession().getAttribute("AC TIVE").toString();
System.out.println("ACTIVE"+strActive);
}

%>

<form:form action="<%=targetURL%>" commandName="bdCompanyFilter">
<input type="hidden" name="param" value="Search" />

<table border="0" cellpadding="4">
<tr>
<td class="wpsTableText">Company name</td>
<td class="wpsTableText">Business unit Nr.</td>
<td class="wpsTableText">Active</td>
</tr>
<tr>
<td>&nbsp;&nbsp;<form:input cssClass="wpsEditField" path="firmename" size="15" maxlength="10" /></td>
<td>&nbsp;&nbsp;<form:input cssClass="wpsEditField" path="bu_nr" size="15" maxlength="10" onkeypress="return checkNumberic(event);" /><%=strBusinNr%></td>
<!--<td>&nbsp;&nbsp;<input type="text" name="bu_nr" size="15" maxlength="10" onkeypress="return checkNumberic(event);" value="<%=strBusinNr%>" /></td>
<form:hidden path="bu_nr" />-->
<td>&nbsp;&nbsp;<input type="checkbox" name="chkActive" onclick="populateActive()" /></td>
<form:hidden path="active" />
</tr>
<tr>
<td colspan="2">&nbsp;
<button type="submit" class="wpsButtonText" onclick="populateActive()">Search</button>
</td>
</tr>

<script>

function checkNumberic (evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if (charCode < 48 || charCode > 57) {
return false;
} else {
return true;
}

}


function populateActive()
{
if(document.forms[0].chkActive.checked)

document.forms[0].active.value=1;
else
document.forms[0].active.value=0;
}


function populateActiveCheckBox()
{

activeCheck="<%=strActive%>";
alert("ACTIVE Value:"+activeCheck);
if(activeCheck==1)
{
document.forms[0].active.checked=true;
}
else
{
document.forms[0].active.checked=false;
}
}
populateActiveCheckBox();

</script>
</table></fieldset>
</form:form>



Thank u
Lakshmi

Marten Deinum
Sep 13th, 2007, 08:38 AM
When posting code please use the [ code][/code ] tags, that way we can read your code...

I don't understand why you are creating all that stuff in your JSP, your controller should handle that. I suggest you read the reference guide and checkout the samples (especially the SpringMVC part) because yu seem to be missing the basics.


public class YourController extends SimpleFormController {

protected Object formBackingObejct(HttpServletRequest request) {
return new BDCompanyFilterCommand();
}


}



<h3>Search Entries</h3>
<form:form action="<%=targetURL%>" commandName="bdCompanyFilter">
<input type="hidden" name="param" value="Search" />
<table border="0" cellpadding="4">
<tr>
<td class="wpsTableText">Company name</td>
<td class="wpsTableText">Business unit Nr.</td>
<td class="wpsTableText">Active</td>
</tr>
<tr>
<td>&nbsp;&nbsp;<form:input cssClass="wpsEditField" path="firmename" size="15" maxlength="10" /></td>
<td>&nbsp;&nbsp;<form:input cssClass="wpsEditField" path="bu_nr" size="15" maxlength="10" onkeypress="return checkNumberic(event);" /></td>
<td>&nbsp;&nbsp;<input type="checkbox" name="chkActive" onclick="populateActive()" /></td>
<form:hidden path="active" />
</tr>
<tr>
<td colspan="2">&nbsp;<button type="submit" class="wpsButtonText" onclick="populateActive()">Search</button></td>
</tr>
</table></fieldset>
</form:form>

Also your jsp with all that javascript looks overly complex, especially the part where you are checking active/chkActive, seems redundant to me.

rajyalakshmi.suman
Sep 13th, 2007, 09:12 AM
hi ,filtercontroller has been already
configured in controller formbacking object
still the value is not persisting

rajyalakshmi.suman
Sep 13th, 2007, 09:14 AM
protected Object formBackingObject(PortletRequest request)
throws Exception {
logger.info("Inside formBackingObject of FilterController");
BDCompanyFilterCommand filter;

filter = new BDCompanyFilterCommand();
return filter;
}