user2314868
user2314868

Reputation: 129

how to insert space in jsf page through bean

I am working with JSF.

I want to insert a space before some text, But it is not working.

Ex: max_lenght =8
The String is "120.00"
The out put will become "  120.00"
But it is giving "120.00" only

I know that using &#160 ; we will add space, but i want to add through bean.

Java Code

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

I am trying to print the amount to below format:

1,779.99
   220.01
2,000.00

So i am adding 3 spaces for 220.01 through backing bean(above code).

Upvotes: 0

Views: 930

Answers (1)

Leo
Leo

Reputation: 6570

In your bean

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

In your 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>

gives me

enter image description here

Upvotes: 1

Related Questions