Nathan England

Greenhorn
+ Follow
since Jul 13, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Nathan England

Thanks for the quick response! I'll check that out.
12 years ago
Hello, I have a question regarding what pattern or approach to use in Java for the following scenario:

In the "real world" I'm using a web API that accepts a REST query, an XML string, or a SOAP message.
However, the question isn't about the service but rather which pattern do I use to marshall a plain Java object into XML, SOAP, JSON, or a URL REST query key/value pairs.
Theoretically, I have just a given POJO, but I want to convert that into different forms (XML, REST style map, SOAP, JSON).

I cannot change the code for the POJO (but they are annotated where I can use JAXB, at least for the XML part). But I need to take a POJO and be able to generate all different formats without changing the base POJO.

Which design pattern or patterns should I investigate to accomplish this task?
12 years ago
A solution!!

I finally got it to work, after much trial and error.

Multiple loops with multiple levels of check boxes work much better using Struts <nested> tags. I'm not really sure why, but using nested tags with <nested:checkbox> works like a charm. Seems really simple now.

Posting solution here. (I added an "int id;" to each of my data objects, not sure if that is relevant or not but I was simply following some examples from the web).

My ActionForm is in session scope.

(my ActionForm is parent, has list of MasterOrder objects, MasterOrder is parent of a list of Order(s) and Order is parent of a list of OrderDetail.)

The OrderDetail is a plain java object:


Now for my Order object, which contains a "selected" flag, and a list of OrderDetails. Another plain java object:


One more plain java object, which contains a list of Orders


Now for my ActionForm. The form object contains a table of OrderMaster objects

(*Side note, while doing research I may need to put code in the reset() method to handle unchecked values..if that is the case I'll post that fix below. Right now it's not really doing anything.)

Now for the JSP code. Which seems ridiculously simple now:

14 years ago
Could this have something to do with my form being in session scope?

I'm going to attempt to write some JSP that sets data in the form object when the check box is clicked, and see if that works...
14 years ago
I'm having a difficult time with checkboxes and iterating through a few nested collections.

-My form page contains a Hashtable of OrderMaster objects.
-An OrderMaster contains an ArrayList of Order objects.
-The Order objects themselves contain an ArrayList of details.

I am displaying that structure on my JSP page as an unordered list, and I would like to have a checkbox on at least the detail level (lowest level).

My unordered list ends up looking like this:
(the [] denotes a check box)

Order (Order Master 1)
----[] Release 1(Order)
--------[] Detail 1
--------[] Detail 2
----[] Release 2 (Order)
--------[] Detail 1


I have the details of the structure displaying correctly. The data in each object is being printed to the screen. My problem is the values of the check boxes are not being submitted with the form.

Starting from the lowest level going up, here are my data objects and form.

The OrderDetail is a plain java object:


Now for my Order object, which contains a "selected" flag, and a list of OrderDetails. Another plain java object:


One more plain java object, which contains a list of Orders


Now for my ActionForm. The form object contains a table of OrderMaster objects


Here is the JSP code for my list. This seems to display the data properly for each nested iterate, however, clicking on the check box and submitting doesn't change any of the bean's "selected" value.
I can't figure out why that doesn't work:

14 years ago
I'm concerned I may be going about something incorrectly. I have an interface, and an implementation, but I need to extend the implementation and add on some more member variables to the subclass. Seems easy enough, but these extensions are bundled up into Collection objects, and that is where my headache begins.

What is the best way to create a list of my subclass objects, from a list that is returning a superclass of said objects?

Here is code that illustrates the issue:


Implementation of the interface:


This class extends the "Details" object, and simply adds one or two new member variables


Now for the part that is causing me some confusion. I have a service method, that returns an ArrayList of IType objects:


In another class (like a form class for a web app), I need to convert the IType list into a list of the *extended* class (MoreDetails).

So, long story short, I have a service that returns a list of IType objects, but I need to put them into a list of MoreDetail objects. What is the best or most appropriate way to do this?

The only way I came up with, was to loop through the collection one by one, cast each IType element to a MoreDetail, and generate a new collection that way. Seems like it's not the most elegant solution....


In the program, I call the service method, and need to populate my list:


Is the for loop that I used to extract the IType, then cast it to MoreDetails the correct approach?
14 years ago
Thank you Rob!

And yes, this is exactly the problem I seem to be running into. I have to switch between the xml and non-xml and it's getting quite confusing. The framework you present makes a lot of sense, I will give it a try.
14 years ago
Greetings all! I have a puzzling issue on how to properly design some relatively simple objects. Lets say I start out with a simple data object, whose members are also other data objects.

