Multiple file upload(stripes) - file-upload

I am trying to make a file upload that will accept multiple files using the stripes framework. I have a single file upload working. I am trying to understand the Documentation for multiple file upload.
According to the doc, all I need to do is modify single file example to:
<stripes:form>
<c:forEach ... varStatus="loop">
...
<stripes:file name="newAttachments[${loop.index}]"/>
...
</stripes:form>
ActionBean
private List<FileBean> newAttachments;
public List<FileBean> getNewAttachments() {
return this.newAttachments;
}
public void setNewAttachment(List<FileBean> newAttachments) {
this.newAttachments = newAttachments;
}
What do I need to replace the ...(in particular, the one in the forEach loop) with to get this example working? Thanks.

Probably that should work:
<c:forEach begin="1" end="3" varStatus="loop">
see Tag forEach doc

Related

Apache Camel Read only First Line

I have a requirement where in i have to push files on directories dynamically based on their contents.
The information related to the directory is available in the first line of the File.
As the files are very large in size, loading the entire contents of the file will not be suitable.
Also i want to skip the rest of the file once the first line is read. Following is the code that i have written
from("file:D:\\camel\\input?recursive=true&delete=true")
.split().tokenize("'",1)
.process(new CustomProcessor())
.to("file:D:\\camel\\output\\${header.foldername}");
The issue with the approach is that camel parses the entire file. Also the destination gets only the line that is being tokenized at the output folder rather than the entire file contents.
Please assist
thanks #claus and #Souciance for your feedback. Actually i had another challenge many of the files i received did not have '\n' or '\r' as delimiter hence even reading a single like could be like reading the entire file. I implemented the solution using the scanner with delimiter as follows.
My Router is defined as follows
#Override
public void configure() throws Exception {
from("file:D:\\camel\\input?recursive=true&delete=true")
.process(new CustomProcessor())
.recipientList(header("foldername"));
}
Processor Code is
#Override
public void process(Exchange exchange) throws Exception {
File data = exchange.getIn().getBody(File.class);
Scanner sc = new Scanner(data,"UTF-8");
sc.useDelimiter("'");
String folderPath="";
while (sc.hasNext()){
String line = (String) sc.next();
//business logic
break;
}
sc.close();
String destDir = "file:D:\\camel\\output\\"+folderPath;
exchange.getIn().setHeader("foldername",destDir);
}

Prestashop: duplicate Invoice PDF with new tpl

How can I duplicate the Generate Invoice PDF Process in Prestashop? I want to use a different tpl file, but the rest should stay the same.
Let me explain, what I already did:
HTMLTemplateInvoice as HTMLTemplateMahnung and changed Class Name.
Added: const TEMPLATE_MAHNUNG = 'Mahnung'; to the file classes/pdf/PDF.php
Created file mahnung.tpl in root/pdf folder
Added to AdminPdfController.php:
public function processGenerateMahnungPdf() {
if (Tools::isSubmit('id_order')) {
$this->generateMahnungPDFByIdOrder(Tools::getValue('id_order'));
} elseif (Tools::isSubmit('id_order_invoice')) {
$this->generateInvoicePDFByIdOrderInvoice(Tools::getValue('id_order_invoice'));
} else {
die(Tools::displayError('The order ID -- or the invoice order ID -- is missing.'));
}}
AND
public function generateMahnungPDFByIdOrder($id_order)
{
$order = new Order((int)$id_order);
if (!Validate::isLoadedObject($order)) {
die(Tools::displayError('The order cannot be found within your database.'));
}
$order_invoice_list = $order->getInvoicesCollection();
Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $order_invoice_list));
$this->generatePDF($order_invoice_list, PDF::TEMPLATE_MAHNUNG);
}
But it's not working. It just doesn't generate the PDF.
Any help?
UPDATE
I had to include the class: require_once _PS_ROOT_DIR_ . '/classes/pdf/HTMLTemplateMahnung.php';
Now its working. Anybody knows why I had to this? I don't see any includes of Core Files :S
Pretashop uses the file cache/class_index.php to keep track of the classes it needs.
Everytime you add a new override, or even a class or controller, you need to delete (or rename) this file. If it doesn't find it, Prestashop will recreate indexing all files in set folders (classes, controllers, overrides, and others).

