简体   繁体   English

如何在ap:tooltip中的p:messages中放置换行符

[英]How do I put line breaks in p:messages in a p:tooltip

I am trying to put a line break between list of rules a password filed is supposed to have: 我试图在密码归档应该具有的规则列表之间插入换行符:

Hope this code would help you reproduce it on your local machines 希望这段代码可以帮助您在本地计算机上重现它

My JSF form looks like: 我的JSF表单如下所示:

<h:form id="passwordForm">
     <div class="form-group has-feedback">
        <p:password id="password1" value="#{testBean.password}"
                    required="true"
                    requiredMessage="This field cannot be left empty"
                    placeholder="Password">
        </p:password>
        <p:tooltip for="password1"  id="password1ToolTip"
                   hideEvent="focus"
                   rendered="#{not empty facesContext.getMessageList('passwordForm:password1')}"
                   position="right" hideEffect="fade" showEffect="fade">
            <p:message for="password1"/>
        </p:tooltip>
    </div>
</h:form>

This is how my bean looks: 这是我的豆子的样子:

@Named
@RequestScoped
public class TestBean implements Serializable {

    private static final long serialVersionUID = 2016821444602021904L;


    @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}", 
    message = "Password should contain minimum 8 characters, 1 Uppercase alphabet, 1 lower case alphabet and 1 special character")
    @Size(min = 8, message = "Password cannot be this short!")
    private String password;

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

}

Based on a few answers on SO I have tried modifying the validation message by introducing special entity codes &#13; 基于SO的一些答案,我尝试通过引入特殊实体代码&#13;来修改验证消息&#13; and [![&#10;][1]][1] as follows: [![&#10;][1]][1]如下:

Password should contain&#13;Minimum 8 characters&#13;1 Uppercase alphabet&#13;&#10; 1 lower case alphabet and 1 special character

Note: This attached image might not show up in a few browsers 注意:此附件图像可能不会在某些浏览器中显示 这是工具提示的外观

Why you're showing the message in an extra tooltip? 为什么要在额外的工具提示中显示该消息? Looks a bit strange. 看起来有点奇怪。

Anyway, what you need is a <br/> where you want the line break and set escape="false" in your p:message. 无论如何,您需要的是<br/>想要换行并在p:message中设置escape =“ false”的地方。

message: 信息:

Password should contain&#13;Minimum 8 characters&#13;1 <br/> Uppercase Password...

xhtml: xhtml:

<p:message for="password1" escape="false"/>

UPDATE1: UPDATE1:

Thanks to Parkash Kumar for the additional info to improve the answer. 感谢Parkash Kumar提供了更多信息来改善答案。

UPDATE2: UPDATE2:

You could also use CSS and /n for a line break, then you need to apply: 您还可以使用CSS和/n进行换行,然后需要应用:

#messages td { white-space: pre; }

to your CSS. 到您的CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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