This is a simple yet weird one. I have an app that uses a setting to create a string, which then gets put into a rich text box. sounds simple right? But for some weird reason i'm getting an extra line break. Simple example :
if i do this :
head = "Some text :" + " some other text"
richtextbox.AppendText(head)
the output is
Some text : some other text"
as you would expect. but if the app does the following :
my.settings.variable1 = " some other text"
head = "Some text :" + my.settings.variable1
richtextbox.AppendText(head)
the output is
Some text :
some other text"
ie with a line break i never specified. It's not a word wrap or tab issue as i've tried every variation under the sun to eliminate those possibilities. any ideas?
**** EDIT ********
I have narrowed down the cause but still makes little sense. The cause is the setting i am using to provide part of the string. the actual code in my app is :
head = "Your Server : " + My.Settings.Server + "....Bill#" + My.Settings.BinNo
which somehow puts a line break after my.settings.server. However if i have the exact same line but change the code to :
head = "Your Server : " + My.Settings.BinNo + "....Bill#" + My.Settings.BinNo
I no longer see the problem. Bizarre, but progress. Still can't figure out why. Both are string variables, both are same length....
Found the problem. It was strange but simple. There was a recursive bit of code earlier in the module that formatted the string before assigning it to the server setting. It was meant to check the length of the string and pad it to a certain length. However it went awry and added a whole bunch of spaces on the end, so at the end of it all it was not a line feed that made it go to the next line, it was simple word wrap and invisible space characters pushing the text to the right. simple but annoying to find. thanks for the help guys
Related
ASP.NET Core 3.1
I have the following code in my View:
<span asp-validation-for="NewPassword" class="text-danger"></span>
If I type in a password, such as 'a', I get multiple errors back. I want to display them in that span ONE PER LINE.
In my Controller I have the following:
var descriptions = string.Empty;
foreach (var error in errors)
descriptions += error.Description + "<br />";
ModelState.AddModelError("NewPassword", descriptions);
But this does not translate the "br" tags and they get displayed as if they were part of one very long single error message.
Note: Adding them one at a time into the ModelState simply overwrites the previous, leaving only the last one displayed.
Instead of "br", i've tried HTMLString.NewLine and Environment.NewLine but none of these work. I could write a loop in my View, but is there a preferred way in ASP.NET Core?
So my question is: How can I put a new line between each description?
Instead of "br", i've tried HTMLString.NewLine and Environment.NewLine but none of these work.
That's because <br/> will be escaped by default. If you wish, you could use #Html.Raw() to generate the raw content without escaping the dangerous characters. But I don't think it's a good idea: there will be a high risk of XSS if you output a raw string directly.
By default, \r\n won't be displayed in browser. You need a CSS snippet to show a new line.
A much better way is to use the CSS to control the display style: add a style for the validation field in your *.css file:
span.field-validation-error{
white-space: pre-line;
}
And change the csharp code to use a \n as separator:
foreach (var error in errors)
descriptions += error.Description + "\n";
Demo :
My reports preview is ok.
But now, I need to export to pdf...and I've got an issue : the content of some cells are truncated to the witdh of the column.
For instance, 1 cell should display "BASELINE"...in the preview it's ok...but in pdf, it displays "BASEL".
I've been looking for a solution the whole day and did not find anything...
Of course : I don't want to fit the width of the column on the length of this word "BASELINE" because the content is dynamic...
Instead, I want to fix the column width and then, the cell should display something like that :
BASEL
INE
Any idea ?
Thanks in advance (am a little bit desperated...)
The solution is trivial in BIRT v4.9 if you've integrated the engine into your java code. Just set the PDF rendering options.
RenderOption options = new PDFRenderOption();
options.setOutputStream(out);
options.setOutputFormat("pdf");
options.setOption(PDFRenderOption.PDF_WORDBREAK, true);
options.setOption(PDFRenderOption.PDF_TEXT_WRAPPING, true);
task.setRenderOption(options);
You have to set a special PDF emitter option:
PDFRenderOption options = new PDFRenderOption();
options.setOption(PDFRenderOption.PDF_HYPHENATION, true);
This is if you integrated BIRT into your Java program.
For the viewer servlet, it is possible to set such options, too, AFAIK, but I don't know how; maybe on the URL or using environment variables.
I had the same issue. I found a very good topic about that : http://developer.actuate.com/community/forum/index.php?/topic/19827-how-do-i-use-word-wrap-in-report-design/?s=173b4ad992e47395e2c8b9070c2d3cce
This will split the string in the given number of character you want :
The function to add in a functions.js (for example). To let you know, I create some folder in my report project : one for the reports, one for the template, one for the libraries, another for the resources, I added this js file in the resources folder.
/**
* Format a long String to be smaller and be entirely showed
*
*#param longStr
* the String to split
*#param width
* the character number that the string should be
*
*#returns the string splited
*/
function wrap(longStr,width){
length = longStr.length;
if(length <= width)
return longStr;
return (longStr.substring(0, width) + "\n" + wrap(longStr.substring(width, length), width));
}
You will have to add this js file in the reports : in the properties -> Resources -> Javascript files
This is working for me.
Note: you can add this function in your data directly if you need only once...
The disadvantage of this : you will have to specify a max length for your character, you can have blank spaces in the column if you specify a number to small to fill the column.
But, this is the best way I found. Let me know if you find something else and if it's working.
I am trying to make a prompt for the user to select from the figure (plot).
When I run it with the code below, the prompt doesnt display until i click on the figure, after which the prompt displays and the code continues. In fact, no call to printf (or disp) that is called before the ginput call displays until i select the figure.
printf("Select part\n"); % (disp also doesnt work properly)
[xinput,yinput] = ginput(1);
The purpose of the prompt is to alert the user to move to the figure, so naturally it needs to display before selecting the figure.
I can add an extra redundant input call between the two which forces the printf to display in the console. eg input("Press Enter"). but this is an inconvenient solution.
Strangely, if you run just the code above it does work normally. But when running in the remainder of the program it displays the issue. So it may be a difficult one to debug. Also, running it one line at a time in the full code using the debugger works properly, displaying the prompt before selecting the figure.
Just to add to the confusion. When running this part of the program in a loop, the first instance doesnt display the prompt correctly, but every other instance it works.
Thanks
EDIT:
The following code reliably fails (for me) in the same way my full program fails; (edited again to simplify)
figure(1);
input_test = input("press 1: ");
switch input_test
case 1
while true
clc;
printf("Left click to get coords or right click to finish\n");
[xinput,yinput,mouse_button] = ginput(1)
if mouse_button == 3
break
endif
endwhile
endswitch
It appears it has something to do with the line;
input_test = input("press 1: ");
If I replace this with
input_test = 1;
it works properly.
I dont know what is the reason for this, and I cannot remove the input request from this location.
Thanks Roger, you were correct, I did find a solution.
Using
fflush(stdout)
before the 'ginput' call solves the problem.
Found this in the 'input' help;
"Because there may be output waiting to be displayed by the pager,
it is a good idea to always call 'fflush (stdout)' before calling
'input'. This will ensure that all pending output is written to
the screen before your prompt."
So I'm trying to use docx4j. I made a simple template, use that and replace th value programmatically.
Here's my docx template.
My Name is «myName»
I’m «myAge» years old.
My address is «myAddress»
When I click toggle field codes it looks like this.
My Name is {MERGEFIELD myName \* MERGEFORMAT}
I’m {MERGEFIELD myAge \* MERGEFORMAT} years old.
My address is {MERGEFIELD myAddress \* MERGEFORMAT}
I do not know the use of MERGEFIELD but I tried to use it simply because that's what the post in the internet currently use.
Here's my code.
def config = grailsApplication.config.template.invoiceSample as Map
def String templateFileName = "${grailsApplication.config.template.dir}/${config.doc.templateFileName}"
WordprocessingMLPackage template = WordprocessingMLPackage.load(new File(templateFileName));
Map<DataFieldName, String> map = new HashMap<DataFieldName, String>();
map.put(new DataFieldName("#myName"),"Jean");
map.put(new DataFieldName("#myAge"),"30");
map.put(new DataFieldName("#myAddress"),"Sampaloc");
org.docx4j.model.fields.merge.MailMerger.setMERGEFIELDInOutput(MailMerger.OutputField.KEEP_MERGEFIELD);
org.docx4j.model.fields.merge.MailMerger.performMerge(template, map, false);
template.save(new File("C:/temp/OUT_SIMPLE.docx") );
However, It doesn't replace the value in the output file. Could you tell me what is wrong with my code?
I found out that this problem is just easy to fix.
Basically this line affects the output.
MailMerger.setMERGEFIELDInOutput(MailMerger.OutputField.KEEP_MERGEFIELD);
Based on my observation, these options do the following:
MailMerger.OutputField.KEEP_MERGEFIELD - replace the field with value but you need to click toggle field codes to reveal it.
MailMerger.OutputField.REMOVED - the codes will be gone but most importantly the value will be replaced without the need to click toggle field codes
MailMerger.OutputField.AS_FORMTEXT_REGULAR - I honestly don't know what it does, it just shows {FORMTEXT} in the word.
MailMerger.OutputField.DEFAULT - does the same thing with REMOVED.
Please feel free to update my answer if you think i've said something wrong.
I am going to a field, entering text, saving it, then going back to verify the value is still in the field.
$I->waitForText is not working. Not sure why. I am trying the following but getting the error below:
$I->canSeeInField("//form[#id='Foo']/table/tbody/tr[3]/td[3]/textarea", "123");
Sorry, I couldn't see in field "//form[#id='Foo']/table/tbody/tr[3]/td[3]/textarea","123":Failed asserting that two strings are equal.
Any ideas?
Thanks
If you are using WebDriver, you can just debug your page using makeScreenshot()
You can just use:
$value = $I->grabFromField('//form[#id='Foo']/table/tbody/tr[3]/td[3]/textarea');
and fill other fill with your value:
$I->fillField('#your_field_id', $value);
and than, just make a screenshot:
$I->makeScreenshot('name_of_your_screenshot');
Now check your debug folder with your image.