Submit data along with File Upload

I am trying to post form data (such as textbox, checkbox etc) along with a File Upload . I am using MVC.
Any one give me a solutions?
There are so many ways to do it with MVC, with strong-typed as suggested above or this way also would work
[HttpPost]
public JsonResult CreateUpdate(FormCollection _formValues, YourModel _extraItem)
{
HttpPostedFileBase files = HttpContext.Request.Files;
//do whatever u wish with ure files here
}
hope it helps
Your Post Controller will look like this :
[HttpPost]
public ActionResult YourController(YourModel model1, HttpPostedFileBase file)
{
if (file != null)
{
//here file variable will have the file which you have uploaded
}
}
HttpPostedFileBase contains the file which you have posted from View.
and in your view BeginForm() should look like :
Html.BeginForm(action, controller, FormMethod.Post, new { enctype="multipart/form-data"})
i use XMLHttpRequest to resolve this solution. Thanks everyone so much :D

Can't get data from a static array in HelperAdmin

I have a file/class::method (HelperAdmin.php/HelperAdmin::menuItem()) which extracts data from DB to generate main menu and submenu.
I have to get this data after the menu being generated but I don't want to call this method twice.
So I have created a static array in HelperAdmin class. It looks like this:
class HelperAdmin {
static $arrMenuItems;
...
public static function menuItem() {
....get $items....
self::$arrMenuItems = $items;
return $items;
}
....
}
But here is a problem. If I call the METHOD again:
$items=HelperAdmin::menuItem();
...I can get data.
In other hand if I try to get data through a static array:
$items=HelperAdmin::$arrMenuItems;
...it just returns null.
I hope to see some ideas. After all, if your opinion is that using static variable here (from Yii architecture view) is not the best solution, I'd like to get your advice!
#bool.dev:
OK, imagine the following scheme:
1. We have the main file
/modules/admin/views/layouts/admin.php
which is in essence our backend template.
2. We have the helper here:
/modules/admin/components/HelperAdmin.php
which contains:
* a class HelperAdmin,
* menuItem() method and
* a class static array $arrMenuItems.
A content of this ARRAY returned by calling HelperAdmin::menuItem().
We want get data from the HelperAdmin class twice:
1. While generating a menu in admin.php;
2. As part of content which we get with variable $content putting it at this file.
$content in turn is generated in another file:
/modules/admin/views/generator/index.php
So as you can see, our page compounds itself from the template file /modules/admin/views/layouts/admin.php and data ($content) getting from /modules/admin/views/generator/index.php.
First I get data for menu:
HelperAdmin::menuItem();
$items=HelperAdmin::$arrMenuItems;
$this->widget(....
'items'=>$items,
...),
));
That's OK. Notice that after this a static array $arrMenuItems already is generated in HelperAdmin.
Next I'm trying to get the same data ($arrMenuItems generated earlier) in file /modules/admin/views/generator/index.php to place it as $content:
$items=HelperAdmin::$arrMenuItems
And here I can't get it as described above.
Well, I hope it made a situation more clear (?).

dynamic file path in log4php

I am new to log4php.
I would like to save the log files in the format /logs/UserId/Info_ddmmyyyy.php
where the UserId is dynamic data.
(I would basically like to save one log per user.)
Is there any way to change the log file path dynamically?
This behaviour is not supported by default. But you can extend LoggerAppenderFile (or RollingFile, DailyFile whatever your preference is) to support it.
Create your own class for that and make it load to your script.
Then extend from this class:
http://svn.apache.org/repos/asf/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
class MyAppender extends LoggerAppenderFile { ... }
You'll need to overwrite the setFile() method, similar to:
public function setFile($file) {
$path = getYourFullPath();
$this->file = $path.$file;
}
After all you need to use your new Appender in you config
log4php.appender.myAppender = MyAppender
log4php.appender.myAppender.layout = LoggerLayoutSimple
log4php.appender.myAppender.file = my.log
Please note, instead of giving your full path to the log file you now need to add a plain name. The full path (including username) must be calculated with your getYourFullPath() method.
Hope that helps!
Christian