开发者

Struts 1 bean tag inside HTML quotes

开发者 https://www.devze.com 2023-04-10 20:58 出处:网络
Here is my code: <html:text name=\"rptData\" property=\"emailAddress\" onblur=\"checkIfEmpty(\'<bean:write name=\"rptData\" property=\"status\" />\' , this.id)\" />

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 valu开发者_如何学JAVAe 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.


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.


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="abc@gmail.com" 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="abc@gmail.com" 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 !


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)"


Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消