You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lorrin Nelson <lh...@the-fam.net> on 2003/05/24 06:19:58 UTC

html:link with dynamic javascript confirmation

I have a table displaying a list of items, and on each row there is a 
"delete" link that pops up a confirmation dialog and then deletes the item. 
This works:

<c:forEach var="template" items="${templates}">
	<tr>
		<td><c:out value="${template.name}" escapeXml="true"/></td>
		<td>
			<html:link action="/user/template/delete"
				paramId="id" paramName="template" paramProperty="id"
				onclick="return confirm('Really?')">
				<fmt:message key="template.list.action.delete"/>
			</html:link>
		</td>
		</tr>
</c:forEach>

My problem is the hardcoded 'Really?' -- instead, I want to use a message 
resource and plug in the name of the item in the row, like so:
<fmt:message key="temple.delete.confirm"><fmt:param 
value="${template.name}"/></fmt:message>

That works fine if it's not inside the <html:link> tag, but inside the 
<html:link> it doesn't get parsed at all. In fact, if I do 'Really 
<%=4+4%>?' I don't even get 'Really 8', I get the unparsed text in the 
confirmation dialog..

Any suggestions? I'm not married to this approach; if I've gotta use 
old-skool Struts tags instead of JSTL or do it as a form instead of a 
html:link that's alright.

Thanks!

-Lorrin


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


Re: html:link with dynamic javascript confirmation

Posted by Lorrin Nelson <lh...@the-fam.net>.
Thanks David! That solved my problem and sounds like something I never 
would have figured out on my own..

-Lorrin

At 12:49 PM 5/24/2003, you wrote:
> >>>>> "Lorrin" == Lorrin Nelson <lh...@the-fam.net> writes:
>
>     Lorrin> I have a table displaying a list of items, and on each row 
> there is a "delete"
>     Lorrin> link that pops up a confirmation dialog and then deletes the 
> item. This works:
>
>
>     Lorrin> <c:forEach var="template" items="${templates}">
>     Lorrin>     <tr>
>     Lorrin>             <td><c:out value="${template.name}" 
> escapeXml="true"/></td>
>     Lorrin>             <td>
>     Lorrin>                     <html:link action="/user/template/delete"
>     Lorrin>                             paramId="id" paramName="template" 
> paramProperty="id"
>     Lorrin>                             onclick="return confirm('Really?')">
>     Lorrin>                             <fmt:message 
> key="template.list.action.delete"/>
>     Lorrin>                     </html:link>
>     Lorrin>             </td>
>     Lorrin>             </tr>
>     Lorrin> </c:forEach>
>
>     Lorrin> My problem is the hardcoded 'Really?' -- instead, I want to 
> use a message
>     Lorrin> resource and plug in the name of the item in the row, like so:
>
>     Lorrin> <fmt:message key="temple.delete.confirm"><fmt:param
>     Lorrin> value="${template.name}"/></fmt:message>
>
>     Lorrin> That works fine if it's not inside the <html:link> tag, but 
> inside the
>     Lorrin> <html:link> it doesn't get parsed at all. In fact, if I do 
> 'Really <%=4+4%>?' I
>     Lorrin> don't even get 'Really 8', I get the unparsed text in the 
> confirmation dialog..
>
>     Lorrin> Any suggestions? I'm not married to this approach; if I've 
> gotta use old-skool
>     Lorrin> Struts tags instead of JSTL or do it as a form instead of a 
> html:link that's
>     Lorrin> alright.
>
>Well, the simple fix is to understand that expression scriptlets have to 
>be the
>entire attribute value, not just a portion.  Instead of:
>
>   'Really <%=4+4%>?'
>
>you would need
>
>   '<%= "Really" + (4 + 4) + %>?'
>
>Alternatively, if you are using the nightly build of Struts, you could use the
>"Struts-EL" contrib library, which gives you the ability to reference EL
>expressions in the attributes of the Struts tags.
>
>--
>===================================================================
>David M. Karr          ; Java/J2EE/XML/Unix/C++
>dmkarr@earthlink.net   ; SCJP; SCWCD
>
>
>
>
>---------------------------------------------------------------------
>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


