Hi Ute,
I would recommend you split up your JavaScript into separate files as well, but
if you ABSOLUTELY have to write a property value inside a Struts tag, the best
way to do that is probably through an OGNL or JSTL expression. In your case,
you can replace the s:property tag inside the onclick by %{id} or ${id} and it
probably should work. I am unable to test your exact case, but I have such
expressions inside my own code and they work fine.
But again, I would strongly recommend you split your JavaScript into a separate
file. If there are any properties you need to populate from server values, you
can put those in a separate script tag inside the head of your page using
s:property tags:
<script>
var jsProperty = <s:property value="id" />;
</script>
Nate
-----Original Message-----
From: Dave Newton <[email protected]>
Sent: Friday, 6 June 2025 15:58
To: Struts Users Mailing List <[email protected]>
Subject: Re: struts-tag property in javascript
On Fri, Jun 6, 2025 at 09:14 Ute Kaiser <[email protected]> wrote:
> Hi,
> migrating from Struts1 I encounter in a jsp the error "Equal symbol
> expected" at the "onclick" row.
> I think my old quotes do not work any more with Struts2.
>
> Struts1:
> <logic:iterate id="b" name="blabla" scope="request">
> <input type="button" value="Delete"
>
> onclick="javascript:if(confirmDelete()){document.getElementById('delet
> eid').value='<bean:write
> name="b" property="id" />';}"/>
>
> Struts2:
> <s:iterator value="blabla">
> <s:submit type="input" value="Delete"
>
> onclick="javascript:if(confirmDelete()){document.getElementById('delet
> eid').value='<s:property
> value="id"/>';}"/>
>
> I tried 'id', \"id\", \'id\' "id" but nothing worked out
This would be double-evaluation, JSP doesn’t work like this—tags can’t used as
property values. But you should be able use standard JSP EL iirc.
That said, I’d take the opportunity to clean up JSPs and JS since you’re
rewriting everything anyway and split up the JS and markup if you’re not also
migrating the front end away from JSP.
Dave