Research Log of Web Science Students

Computer Science is not simply programming

Posts Tagged ‘Spring Framework

Binding our courses to a command class using Spring’s SimpleFormController

with 2 comments

I am currently trying to figure out how to bind our forms to the command object used by our SimpleFormController.

I have a form where I have two fields that I can add as much as I can. Think of it as like the upload file in gmail where I can add 1,2,3… files to upload only that I have two fields.

I am not so sure how this will check out using a SimpleFormController in Spring.

Here’s our form dilemna:

learning_activity

A user can add any number of learning activities to a course he makes. This makes our form “dynamic” or should I say “non-deterministic” in terms of the fields it has.

Read the rest of this entry »

Advertisements

Written by Jose Asuncion

September 15, 2009 at 3:46 pm

Posted in Hardwire

Tagged with ,

Spring in a nutshell

leave a comment »

Spring in a nutshell is a lightweight, opensource application framework that aims to make JavaEE development easier. It has several modules designed to give developers what they need to make web applications. These modules are built on top of the Core Container where Spring’s Dependency Injection is stored. Modules include:
Application Text Module
Spring’s AOP Module
JDBC abstraction and the DAO Module
Object-relational Mapping (ORM) Integration Module
Java Management Extensions (JMX)
Java EE Connectot API (JCA)
The Spring MVC Framework
Spring Portlet MVC
Spring’s Web Module
Remoting
Java Message Service (JMS)
*We’re not yet familiar with all of them, except maybe the MVC Framework and JavaEE but we’re learning. *fingers crossed*

Spring in a nutshell is a lightweight, opensource application framework that aims to make JavaEE development easier. It has several modules designed to give developers what they need to make web applications. These modules are built on top of the Core Container where Spring’s Dependency Injection is stored. Modules include:

Read the rest of this entry »

Written by Daniela

September 14, 2009 at 3:07 pm

Posted in ProjectriX

Tagged with ,

There’s no simple way to wire Twitter4j in the Spring Framework

with one comment

jeune.writingCodeException: 404 SEVERE REFACTORING FAIL 
                                      Jeune, you're a noob!

I have been attempting to wire Twitter4j in Spring for the past two days now. Although we’ve been successful at accessing Twitter data using Oauth already, I wasn’t satisfied at just making the code work. What we came up with was a “code duplication” monster and the only way to deal with this thing is through shotgun surgery.

I tried 6 sets of wirings for 2 code designs over 24 hours where I only ate twice (a small serving of pasta with pesto sauce). I was all over the SpringSource,  StackOverFlow and Twitter4j forums asking for help. Although some did come none weren’t enough to solve my problem.

What did I realize?

It’s time to move on.

At the end of day as researchers we will be judged on the features we’ve implemented and not on the refactorings we’ve done. I hope to keep that in mind.

My recommendations: Of course there’s way to wire this. I am thinking about extending AbstractController by an AbstractMethod, TwitterController and then put the relevant code in a protected method so I the controllers who need access to twitter can instantiate and initialize a Twitter class.

That would mean me reading chapter 3 of Spring in Action.

Hmmm I am already thinking about other the consequences of doing this. What if we’re going to access other social networks? Should I make a FacebookController too? I like that challenge, this is where OO design patterns come into play.

Anyway for my travails on trying to wire Twitter4j, here you go.

Written by Jose Asuncion

September 6, 2009 at 8:24 am

Posted in Hardwire

Tagged with ,

Wiring my first factory in Spring

leave a comment »

I felt the need to have only one instance of google’s user service in our app. Instatiating it in different places is clearly shotgun surgery!

I had this piece of code all over our controllers!


UserService userService = UserServiceFactory.getUserService();

The solution: instantiate it only once in the Spring Container and
inject it into all objects that need it. Like so:

<bean id="googleUserService"
         class="com.google.appengine.api.users.UserServiceFactory" 
         factory-method="getUserService">
</bean>

Sample controller that needs the user service:

<bean id="IndexController"
         class="com.hardwire.controller.IndexController">
 	<property name="userService"
                      ref="googleUserService">
         </property>
 </bean>

I am glad that went well. Sheesh I need to start blogging about our research. Nuff of the technical stuff for now.

Written by Jose Asuncion

August 30, 2009 at 5:33 pm

Posted in Hardwire

Tagged with

Using HashTables for models in Spring MVC

leave a comment »

Spring MVC controllers return a model and view:

return new ModelAndView([jsp],[modelName - to be accessed by the jsp], model you are returning);

As an example, heres the code to return a user’s nickname which the myPage.jsp will print:

String userNickname = "jeune";
return new ModelAndView("myPage","user",userNickname);

To print that in the myPage jsp using jstl tags simply code in:
<html>
.
.
.

<body>

.

.

.

${user}

.

.

</body>

</html>

But what if I wanted to print a whole lot of other things? This is inevitable if I want my web app to be dynamic.
Read the rest of this entry »

Written by Jose Asuncion

August 20, 2009 at 3:00 pm

Posted in Hardwire

Tagged with , ,

Boo Facebook and Sprint 2 Start

leave a comment »

So after setting up the Spring framework and translating the login using Google ID into Java (from PHP), I can finally start working on Sprint 2. The goals for this sprint are:

1. Use Oauth to get a PLE user’s Twitter account profile.
2. Refactor code smells from the first sprint. There are lots of em! I am feeling quite uneasy already. Like this one:

bp

The problem with that is Read the rest of this entry »

Written by Jose Asuncion

August 18, 2009 at 7:50 pm