Project

General

Profile

Actions

Support #2169

closed

Location of Wt Resources Dir & Widget Styles

Added by Bud T over 11 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
08/31/2013
Due date:
% Done:

0%

Estimated time:

Description

There is no reference to the approot in the installation instructions for Windows: http://redmine.webtoolkit.eu/projects/wt/wiki/Installing_Wt_on_MS_Windows

How does one specify the approot?

Regarding the /resources/ file, when using whttp, do we place it within the docroot? Where is the docroot? Shouldn't I be able to place /resources/ wherever I wish? Maybe I don't want it in the source directory of my project, then what do you suggest?

The issue was prompted by the fact that I'm having trouble getting WNavigationBar to display with style as it is shown in the widget gallery: http://www.webtoolkit.eu/widgets/navigation/navigation-bar - basically no style is applied. The code on the page says nothing about including style sheets.


Files

navbar_sshot.png (38.3 KB) navbar_sshot.png Bud T, 09/08/2013 04:06 AM
Actions #1

Updated by Bud T over 11 years ago

After moving /resources/ into my source directory using VisualStudio - which is undesirable since I'm using svn plugin and it is preferable to manage source in one place without external resources commingled into it - only part of the style gets applied to the navigation bar, and this only after I've included a style sheet:

    this->useStyleSheet(Wt::WCssStyleSheet(Wt::WLink("/resources/themes/bootstrap/bootstrap.css")));

I'm not sure why one should be required to manually link to a style sheet in the resources directory that is being used by a Widget?

In the navigation bar being displayed: the title font and rounded corner box style gets applied, but the menu items still display as bullet list elements. Again, I'm using the code from the widget gallery.

Actions #2

Updated by Wim Dumon over 11 years ago

  • Status changed from New to Feedback

Historically, for all examples approot docroot the source directory. That is documented in the link you mentioned. That is a simple directory layout, but not desirable for normal deployment since source code and databases etc are located in docroot, which means that they can be downloaded.

Widgetgallery is however an example that we migrated to a more complex directory structure, where source directory, docroot, and approot are three different paths. You set docroot with ---docroot=..., approot with ---approot=... and the source directory is not needed for executing the example. This is documented in the README file of the widgetgallery example.

You always need to copy the resources directory in the docroot directory.

You never have to include css files from the themes directory yourself.

If you have problems with docroot and resources, you will see them in your browser's debugger as 404 errors. This also gives you a hint where they are expected to be, given the current configuration.

Problems with approot will usually result in error messages being printed in the log, or by the example refusing to start.

BR,

Wim.

Actions #3

Updated by Bud T over 11 years ago

Wim Dumon wrote:

Widgetgallery is however an example that we migrated to a more complex directory structure, where source directory, docroot, and approot are three different paths. You set docroot with ---docroot=..., approot with ---approot=... and the source directory is not needed for executing the example. This is documented in the README file of the widgetgallery example.

Ah, I it see now down there in the Widgetgallery folder. I was looking in the top level README file and the files within the other examples. Hadn't looked at the Widgetgallery example yet.

Wim Dumon wrote:

You always need to copy the resources directory in the docroot directory.

Okay. I kind of like the use of symlink to resources from within approot, and have done that in Linux but have not worked out the same in Windows as yet. There should be a suggested way of doing this - IMO - that doesn't require copying the resources folder over into each example or leaving it in docroot.

Wim Dumon wrote:

Problems with approot will usually result in error messages being printed in the log, or by the example refusing to start.

Are you referring to the Apache log? I'm sorry if this is a silly question, but where is the log for Whttp located?

Wim Dumon wrote:

You never have to include css files from the themes directory yourself.

Okay, I'll post back here after figuring it out.

Actions #4

Updated by Bud T over 11 years ago

Wim Dumon wrote:

Problems with approot will usually result in error messages being printed in the log, or by the example refusing to start.

Are you referring to the Apache log? I'm sorry if this is a silly question, but where is the "log" for Whttp located?

Wim, is there a reason why the widgetgallery example isn't built in the WT.sln along with the other examples?

I also don't understand why including resources dir isn't sufficient. Why do you say that it must always be copied to docroot? In the widgetgallery README file it is written:

    cd widgetgallery/docroot
    ln -s ../../../resources . # include standard Wt resource files in docroot

Is there no way to similarly include /resources/ dir in docroot by setting a parameter in VisualStudio? It doesn't look like it, does it?

Regarding styles not getting applied to the NavigationBar: I've added the path to the resources folder ( "C:\witty\wt-3.3.0\resources" ) in VisualStudio's "Include Directories" and "Additional Include Directories". I've got the "Working Directory" set to the default which is "$(ProjectDir)". My class constructor inheriting from WApplication has:

setCssTheme("bootstrap");

The styles don't get applied. There are no other styles applied in the program to conflict. If I add this line to the class constructor then some of the styles get applied to the Navigation Bar:

useStyleSheet(Wt::WCssStyleSheet(Wt::WLink("/resources/themes/bootstrap/bootstrap.css")));

Without that line they do not get applied. And these only get applied if I also have the resources directory copied into my project directory like so:

C:\Users\user\Documents\Visual Studio 2010\Projects\project_name\app\resources

If I don't it there then Firebug shows 404 errors for not only bootstrap.css but also wt.css

The command argument used in VS is:

--http-address=0.0.0.0 --http-port=8080 --deploy-path=/ --docroot=.

If I remove that include line for the style from my class constructor, then no call to bootsrap.css is even made, per Firebug.

So, why isn't there any call to bootstrap.css when I have this line in my class constructor?

setCssTheme("bootstrap");

And why aren't bootstrap styles getting applied? I see a call to wt.css but nothing else.

Even if I copy the resources dir to the directory that contains the build binary from VisualStudio:

C:\Users\user\Documents\Visual Studio 2010\Projects\project_name\Debug\resources

This is presumably the docroot as defined by my command arguments (above) because it contains app.exe. Right? So styles should get applied, right? But they don't. No call to bootstrap.css is even made.

Actions #5

Updated by Bud T over 11 years ago

I should add that I'm calling this function in my constructor:

void header() {
    WContainerWidget* header = new WContainerWidget(root());
    header->setId("header");

    // Create a navigation bar with a link to a web page.
    Wt::WNavigationBar *navigation = new Wt::WNavigationBar(header);
    navigation->setTitle("Corpy Inc.",
                 "http://www.google.com/search?q=corpy+inc");
    navigation->setResponsive(true);

    Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(header);

    contentsStack->addStyleClass("contents");

    // Setup a Left-aligned menu.
    Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, header);
    navigation->addMenu(leftMenu);

    Wt::WText *searchResult = new Wt::WText("Buy or Sell... Bye!");

    leftMenu->addItem("Home", new Wt::WText("There is no better place!"));
    leftMenu->addItem("Layout", new Wt::WText("Layout contents"))
        ->setLink(Wt::WLink(Wt::WLink::InternalPath, "/layout"));
    leftMenu->addItem("Sales", searchResult);

    // Setup a Right-aligned menu.
    Wt::WMenu *rightMenu = new Wt::WMenu();
    navigation->addMenu(rightMenu, Wt::AlignRight);

    Wt::WHBoxLayout *hbox = new Wt::WHBoxLayout();
    header->setLayout(hbox);
    header->setMargin(5);

    hbox->addWidget(navigation);
  }
Actions #6

Updated by Wim Dumon over 11 years ago

Wt log: by default on the console, unless configured differently in wt_config.xml

Widgetgallery uses c+11 features. Recent compiler required (msvs 2012 on windows, g+4.6 or newer (not autodetected!) on linux), cmake script tests for this and disables widgetgallery if not available. You should see a message in the cmake output when this happens.

For gcc, please don't mix C+08 and C11 in one executable. It seems to work, and often does, but it's a recipe for disaster. That's why we don't compile C11 by default on Linux: you must be aware that you'll have to build your own project as C+11 as well.

There's no equivalent of 'ln -s' on windows that works, as far as I know.

Wt's resources folder must be copied in the docroot. It has no place in include direcotries, additional include directories, ... With the errors you see, the ---docroot parameter is wrong. To be sure, put a full path there to your docroot. '.' means current work directory, so your alternative is to fix your CWD.

BR,

Wim.

