Note that there are some explanatory texts on larger screens.

plurals
  1. PODelegating static members to extended classes - Java
    primarykey
    data
    text
    <p><strong>About project:</strong> I'm trying to write CMS-like web-site on Java. Previously I used PHP for such purposes, but now I need tight integration with existing server-side solution, written on java, so decided to use Java for web-site too. Currently, for easier developing, I made some "hierarchy" of my project: top-level "Server" class (in closest future it'll be filled with content and functionality, but now it's empty), next Subsystems, Extensions, and as a part of any of this - Modules and Blocks. Each of them have some restrictions and possibilities, not available to one another... Maybe there is other way, but currently I don't know it.</p> <p>I'm making some kind of caching, depending on the fact, that mine Dynamic Web Project's vars can be kept in the memory all the time. For example, 'Tree', that represents all this elements, loaded from database and kept in memory, and all next requests (for example, what Extension has this Module as a child - for managing privileges) made without asking database.</p> <p>Of course, for this purposes, I need to have some flag, that will tell elements, that their data was changed and they need to refresh it from database. Single global flag (in context, for example) is bad, while in almost all situations I'll need to refresh single element or group. Single element's flag is done, but...</p> <p><strong>About realization:</strong> The problem itself. Lets say I have class Module:</p> <pre><code>public abstract class Module{ private final static boolean Changed; public static boolean getChanged(){ return Changed;} public static void setChanged(boolean newState){ Changed = newState;} public abstract String getName(); public abstract String getTitle(HttpServletRequest request, HttpServletResponse response, ServletContext context);} </code></pre> <p>And I have some module:</p> <pre><code>public final class Articles extends Module{ public class Article{...} private Tree&lt;Article&gt; ArticleList; public final ArrayList&lt;Article&gt; getArticlesInGroup(int groupID){ if(getChanged()) refreshFromDatabase(); ... } } </code></pre> <p>Here, for example, this flag used as in case of changing some global preferences, that may change Articles work - for example, some operations on database, that performed through Query browser or some else - class 'caching' a tree of articles and groups (it doesn't keeping whole article - only Title, ID, ParentGroup or maybe some else...</p> <p><strong>The problem itself:</strong> in servlet Main in doGet(...) I have next code executed:</p> <pre><code>if(request.getParameter("SetModify") &amp;&amp; UsersManager.inGroup(currentUser,"Administrator") Module.setChanged(true); </code></pre> <p>And, I checked, "Module.setChanged(true)" executed successfully... But when it comes to "getChanged()" in class Article, I got false...</p> <p>Does there exists any way to create static variable, that will be static among all class, that extends it, or I simply doesn't understand something? Case "Module.getChanged()" in class Articles tested as well - the result is the same...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload