[英]How do I put line breaks in p:messages in a p:tooltip
我試圖在密碼歸檔應該具有的規則列表之間插入換行符:
希望這段代碼可以幫助您在本地計算機上重現它
我的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>
這是我的豆子的樣子:
@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;
}
}
基於SO的一些答案,我嘗試通過引入特殊實體代碼
來修改驗證消息
和[![ ][1]][1]
如下:
Password should contain Minimum 8 characters 1 Uppercase alphabet 1 lower case alphabet and 1 special character
為什么要在額外的工具提示中顯示該消息? 看起來有點奇怪。
無論如何,您需要的是<br/>
想要換行並在p:message中設置escape =“ false”的地方。
信息:
Password should contain Minimum 8 characters 1 <br/> Uppercase Password...
xhtml:
<p:message for="password1" escape="false"/>
UPDATE1:
感謝Parkash Kumar提供了更多信息來改善答案。
UPDATE2:
您還可以使用CSS和/n
進行換行,然后需要應用:
#messages td { white-space: pre; }
到您的CSS。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.