简体   繁体   中英

how to put an apostrophe in my message resource without breaking the javascript confirm?

I'm using JSF2 (Primefaces 2.x, and GlassFish 3.1.x).

I have a 'delete' button with a javascript confirmation.

<p:commandButton ajax="false" value="#{msg.common_delete}"
  action="#{profileHandler.doDelete}"
  onclick="return confirm('#{msg.profile_confirmDeleteMessage}')"
  immediate="true"
/>

The problem is the message in the resource bundle has an apostrophe. Like "Are you sure you want to delete the user's profile?"

The apostrophe is breaking the javascript so the confirmation message never appears, the button just does the delete.

I tried changing the text in the message bundle to ' and ' but neither worked; I just see the "'" in the message.

Any help is greatly appreciated!

Rob

您可以尝试在邮件属性文件中的'字符前添加\\'。

Does JSF2 allow single quoted attributes? If so, you can try switching out the outer qutoes to be single quotes and the inner ones to be double quotes. That way js shouldn't get confused.

onclick='return confirm("#{msg.profile_confirmDeleteMessage}")'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM