Andreas Svenkson

Ranch Hand
+ Follow
since Jan 17, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
11
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andreas Svenkson


Hi guys.

I have coded a REST webservice client, that interacts with a service that provides JSON-formatted resources. While my code is working fine, I would like to further decouple it from the actual REST-API structure in the way that HATEOAS is generally meant to be done.
I should add that I am using Jersey 2 for the interaction with the webservice, and thus a general resource-query against the service would like as follows:



Now, the next step is usually to request and read the resource at the targeted location as such



Or alternatively, to process the returned data (and this is the way I have consistently done it in my code thus far):


However.... I am positive that other than that kind of processing, I should also be able to "traverse" the webservice application by means of the links contained in the response.
It should work like this:

.. However this does not work. This is despite that I can confirm that the resource has links in it.
The returned resource has the following JSON format:


As you can see there are clearly some links in the returned resource, and yet, a call to getLinks() consistently returns an empty Set<Link>.

Does anyone know how to configure Jersey to successfully let me extract link URI's this way from a Response object?

// Andreas
10 years ago

Tim Holloway wrote:The problem is more like "why did it ever work at all?"

The JSF View Definition Language (VDL) is not a programming language. It is a specification language that defines a View template. Although you can code simple expressions using EL, they should be limited to things that control how the view displays. Using EL to code application logic (business logic) is a violation of the MVC paradigm which makes it more expensive to maintain apps and is a right royal to debug on top of that.

