You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Arne Brutschy <ma...@studserv.uni-leipzig.de> on 2004/01/29 11:10:15 UTC

best way to handle an indexed property and a textarea

Hi all,

I want to use an indexed property with a textarea. Line 0 in the 
textarea should be array[0] etc. What is the best way to do this? Right 
now, I'm thinking about writing a custom tag, subclassing TextareaTag 
and splitting up the data something like value.split("\\r\\n");
Is there a more simple way?

Regards,
Arne Brutschy



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: best way to handle an indexed property and a textarea

Posted by Guillermo Meyer <gm...@sib.interbanking.com.ar>.
I needed this feature in one place of my application and made it but
didn“t subclass TextAreaTag, neither created a custom tag (thought i
should). In fact, now that I see it, it's a little messy :P. I know it
can be done better, but it's just only as an idea of what i did and a
starting point for you to solve this problem:


<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/x71taglib.tld" prefix="x71" %>

<%
String maxLength = "78"; //max lenght of each row
String size = "145"; //size of each row
int max = 10; //number of rows
%>

<style>
.editMsg { BORDER-BOTTOM: #104a7b 1px solid; BORDER-LEFT: #afc4d5 1px
solid; BORDER-RIGHT: #104a7b 1px solid; BORDER-TOP: #afc4d5 1px solid;
COLOR: #000000; CURSOR: none; FONT-FAMILY: tahoma,sans-serif; FONT-SIZE:
11px; HEIGHT: 19px; TEXT-DECORATION: none}
</style>
<%-- you could use logic:iterate --%>
		<% for(int i=0;i<max;i++) { %>
<br><input type="text" name="textoMensaje" size="<%=size%>"
maxlength="<%=maxLength%>" class="editMsg"
onkeypress="inputKeyPress(<%=i%>, this, event);">
		<% } %>

		<%-- this is the property that replaces the textarea
--%>
		<html:hidden property="elemento.adenda.MCStexto"/>
<script>
<!--
//detects keypressed on each row
function inputKeyPress(index, input, e) {
	var whichASCCan = (document.all?e.keyCode:e.which);
	if((whichASCCan==13 || input.value.length == <%=maxLength%>) &&
index < <%=max - 1%>) {
		document.forms['0'].textoMensaje[index+1].focus();
	}
}

//load text and splits in each row
function loadText() {
	var textoCompleto =
document.forms[0].elements['elemento.adenda.MCStexto'].value;
	var ind = 0;	
	var k2 = 0;
	var strAux = "";
	for(k=0;k<textoCompleto.length;k++) {
		strAux+=textoCompleto.charAt(k);
		k2++;
		if(k2>=<%=maxLength%>) {
	
document.forms[0].textoMensaje[ind].value=trim(strAux);
			strAux = "";
			ind++;
			k2=0;
		}
	}
	if(ind < <%=max%>)
		document.forms[0].textoMensaje[ind].value=strAux;
}

//collects all rows and append the result in the hidden value.
function saveText() {
	var textoCompleto =
document.forms[0].elements['elemento.adenda.MCStexto'];
	textoCompleto.value = "";
	for(k=0;k < <%=max%>;k++) {
	
textoCompleto.value+=padd(document.forms[0].textoMensaje[k].value,
<%=maxLength%>, ' ');
	}
	return true;
}

//it could be placed onload of body
loadText();
//-->
</script>

Cheers
Guillermo.

-----Original Message-----
From: Arne Brutschy [mailto:mai01cvr@studserv.uni-leipzig.de] 
Sent: Jueves, 29 de Enero de 2004 07:10 a.m.
To: Struts Users Mailing List
Subject: best way to handle an indexed property and a textarea


Hi all,

I want to use an indexed property with a textarea. Line 0 in the 
textarea should be array[0] etc. What is the best way to do this? Right 
now, I'm thinking about writing a custom tag, subclassing TextareaTag 
and splitting up the data something like value.split("\\r\\n"); Is there
a more simple way?

Regards,
Arne Brutschy



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org