BR,

Wim.

Actions #7

Updated by Bud T over 11 years ago

Guys:

Please explain this to me: why aren't the bootstrap styles being applied to my navigation bar when

setCssTheme("bootstrap");

is being called within the App class constructor, and Firebug shows this file being loaded?

<link type="text/css" rel="stylesheet" href="resources/themes/bootstrap/wt.css">

As a test, adding the following line of code within the App class constructor:

useStyleSheet(Wt::WCssStyleSheet(Wt::WLink("/resources/themes/bootstrap/bootstrap.css")));

causes some of the styles to get applied to the navigation bar - excepting some font and menu styles (menu is showing as bullet list)

Now, I have the /resources dir copied into:

C:\Users\user_name\Documents\Visual Studio 2010\Projects\SOLUTION_name\Debug

which is the docroot that I set explicitly in the "Command Arguments" - as well as for the "Working Directory". This path is, incidentally, equivalent to writing

..\Debug

Since VisualStudio treats this directory as the CWD by default:

\SOLUTION_name\project_name\Debug\

I'm assuming here that the docroot is the Debug folder under the \SOLUTION_name folder since that is where the binary file gets placed when compiled by VisualStudio. I know that in Apache the docroot is where we place the .wt binary file, right? So that is what defines the docroot? But if this is docroot, and /resources dir has been copied there, and this folder has likewise been set as the docroot in command arguments, as well as set as the working directory in VisualStudio, then why won't the styles get applied??

Actions #8

Updated by Bud T over 11 years ago

This is a follow up on last message.

I've made the change of adding the simplest application code

possible for testing navigation bar (based upon lift from the gallery code):

#include <Wt/WLineEdit>
#include <Wt/WMenu>
#include <Wt/WMessageBox>
#include <Wt/WNavigationBar>
#include <Wt/WPopupMenu>
#include <Wt/WPopupMenuItem>
#include <Wt/WStackedWidget>
#include <Wt/WText>
#include <Wt/WApplication>

using namespace Wt;

class App: public WApplication {
private:
  WContainerWidget* container;

public: 
  App(const WEnvironment &env): WApplication(env) {
    this->setCssTheme("bootstrap");
    nav_test();
  }

  void nav_test() {
    Wt::WContainerWidget *container = new Wt::WContainerWidget(root());

    // Create a navigation bar with a link to a web page.
    Wt::WNavigationBar *navigation = new Wt::WNavigationBar(container);
    navigation->setTitle("Corpy Inc.",
                 "http://www.google.com/search?q=corpy+inc");
    navigation->setResponsive(true);

    Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(container);
    contentsStack->addStyleClass("contents");

    // Setup a Left-aligned menu.
    Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, container);
    navigation->addMenu(leftMenu);

    Wt::WText *searchResult = new Wt::WText("Buy or Sell... Bye!");

    leftMenu->addItem("Home", new Wt::WText("There is no better place!"));
    leftMenu->addItem("Layout", new Wt::WText("Layout contents"))
        ->setLink(Wt::WLink(Wt::WLink::InternalPath, "/layout"));
    leftMenu->addItem("Sales", searchResult);

    // Setup a Right-aligned menu.
    Wt::WMenu *rightMenu = new Wt::WMenu();
    navigation->addMenu(rightMenu, Wt::AlignRight);

    container->addWidget(contentsStack);
  }
};

Wt::WApplication* createApplication(const Wt::WEnvironment &env) {    
  return new App(env);
}

int main(int argc, char** argv) {
  return Wt::WRun(argc, argv, &createApplication);
}

Running this (after clean and rebuild of project) creates blank white page in the browser. If I make the change of assigning root() to be the parent node of the container, then the navigation bar appears without style (see attached screenshot). There are no 404 messages in the log in either case.

Here are the console output (below) and screenshot (attached) for case of root() specified as parent (as shown in code).

