form fixes

This commit is contained in:
Peter Schojer
2008-08-28 06:02:11 +00:00
parent cdab287496
commit 716d71c833
10 changed files with 90 additions and 3 deletions

View File

@@ -41,6 +41,7 @@ namespace Poco {
namespace WebWidgets {
const std::string Form::FORM_ID("__form__");
const std::string Form::METHOD_GET("GET");
const std::string Form::METHOD_POST("POST");
const std::string Form::ENCODING_URL("application/x-www-form-urlencoded");

View File

@@ -41,9 +41,11 @@
#include "Poco/WebWidgets/Page.h"
#include "Poco/WebWidgets/RenderContext.h"
#include "Poco/WebWidgets/RequestProcessor.h"
#include "Poco/WebWidgets/SubmitButtonCell.h"
#include "Poco/WebWidgets/WebWidgetsException.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/NumberParser.h"
#include "Poco/URI.h"
#include "Poco/ThreadLocal.h"
#include <sstream>
@@ -90,6 +92,11 @@ void RequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
{
handleForm(form);
}
Poco::Net::NameValueCollection::ConstIterator it = form.find(Form::FORM_ID);
if (it != form.end())
{
_pApp->notifySubmitButton(Poco::NumberParser::parse(it->second));
}
handlePageRequest(request, response);
}
else
@@ -144,7 +151,12 @@ void RequestHandler::handleAjaxRequest(Poco::Net::HTTPServerRequest& request, Po
response.send();
return;
}
SubmitButtonCell* pCell = dynamic_cast<SubmitButtonCell*>(pProc);
if (pCell) // hide click event from submitbuttons
{
response.send();
return;
}
try
{
pProc->handleAjaxRequest(args, response);

View File

@@ -36,8 +36,11 @@
#include "Poco/WebWidgets/WebApplication.h"
#include "Poco/WebWidgets/RequestProcessor.h"
#include "Poco/WebWidgets/SubmitButtonCell.h"
#include "Poco/WebWidgets/WebWidgetsException.h"
#include "Poco/Net/HTMLForm.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/NumberFormatter.h"
namespace Poco {
@@ -119,6 +122,16 @@ RequestProcessor* WebApplication::getFormProcessor(const std::string& fieldName)
void WebApplication::registerAjaxProcessor(const std::string& id, RequestProcessor* pProc)
{
SubmitButtonCell* pCell = dynamic_cast<SubmitButtonCell*>(pProc);
if (pCell)
{
Form::Ptr pForm = insideForm(pCell->getOwner());
if (!pForm)
throw Poco::WebWidgets::WebWidgetsException("submitButton without outer Form detected");
std::pair<SubmitButtons::iterator, bool> res = _submitButtons.insert(std::make_pair(pForm->id(), pCell));
if (!res.second)
res.first->second = pCell;
}
std::pair<RequestProcessorMap::iterator, bool> res = _ajaxProcessorMap.insert(std::make_pair(id, pProc));
if (!res.second)
res.first->second = pProc;
@@ -158,4 +171,31 @@ void WebApplication::handleForm(const Poco::Net::HTMLForm& form)
}
void WebApplication::notifySubmitButton(Renderable::ID id)
{
SubmitButtons::iterator it = _submitButtons.find(id);
if (it == _submitButtons.end())
throw WebWidgetsException("failed to find submitButton with id " + Poco::NumberFormatter::format(id));
it->second->buttonClicked(this);
_submitButtons.erase(it);
}
Form::Ptr WebApplication::insideForm(const View* pChild)
{
Form::Ptr ptr;
while (pChild && !ptr)
{
View::Ptr ptrView = pChild->parent();
ptr = ptrView.cast<Form>();
pChild = ptrView;
}
return ptr;
}
} } // namespace Poco::WebWidgets