Re: html:link with dynamic javascript confirmation

Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Lorrin" == Lorrin Nelson <lh...@the-fam.net> writes:

    Lorrin> I have a table displaying a list of items, and on each row there is a "delete"
    Lorrin> link that pops up a confirmation dialog and then deletes the item. This works:


    Lorrin> <c:forEach var="template" items="${templates}">
    Lorrin> 	<tr>
    Lorrin> 		<td><c:out value="${template.name}" escapeXml="true"/></td>
    Lorrin> 		<td>
    Lorrin> 			<html:link action="/user/template/delete"
    Lorrin> 				paramId="id" paramName="template" paramProperty="id"
    Lorrin> 				onclick="return confirm('Really?')">
    Lorrin> 				<fmt:message key="template.list.action.delete"/>
    Lorrin> 			</html:link>
    Lorrin> 		</td>
    Lorrin> 		</tr>
    Lorrin> </c:forEach>

    Lorrin> My problem is the hardcoded 'Really?' -- instead, I want to use a message
    Lorrin> resource and plug in the name of the item in the row, like so:

    Lorrin> <fmt:message key="temple.delete.confirm"><fmt:param
    Lorrin> value="${template.name}"/></fmt:message>

    Lorrin> That works fine if it's not inside the <html:link> tag, but inside the
    Lorrin> <html:link> it doesn't get parsed at all. In fact, if I do 'Really <%=4+4%>?' I
    Lorrin> don't even get 'Really 8', I get the unparsed text in the confirmation dialog..

    Lorrin> Any suggestions? I'm not married to this approach; if I've gotta use old-skool
    Lorrin> Struts tags instead of JSTL or do it as a form instead of a html:link that's
    Lorrin> alright.

Well, the simple fix is to understand that expression scriptlets have to be the
entire attribute value, not just a portion.  Instead of:

  'Really <%=4+4%>?'

you would need

  '<%= "Really" + (4 + 4) + %>?'

Alternatively, if you are using the nightly build of Struts, you could use the
"Struts-EL" contrib library, which gives you the ability to reference EL
expressions in the attributes of the Struts tags.

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net   ; SCJP; SCWCD




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


Re: html:link with dynamic javascript confirmation

Posted by Lorrin Nelson <lh...@the-fam.net>.
I guess I could have said this more clearly by saying that I can do

<a href="/user/template/delete?id=<c:out value="${template.id}"/>"
       onclick="return confirm('<fmt:message 
key="template.list.action.delete.confirm">
       <fmt:param value="${template.name}"/></fmt:message>')">
     <fmt:message key="template.list.action.delete"/>
</a>

but I can't figure out how to do it with <html:link> instead.


At 09:19 PM 5/23/2003, you wrote:
>I have a table displaying a list of items, and on each row there is a 
>"delete" link that pops up a confirmation dialog and then deletes the 
>item. This works:
>
><c:forEach var="template" items="${templates}">
>         <tr>
>                 <td><c:out value="${template.name}" escapeXml="true"/></td>
>                 <td>
>                         <html:link action="/user/template/delete"
>                                 paramId="id" paramName="template" 
> paramProperty="id"
>                                 onclick="return confirm('Really?')">
>                                 <fmt:message 
> key="template.list.action.delete"/>
>                         </html:link>
>                 </td>
>                 </tr>
></c:forEach>
>
>My problem is the hardcoded 'Really?' -- instead, I want to use a message 
>resource and plug in the name of the item in the row, like so:
><fmt:message key="temple.delete.confirm"><fmt:param 
>value="${template.name}"/></fmt:message>
>
>That works fine if it's not inside the <html:link> tag, but inside the it 
>doesn't get parsed at all. In fact, if I do 'Really <%=4+4%>?' I don't 
>even get 'Really 8', I get the unparsed text in the confirmation dialog.. 
>Any suggestions? I'm not married to this approach; if I've gotta use 
>old-skool Struts tags instead of JSTL or do it as a form instead of a 
>html:link that's alright. Thanks! -Lorrin 
>--------------------------------------------------------------------- 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