[2013-Sep-07 18:33:00.596663] 4276 - [info] "config: reading Wt config file: c:/witty/wt_config.xml (location = 'C:\Users\user_name\documents\visual studio 2010\Projects\SOLUTION_name\Debug\App.exe')"
[2013-Sep-07 18:33:00.645665] 4276 - [info] "WServer/wthttp: initializing built-in wthttpd"
[2013-Sep-07 18:33:01.013686] 4276 - [info] "wthttp: started server: http://0.0.0.0:8080"
[2013-Sep-07 18:33:15.889537] 4276 - [info] "Wt: session created (#sessions = 1)"
[2013-Sep-07 18:33:15.895538] 4276 [/ a2BlSQStJUspYXqu] [info] "WEnvironment: UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"
[2013-Sep-07 18:33:15.931540] 4276 [/ a2BlSQStJUspYXqu] [warning] "WContainerWidget: addWidget(): reparenting widget"
[2013-Sep-07 18:33:15.951541] 4276 [/ a2BlSQStJUspYXqu] [warning] "WApplication: Deploy-path ends with '/', using /?_= for internal paths"
127.0.0.1 - - [2013-Sep-07 18:33:16.000544] "GET / HTTP/1.1" 200 3158
[2013-Sep-07 18:33:16.014544] 4276 - [info] "WebRequest: took 126.007ms"
[2013-Sep-07 18:33:16.067547] 4276 - [info] "Wt: session created (#sessions = 2)"
[2013-Sep-07 18:33:16.075548] 4276 [/ jW5MLs2tjSC6HuLH] [info] "WEnvironment: UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"
[2013-Sep-071 2178.:03.30:.116 .-0 9-7 5[4290]1 34-2S7e6p -[0/7  j1W85:M3L3s:21t6j.S0C968H5u4L9H]]  "[GiEnTf o/]r e"sWotu:r cseisg/ntahle mferso/m deabdo ostesstsriaopn/,w ts.
ecnsdsi nHgT TrPe/l1o.a1d". "304 0
127.0.0.1 - - [2013-Sep-07 18:33:16.102549] "GET /resources/moz-transitions.css HTTP/1.1" 304 0

[2013-Sep-07 18:33:16.120550] 4276 [/1 2j7W.50M.L0s.21t j-S C-6 H[u2L0H1]3 -[Sienpf-o0]7  "1Wt8:: 3s3e:s1s6i.o1n2 3d5e5s1t]r o"yPeOdS T( #/s?ewstsdi=oZnJsC M=r 21T)T"RHKNbQjP
HTTP/1.1" 200 72

[2013-Sep-07 18:33:16.133551] 4276 - [info] "WebRequest: took 67.004ms"
127.0.0.1 - - [2013-Sep-07 18:33:16.277559] "GET /?wtd=a2BlSQStJUspYXqu&sid=-1207986416&htmlHistory=true&deployPath=%2F&request=script&rand=2409681533 HTTP/1.1" 200 36170
[2013-Sep-07 18:33:16.289560] 4276 - [info] "WebRequest: took 39.002ms"
127.0.0.1 - - [2013-Sep-07 18:33:16.412567] "POST /?wtd=a2BlSQStJUspYXqu HTTP/1.1" 200 51
[2013-Sep-07 18:33:16.419568] 4276 - [info] "WebRequest: took 10.001ms"

I don't know what the reparenting widget warning means or if it is relevant.

Actions #9

Updated by Bud T over 11 years ago

SOLVED:

  • In VisualStudio, the default docroot is the Debug (or Release) folder under the solution directory. This is the location of the .exe binary file, and where you want to copy /resources dir or set up a symlink for it using the command line interface. Best approach is to set a value for ---approot= in the Command Arguments field and set a symlink to resources from it.
  • In VisualStudio, the default "Working Directory" is set as $(ProjectDir) which is the Debug (or Release) folder under the project folder (which is under the solution dir). If you leave this default setting then you should use ---docroot=..\Debug in your Command Arguments
  • Even though some themese can be set using setCssTheme("theme_name"), it cannot be used for bootstrap theme, which requires you to include and to set it using setTheme(new WBootstrapTheme());
  • You must specify the parent using root() or some other pointer reference when creating the widget in which you plan to place the navigation bar.
Actions #10

Updated by Bud T over 11 years ago

Correction to above: replace ../Debug with ../../Debug

Actions #11

Updated by Koen Deforche over 11 years ago

  • Status changed from Feedback to Closed
Actions

Also available in: Atom PDF