• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java string question

Hi Guys,

I'm working with an OpenSource POS system and I need to mod some code. I'm pretty good with CFML, but I don't know much about Java.

When receipts are printed, there is one variable which displays a list of attributes linked to an item on the ticket.

1x Cheeseburger
medium well, no cheese, fries, salad

The attributes are the things under the cheeseburger. The attributes for each item on a ticket are kept within a single column as one string.

aka 'medium well, no cheese, fries, salad'

I can't mod this process of combining it all into one string because it would break too many other things and I don't have the time nor will to dive into it like that. So I'm looking at another method.

There is a line of code in the receipt script that displays this string. The problem is, the receipt is only so wide, and if the attributes string is longer than what can be printed, it just gets cut off. there is no word wrap.

Here is the code that displays the attributes.

<line>
<text align="left"> ${ticketline.productAttSetInstDesc}</text>
</line>

${ticketline.productAttSetInstDesc} is the code that displays the attribute string


I'm not good with Java code. but I understand programming.

What I'm thinking would be the easiest fix would be to simply test if the string is longer than X amount of characters, and if so, break the string into two/three parts, and display them.

aka

#if length(${ticketline.productAttSetInstDesc}) gte 45

#set attributestringA = #first 45 of ${ticketline.productAttSetInstDesc}
#set attributestringB = #second block of 45 characters of ${ticketline.productAttSetInstDesc}
#set attributestringC = #third block of 45 characters of ${ticketline.productAttSetInstDesc}

<line>
<text align="left"> ${attributestringA}</text>
</line>

<line>
<text align="left"> ${attributestringB}</text>
</line>

<line>
<text align="left"> ${attributestringC}</text>
</line>

#else

<line>
<text align="left"> ${ticketline.productAttSetInstDesc}</text>

</line>

#end

Granted, I don't know the syntax to count string characters, etc.. so I just put logic in.

Can somebody look at this and tell me if my logic is ok, and if so, perhaps tell me the correct syntax to make this work??
 
I'm wondering too.. lol. I know the source is JAVA, but I'm starting to think the script they use in the template is not.
 
I'm wondering too.. lol. I know the source is JAVA, but I'm starting to think the script they use in the template is not.

1. I think this is an instance of the very common Javascript-is-not-java issue.
2. Anyone who orders a cheeseburger without cheese deserves whatever failure the system throws at them.
Code:
public class Cheeseburger throws NoCheeseException
 
1. I think this is an instance of the very common Javascript-is-not-java issue.
2. Anyone who orders a cheeseburger without cheese deserves whatever failure the system throws at them.
Code:
public class Cheeseburger throws NoCheeseException

No it's not. I know some javascript.. enough to tell.

I talked to a dev in the opensource project and he said it's a hybrid scripting language
 
No it's not. I know some javascript.. enough to tell.

I talked to a dev in the opensource project and he said it's a hybrid scripting language

If your 'hybrid scripting language' has the syntax to split strings into segments, then your logic is correct for doing so -- provided you don't mind splitting mid-word.

Another option would be to put a newline into each possible substring, possibly preceded by a couple spaces, for clarity. E.g., make your receipt look like:
Code:
1x Cheeseburger
  Medium well
  No cheese :(
  Extra pickles
I.e., make the actual string:
Code:
"1x Cheeseburger\n  Medium well\n  No cheese :(\n  Extra pickles"
On the plus side, you might not have to modify the printing code (which might not be possible in your 'hybrid scripting language') ... just the strings themselves.
 
Back
Top