0

I got a string buffer which I then put into a bean and call on a webpage with JSTL. I want it to output something like 10/10/1987 (23 years). The first example doesn't return anything and the second example does.

patAge.append(" ")
      .append("(")
      .append(patientDetails.getAge())
      .append(" ")
      .append(bpt.get("BPT_YRS"))
      .append(")");

output: 10/10/1987

patAge.append(" ")
      .append("{")
      .append(patientDetails.getAge())
      .append(" ")
      .append(bpt.get("BPT_YRS"))
      .append(")");

output: 10/10/1987 {23 years)

patAge.append(" ")
      .append(patientDetails.getAge())
      .append(" ")
      .append(bpt.get("BPT_YRS"))
      .append(")");

output: 10/10/1987 23 years)

It seems that the left open parenthesis causes that it doesn't work.

1
  • 1
    Not because of anything that's apparent from your question. There must be something else going on. Post more or your code and maybe the problem will be clearer.
    – Asaph
    Feb 14, 2011 at 16:25

2 Answers 2

2

For readable code, I recommend to switch to MessageFormat.

This is the default example:

Object[] arguments = {
         new Integer(7),
         new Date(System.currentTimeMillis()),
         "a disturbance in the Force"
     };

String result = MessageFormat.format(
         "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
         arguments);

output: At 12:30 PM on Jul 3, 2053, there was a disturbance in the Force on planet 7.

So you separate the variables from your message.

1

It looks like there is an synax error in your fist statement: the append((") (2. append) looks strange.

I belive it should be:append("(") (one more ")

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.