(In the examples below, the IOrderDetail and IOrder are interfaces that define getter setter signatures)






I want to create a couple of classes that tack on some additional functionality, for example, to add some methods to Order and OrderDetail that generate XML to represent those objects (Order and OrderDetail). I use XML as an example here, but what I really am trying to do is extend an Order, while at the same time extend the OrderDetail to implement the same interface.

so I came up with an interface




The trouble I'm having, is when am coding the Order object, which now needs a new member variable of an extended type OrderDetail. My problem is, I'm just not sure if this is proper design or not.



Is this the correct approach? If I have a bunch of classes that are member variables of another class, I would have to go and edit all of those classes and add new member variables that are extensions of others. It seems difficult to maintain this kind of design, and the less extendable it becomes.
14 years ago
I encountered the same problem in my Rational IDE.

To solve this, I went to properties->Java Build Path-> Order and Export
and I moved both mail.jar and activation.jar above the j2ee.jar. This seems to have resolved the problem in my IDE.

15 years ago
Hey,

I'm running into a confusing issue. I have a Struts 1.1 application.

I cannot seem to get line breaks to appear on the page after putting them into my ApplicationResources.properties.

For example, I am using ActionMessages to display the dynamic messages on the page. Here is a property that is getting read:


code from my JSP:


Instead of the page rendering:


Search yielded no results.
Please CONTINUE.



it is rendering:


Search yielded no results.<br>Please CONTINUE.



Note, no line return, and the page is actually showing the <br> tag, and not recognizing it as HTML.

So, now my text values in ApplicationResources.properties are very ugly, and all strung out in one huge line with no line breaks. I'm not sure what I might be doing wrong.

Any ideas on what I might try? Any workarounds?

-Nathan
15 years ago


Wrong ! the "id" and "property" are two different thing for logic:iterate tag, former defined the current element of the collection on which you're iterating and later one is come with "name" attribute to get the bean which is stored in a scope.

You might did some mistake elsewhere, maybe the logs file can explain the cause..



Well, that's the only thing I changed after trying dozens of different approaches, so may be wrong but it worked in my case.

Actually, I should re-state my assertion. Here is a PDF I followed that helped me do this:

http://www.laliluna.de/download/struts-html-checkbox-en.pdf

What I mentioned about the value of the "id" and the value of the "property" being the same, I misquoted. From the PDF:


Note: In order to refer a property of an element within the collection to a <html:checkbox> element
the attribute id of the <logic:iterate> tag must have the same name like the collection of the form
bean. Furthermore the attribute indexed of the <html:checkbox> have to be set to „true“.

15 years ago
Thanks for the tips. I really struggled with this. I'm not 100% out of deep water yet, but at least I'm getting the checkboxes to set a value in my data object submitted by the form.

I'll post what I managed to get to work so far:
Here is the <table> where my list is displayed:


The part that really hung me up was the iterate, I had my id="person" when it should have been id="personList"
After hours of digging I finally found something that mentioned this. The "id" and the "property" must be the same. (I'll worry about the "why" later).
changed:
<logic:iterate id="person" scope="session" name="PersonSearchForm" property="personList">
to:
<logic:iterate id="personList" scope="session" name="PersonSearchForm" property="personList">

Now I need to find some JavaScript code somewhere that applies some fancy highlighting and selection for the table rows and I'll be all set...
15 years ago
I found the "Struts Survival Guide" to be very useful (as a struts newb myself). There is a free PDF version of it online, you can probably just search for it. I found it was more helpful than the Struts for Dummies book that I purchased.
15 years ago
I think this is more JSP related than struts specificaly, since what I am needing to do is in the JSP page.

I have my struts framework all set up, but I'm struggling with the page design and functionality. I have a jsp page, which is displaying a table. I need to be able to highlight and select exclusively a single row in the table when the row is clicked, and save that index in my ActionForm object. (I have a value in my ActionForm which will be a placeholder for the index).

I have the table displaying my list by using <logic:iterate>, but I have no idea how to get the row to "highlight" as selected, and save the index of the row into the ActionForm.

I've found some examples of using JavaScript to do the row highlighting, but I'm having second thoughts as to whether using JavaScript is the best way or if there is an alternative way using Struts tags, I'm willing to give that a try.

Here is some code:
My ActionForm:


in my jsp page, I am displaying the table:


Should I use JavaScript? Alternatives? This displays my table, but I need some guidance on how to do the row selection and row highlighting when the row is clicked.
15 years ago


<%@taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>



I had the same problem, thought I was doing everything right. The above code is what fixed the problem!
15 years ago