• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Advertisements in JForum

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I was trying to change JForum code to show advertisements depending on the topic name as created by the user.

Hence i changed the jforum_topics table in the database and added two more columns that is the category (under which the topics falls that is wither electronics, gardening etc) and the second column was the list.

I have changed the code that is the forum.java and added these lines:


public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public String getLinkAdv() {
return linkAdv;
}

public void setLinkAdv(String linkAdv) {
this.linkAdv = linkAdv;
}

Now how can i make changes in the templates to check if i am getting the data picked from the database or not...... Also what does this mean:



I dont understand how are we changing the value of topic.id to 1 or 2 depending on which page we are going to.

Can someone explain me ........ ?

Thanks,
Ankit.
[originally posted on jforum.net by ankitoshniwal]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
To support new fields to a jForum "entity" bean, you will need to also create your own related Data Access Object (DAO). For the Category bean, this is an implimentation of the CategoryDAO interface.

Best way to do this is to create a subclass of your the DAO used by your type of Database server with the modification needed. This should handle populating and possibly saving the new fields.

Then create your own DataAccessDriver class based on your DB's version that uses the new DAO class.

jForum can be told to use these new classes by using the config file to point to your version of the DataAccessDriver.

Sounds complicated but if you dig into the code, it isn't and IMHO, it's a pretty elegant way to allow for database changes.

As to the "encodeURL" stuff, the topic.id is just the id number of the topic. The encodeURL call is to just change the base function call into a properly formatted URL. E.g., add in the context URI, etc.
[originally posted on jforum.net by monroe]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.

I would work on creating my own DAO and then make it communicate with the database. Now i also needed answer to the one of the sub-questions which i had asked earlier,
the code



in this case as you explained that the encodeURL function is being used just to make a properly formatted URL, now i looked into it further and there is a
java method called public String encodeURL(String url, String extension), in which we are passing the values as mentioned above, so how does the method resolve it to a topic id = 2.

Is the variable ${topic.id} stored in some config file on runtime, or are we making a run time call to the database to pick the values.

Also how can i display my data in the same way as mentioned above?

I am sorry for all these questions, i just want to get some fair idea of the coding before o delve into code changes.

Thanks,
Ankit.



[originally posted on jforum.net by ankitoshniwal]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I think what you are interested in is how the Freemarker template engine used by Jforum templates works. The full details can be found at www.freemarker.org but the short version is:

jForum action code puts objects (e.g. the Topic object) into the "freemarker context" and associates them with a "handle/freemarker variable name"
.
jForum calls the FreeMarker code with the required template file.

FreeMarker translates ${topic.id} to the Topic object's getId() method to get the id property. It can also translate calls to object methods as well. E.g. the $ForumContext.encodeURL(...) is a call to a static method. You could also use ${topic.getId()}.


[originally posted on jforum.net by monroe]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can you please tell me which java classes you mean by the jforum action code which you have mentioned in the response above. I have created the DAO, along with a genericDAO which is basically going to query the datatbase, now i want to see the results on a web page, so how can i add it to be a part of the template context.

I am so confused because i have done the same part using Entity manager which used to query the database send the results to a servlet and display it on the web page. In this case, i have the interface and the java file which would communicate with database and execute the SQL query, now, how should i display it on my web page using freemarker.

Please help.

Thanks,
Ankit.
[originally posted on jforum.net by ankitoshniwal]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a posting that briefly explains how the jForum URL's get mapped to Java object "actions"...

http://www.jforum.net/posts/list/4159.page#17143
[originally posted on jforum.net by monroe]
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic