2014-08-28 55 views
0

我正在使用JSF。如何通過bean在jsf頁面中插入空間

我想在某些文本前插入一個空格,但它不起作用。

例:max_lenght = 8
字符串爲 「120.00」
的出認沽將成爲 「    120.00」
但它給 「120.00」 只有

我知道,使用&# 160;我們將增加空間,但我想通過bean添加。

Java代碼的

this.without_health_insurance_total_amount_as_String = d.format(this.without_health_insurance_total_amount); 
     if (this.without_health_insurance_total_amount_as_String.length() < max_lenght) { 
      this.without_health_insurance_total_amount_as_String = append_String(this.without_health_insurance_total_amount_as_String, max_lenght); 
     } 
public String append_String(String source, int max_lenght) { 
     for (; source.length() < max_lenght;) { 
      source = new String(new StringBuffer(" ").append(source)); 
      System.out.println(source); 
     } 
     return source; 
    } 

XHTML:可

<h:outputText value="#{paymentreceipt.without_health_insurance_total_amount_as_String}" /> 

enter image description here

我想量打印到以下格式:

1,779.99
      220.01
2,000.00

讓我通過輔助bean(上面的代碼)將3位爲220.01。

+0

你試過逐字? http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_verbatim.html – Leo 2014-08-28 11:32:38

+0

感謝您的快速回復..我沒有這樣做,讓我試試... – user2314868 2014-08-28 11:51:58

+0

不,它不工作... – user2314868 2014-08-28 11:54:23

回答

1

在你的bean

private String with = "&nbsp;&nbsp;xxx"; 
private String without = "xxx"; 

在你的XHTML

<h:panelGrid columns="2"> 
    <h:outputText value="Without spaces:"/> 
    <h:outputText value="#{myMB.without}" escape="false"/> 
    <h:outputText value="With spaces:"/> 
    <h:outputText value="#{myMB.with}" escape="false"/> 

    <p:commandButton value="Enter" /> 
</h:panelGrid> 

給我

enter image description here

+1

謝謝@Leo,它工作正常... – user2314868 2014-08-30 05:47:00