Re: [Cppcms-users] working with http::context.
Brought to you by:
artyom-beilis
|
From: Artyom <art...@ya...> - 2010-08-24 13:07:33
|
>
> I've been trying to work with http::context but with no success.
>
> I am working with forms. During the validation process, I want to set some
> messages to display to the user.
>
> I have seen widgets::base_widget::error_message() but this is not what I
need.
>
> I want to:
> 1) be able to set errors for the *whole* form, not a specific widget.
> 2) be able to set various messages that are valid only within a specific
> context (http get/post request).
If entry form fails validation you may just display any message you want
outside widgets system. i.e.
if(request().request_method()=="POST") {
my_content.my_form.load(context());
if(!my_content.my_form.validate()) {
my_content.fail_flag = true;
}
}
And in template system itself
<% if fail_flag %>
<strong>FAILED</strong>
<% end %>
<form ... >
<% form as_p my_form %>
</form>
See example of forms. Also you can specify a number of reasons
and add some flag to form you are created.
>
> If I understand well, I cannot set those message within my cppcms::application
>
> namespace, since it is shared between all processes, regardless of user or
> sessions (?). Thus a message intended for one user might be displayed for
> another user.
>
> I could use the user session, but a message intended for one page (form
> submission() might appear on another tab, as the user browses other pages
> within the site (race condition?).
I don't understand. What do you mean message? What do you mean shared?
What race condition?
>
> It appeared to me that the http::context might be the best place to store
> temporary messages that I could retrieve and display at the end of the
> request.
No, http::context just preservers specific information for single
request/response. You can't change or alter it.
>
> But I have tried and failed. I am not too sure if it's possible and how to go
> about it. I have tried to add members to the context object. If it's possible
> to do so, I did it the wrong way.
You can't and shouldn't derive from context.
Artyom
|