The "value" attribute that appears on most of the JSF HTML data controls is NOT a method "call". It is a reference[/b] to a backing bean [i]property. A data value, not a function. According the the JavaBean convention, that means that there should be public "get" and "set" accessor methods defined in the backing bean ("set" is optional when you're using a display-only control such as outputText).

What that means is that what JSF is expecting is that you'd code


And that the backing bean would possess


Which I don't think is what you wanted, but it's what JSF wants.



Yes, I'm very well aware of this. And while adding two methods called setMethod() and getMethod(), we can "trick" (more like, tell) JSF that the backing bean has a property called 'method', and therefor can be reached by: #{backingBean.method}.

This is all fine, the only thing I am pointing out here, is that with a newer version of JBoss, we can explicitly input the return value of a backing bean method, without having to go through the "hassle" of craeting getX() and setX() with appropriate names. We can just name the method anything we like, and then reach it from JSF like I wrote earlier.

Obviously, it's not a big deal. I would guess that JSF (or the JBoss implementation of it, to be exact, maybe others too though?) simply added this functionality in a later release than 7.0.2, which is why it's not working in 7.0.2, but working fine in 7.1.1. I was just curious to know if anyone else found it peculiar.

// Andreas
11 years ago
JSF
Hi, thanks for answering.

Yeah, I've tried that too, I get the same inexplicable error:

javax.servlet.ServletException: /listperson.xhtml @13,47 value="#{serviceBean.method}": The class 'se.apper.soda.ejb.ServiceBean$Proxy$_$$_Weld$Proxy$' does not have the property 'method'.



I'm really very puzzled to why this is working with 7.1 and not 7.0.

// Andreas
11 years ago
JSF
Hi guys.

I'm currently working on a webapplication that will be implemented using JSF and JBoss.

Having previously used the latest version of JBoss (7.1.1 Final), I was perfectly able to call a method in jsf using this code:



The ServiceBean class looking like this:



The problem is this.... using JBoss version 7.1.1 Final, this works fine. But when I try to deploy the same application in JBoss 7.0.2 Final, i get the following error:

javax.servlet.ServletException: /pages/persons.xhtml @13,50 value="#{serviceBean.method()}": The class 'com.apper.soda.ejb.ServiceBean$Proxy$_$$_Weld$Proxy$' does not have the property 'method'.



Does anyone have an idea why this code might work on 7.1.1 and not 7.0.2 ?

Thanks,
Andreas.
11 years ago
JSF
SmallPerson has indeed access to protected members of its superclass Person via inheritance. But that's not what you're doing here - you are trying to access a protected member inside SmallPerson, from outside the class (ie: from ZiggyTest2) - and since ZiggyTest2 is not a subclass of Person, it cannot access the protected member.

In order to access the inherited member using inheritance, you would have to write something like this:



Now you have a public method in SmallPerson which is accessible to any other class, which via inheritance accesses the protected inherited variable x.

// Andreas
You probably know this by now, but as Henry elequently pointed out, your first piece of code catches all exceptions. As for the book explanation, yes I can see why you might expect a compiler error and not an exception, although all you really need to know is written in the API for Object's wait() method:

IllegalMonitorStateException - if the current thread is not the owner of this object's monitor.



// Andreas
Excellent, thanks Rob.

Out of curiousity, why is it specifically the rt.jar file that I should add the src.zip file to? What about all the other libraries listed under the jre?

// Andreas
12 years ago
Hey guys.

I was wondering, I am sure I have sometimes (by accident) in netbeans opened the source-file of a class I was using in my program (say, for example, Integer), and I was wondering how to do this in Eclipse.

I was also wondering, are all source-files of the entire java SE api included in the jdk installation? Where in the installation can I find them?

Thanks,
Andreas.
12 years ago

Bumping this cus I'd really like to know, is anyone aware of a container class other than JScrollPane that supplies a setViewportView() method so one can easily change what is viewed ?

// Andreas
12 years ago
Camick, what I meant was that I was using the JList constructor that takes a Vector, instead of a DefaultListModel...

Spoor, thanks I know. I just was unsure of how useful it would be to use generics in these classes, and was wondering if people generally did specify the generic type or not.

// Andreas
12 years ago

Well right now I have removed my JList and am using a JTree instead, but the warning came from for example:



...with the warning: "JList is a raw type. References to generic type JList<E> should be parameterized."

// Andreas
12 years ago
Thanks for the input guys.

I've just tried modifying my code to use a Vector instead of a DefaultListModel, but I have a problem where it seems the JList will not update - presumably because as the description for the Vector-constructor implies - the ListModel constructed is read-only and will not respond to changes in the Vector it was based on. That kind of defeats the purpose for using a Vector in the first place doesn't it? I guess I'm back to using the DefaultListModel since optimization isn't the highest priority for me right now.

As for the generics, I think I'll just forget about them and suppress the warnings I get from Eclipse.

// Andreas
12 years ago
Alright fair enough, although don't you agree that if I was absolutely set on using a design with a single viewport to see different JPanels, then the JScrollPane with its setViewportView() method would be quite ideal to implement it? I mean is there even any other class that has an equivalent setViewportView() method?

Still I totally get your point and will be looking into the other two ways you mentioned. One last question (for now ;)...

I looked into the MVC model and feel like that's probably a great way to implement this application (thanks for the tip on that too btw), however... If I do it like that, I feel inclined to have my View extend JFrame after all. Do you still think it would be better for the View to be implemented with a JFrame variable (local or member) when using the MVC pattern?

Thanks again.

// Andreas
12 years ago

Darryl Burke wrote:1. Yes on not extending JFrame. But do you even need it as a field? Does any code in any method other than the one which constructs and populates the frame require a reference to it?

2. I would prefer a CardLayout with a separate JScrollPane in each card to updating the viewport view of a single scroll pane.

3. What 'something else' did you have in mind?

edit

... any other general advice ...


Follow MVC principles and you can't go wrong.




1: Hmm, good question, I just felt that it "should" be a member... is it perhaps more common to just initialize it and then not reference it anymore? I have absolutely no idea if I'll need to later or not...

2: I'm gonna look into that, although I'm not sure why you say you would use a JScrollPane for each card? Do you mean in case there are so many fields they are not all visible, or does the JScrollPane other functionality/methods that you think might be useful? (The main reason I myself planned on using it is because of the functionality JScrollPane.setViewportView() supplies, so I can swap between the different panels, but with a cardlayout I don't think that functionality would be needed?)

2b: I would also like to know if the functionality of JScrollPane.setViewportView() method exists in any other class, ie; is there any other class that could be used as a view into a set of JPanels, so that one can change which panel is active dynamically?

3: I don't know what else it could be, just thought maybe you guys might have ideas for a better class that I'm unaware of

Thanks for the help guys!

// Andreas
12 years ago

Hi guys.

I'm pretty new to GUI programming in general, and have turned to using WindowBuilder Pro to help me design a bit smoother. I'm not sure if maybe some of you guys here will frown upon that, but I hope not

I'm currently working on a database client, and was considering a layout as follows...

Basically, one should be able to view different table-entries in a component. However, as the type of table that the current entry belongs to will vary, so will the different fields for the displayed entry.

For example, a user-table entry will have a name and a telephone number, etc. Whereas a item-table entry will have specifications for the item, like serial number and other stuff. Now I have a few questions about how to design this application...

1: I am building my main application by using HAS-A relationship to a JFrame. I remember from long ago when I coded a few GUIs by hand that it was a common approach to just extends JFrame for an application. But now I feel like I want to build my application as flexible as possible, so I am currently using a field to store the JFrame instead. Do you guys have any opinions about why this might be a bad idea, or would you say it's a good approach (as opposed to having the main application subclass JFrame that is) ?

2: I am currently considering a layout with for example a "main" JScrollPane that is used to view the table entries, but depending on what kind of entry is selected, I would like the JScrollPane to change its viewport-settings (JScrollPane.setViewportView(Component)) to different JPanels. This is ofcourse so that I can populate the various JPanels with the corrent fields depending on what kind of table the entry is selected from, since they will have different properties. What I'm wondering is if you think it makes sense to use a JScrollPane to view the different JPanels, where I have one JPanel-design for each table-type entry. Is there even any alternative to JScrollPane which also allows me to dynamically change its viewport-settings to another component, or is JScrollPane my only choice?

3: Also, is there any reason I should consider using something else than JPanel to view the different types of table entries? The information contained will be "simple" text-data, no images or so, which is why I personally think a basic JPanel will do fine...

If you have any other general advice on how to structure a GUI like this it's greatly appreciated, this is my first bigger GUI application and I feel like I have a ton of questions in my head...

Thanks.

// Andreas
12 years ago