HashimR
HashimR

Reputation: 3833

Struts 1 bean tag inside HTML quotes

Here is my code:

<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name="rptData" property="status" />' , this.id)" />

This is nested inside a logic:iterate tag. What i need to do, is to pass value of 'status' to the javascript checkIfEmpty method. But i guess there is some error in the quotes. It is not working properly. Please anyone guide me. Thanks.

Upvotes: 3

Views: 3595

Answers (4)

HashimR
HashimR

Reputation: 3833

ok after doing some research i found out the answer.

if i have some code like this:

<html:text styleId="emailAddress+<%=statusC.toString() %>" name="rptData" property="emailAddress" />

its output is as follows:

<input type="text" name="emailAddress" value="[email protected]" id="emailAddress+<%=statusC.toString() %>" />

but if i use

<html:text styleId="<%=statusC.toString() %>" name="rptData" property="emailAddress" />

the output is:

<input type="text" name="emailAddress" value="[email protected]" id="Approved" />

That means without string concatenation the output is correct. i.e. only using

styleId="<%=statusC.toString() %>"

rather then

styleId="emailAddress + <%=statusC.toString() %>"

or even

styleId="emailAddress" + <%=statusC.toString() %> - This results in an error, though

yeilds correct output.

So the workaround is to first intialize a complete java String in a scriplet then use it inside the styleId tag.

<% String emailId =  "emailAddress" + statusC.toString()  ;%>
<html:text styleId="<%=emailId%>" name="rptData" property="newEmailAddress" />

It will work fine. Cheers !

Upvotes: 1

Dave Newton
Dave Newton

Reputation: 160191

You can't nest custom tags like that, period, and it's unfortunate most of the answers imply you can, because that represents a fundamental misunderstanding of JSP.

Ideally, you wouldn't use the <logic:iterate> tag, as its use is not recommended when you have JSTL available: when JSTL and Struts 1 tag functionality overlaps, use the JSTL option. Then use standard JSP EL to access the variable.

<c:forEach items="listOfThings" var="current">
  ...
  <html:text ... onblur="checkIfEmpty('${rptData.status}', ${current.id})" ...
  ...

In this example I also assumed that this was supposed to refer to the current iteration object, defined in the <c:forEach> tag.

Upvotes: 1

linkamp
linkamp

Reputation: 215

Try this:

<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name=\'rptData\' property=\'status\' />' , this.id)" />

Upvotes: 0

Umer Hayat
Umer Hayat

Reputation: 2001

You might want to try adding some escape characters while using double quotes inside double quotes like in your case it would be some like:

onblur="checkIfEmpty('<bean:write name=\"rptData\" property=\"status\" />' , this.id)"

Upvotes: 0

Related Questions