Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ComptimusPrime
Jan 23, 2006
Computer Transformer
Are they loading and just not showing? You may need to apply some sizing info to the img tags there.

Adbot
ADBOT LOVES YOU

DholmbladRU
May 4, 2006

ComptimusPrime posted:

Are they loading and just not showing? You may need to apply some sizing info to the img tags there.

They are showing as redX when I run it in eclipse, and in a browser they just do not show.

I am trying to alter an xml document, trying to update an element

code:
	List children = rootnode.getChildren("homes");
			 Iterator itr = children.iterator();
			 while (itr.hasNext()) {
			   Element child = (Element) itr.next();
			 int i = Integer.parseInt(child.getAttributeValue("ndom"));
			 child.setAttribute("ndom", Integer.toString(i+1));
			  // itr.remove();
			   
			 }

The above doesnt seem to do anything. The below code was able to update the first "element section" for the total number

code:
Element rootnode = document.getRootElement();
		List n = rootnode.getChildren();
		for(Object rootNode : n){
                      do stuff to rootnode.child
}

DholmbladRU fucked around with this message at 08:41 on Feb 6, 2012

ComptimusPrime
Jan 23, 2006
Computer Transformer
Regarding the img tags.

First, I would recommend opening up the developer tools in chrome, or installing firebug in ff, and looking at the errors that are being logged.

The first thing you need to find out is if it is loading or not. And if it is logging a not found then you know at least that much.

Also, I am not familiar really with tomcat, but I would make sure that requests for /src/images are really serving that directory.

Also, I don't think this is likely the case, but if you are using XHTML, then you need to get that img tag to be lower case.

ComptimusPrime fucked around with this message at 08:57 on Feb 6, 2012

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

Luminous posted:

You may want to consider an account as, well, just an account that has f.ex, a username and a role or a list of roles, where a role is an admin, a mod, or a schmoe (use inheritance here).

Then serializing an account and determining which actual role objects need to be instantiated is more straightforward.

Yes, I think you're right. Thanks.

DholmbladRU
May 4, 2006

ComptimusPrime posted:

Regarding the img tags.

First, I would recommend opening up the developer tools in chrome, or installing firebug in ff, and looking at the errors that are being logged.

The first thing you need to find out is if it is loading or not. And if it is logging a not found then you know at least that much.

Also, I am not familiar really with tomcat, but I would make sure that requests for /src/images are really serving that directory.

Also, I don't think this is likely the case, but if you are using XHTML, then you need to get that img tag to be lower case.


HM using a URL seemed to work. I probably just dont have the images in the correct directory.

Innocent Bystander
May 8, 2007
Born in the LOLbarn.
Why does the finally block override a return?

code:

try {
    System.out.println('Hey broman!');
    return 2;
}
catch(Exception e) {
    return 3;
}
finally {
    System.out.println('Whats up duuuude?');
}

// Prints 'Hey broman!\nWhats up duuuude?'

baquerd
Jul 2, 2007

by FactsAreUseless

Innocent Bystander posted:

Why does the finally block override a return?

code:

try {
    System.out.println('Hey broman!');
    return 2;
}
catch(Exception e) {
    return 3;
}
finally {
    System.out.println('Whats up duuuude?');
}


It doesn't override the return, the return still executes (unless the finally block returns). Check out the second answer here: http://stackoverflow.com/questions/65035/in-java-does-return-trump-finally

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Innocent Bystander posted:

Why does the finally block override a return?
it's not overriding the return, and if it didn't execute here it would be worthless

DholmbladRU
May 4, 2006
I am trying to build a drop down using elements from an array in js

code:

for ( int i = 1; i < h.length; i++ ) {
    	
    	String tmp = h[i].getHome();
    	String tmp2 = h[i].getLocation();
    	
        %>
        
		<option name="hSold" value="<%= i%>">   <%=tmp + " " + tmp2%></option>
		
		<% }%>
What makes no sense to me is that the string in the drop down is populated correctly. However the 'value' isnt. So when I do request.getParameter("stuff") I am getting null. This is driving me crazy...

Computer viking
May 30, 2011
Now with less breakage.

DholmbladRU posted:

I am trying to build a drop down using elements from an array in js

code:

for ( int i = 1; i < h.length; i++ ) {
    	
    	String tmp = h[i].getHome();
    	String tmp2 = h[i].getLocation();
    	
        %>
        
		<option name="hSold" value="<%= i%>">   <%=tmp + " " + tmp2%></option>
		
		<% }%>
What makes no sense to me is that the string in the drop down is populated correctly. However the 'value' isnt. So when I do request.getParameter("stuff") I am getting null. This is driving me crazy...

How, exactly, does the HTML output look?

DholmbladRU
May 4, 2006
code:
  <form name="setAsSold"  action="markSold.jsp" method='POST'>
   		<select name="setAsSold">
   		<option value="" name="hSold"></option>
   	<%
    for ( int i = 1; i < h.length; i++ ) {
    	
    	String tmp = h[i].getHome();
    	String tmp2 = h[i].getLocation();
    	
        %>
        
		<option name="hSold" value="<%= i%>">   <%=tmp + " " + tmp2%></option>
		
		<% }%>
		</select>
		<th><input type="submit" value="Mark as sold"/></th>
    </form>
    </body>
When displayed the drop down is populated with two concatinated strings. Howester I am unable to get the "value" of the element I select in the drop down when I submit the form. I am using 'request.getParameterValues("stuff")' on the JSP end to get the value. This worked for other forms when they were text fields.

Computer viking
May 30, 2011
Now with less breakage.

Let me rephrase: Not the code that creates the HTML, but the HTML that is has created. If you view source in a browser displaying the output from that code, how does the HTML look?

I'm just wondering if it outputs value="" or value="0" or value="Null" or value="i" or something else wrong - or if it actually looks fine, and the problem is elsewhere. Usually a good place to start debugging.

Computer viking fucked around with this message at 16:14 on Feb 7, 2012

DholmbladRU
May 4, 2006

Computer viking posted:

Let me rephrase: Not the code that creates the HTML, but the HTML that is has created. If you view source in a browser displaying the output from that code, how does the HTML look?

I'm just wondering if it outputs value="" or value="0" or value="Null" or value="i" or something else wrong - or if it actually looks fine, and the problem is elsewhere. Usually a good place to start debugging.

Ill show you in a little while. I am having some problems getting it to publish on this instance of apache/eclipse at work.. working through a 404 error

Doctor w-rw-rw-
Jun 24, 2008

DholmbladRU posted:

code:
  <form name="setAsSold"  action="markSold.jsp" method='POST'>
   		<select name="setAsSold">
   		<option value="" name="hSold"></option>
   	<%
    for ( int i = 1; i < h.length; i++ ) {
    	
    	String tmp = h[i].getHome();
    	String tmp2 = h[i].getLocation();
    	
        %>
        
		<option name="hSold" value="<%= i%>">   <%=tmp + " " + tmp2%></option>
		
		<% }%>
		</select>
		<th><input type="submit" value="Mark as sold"/></th>
    </form>
    </body>
When displayed the drop down is populated with two concatinated strings. Howester I am unable to get the "value" of the element I select in the drop down when I submit the form. I am using 'request.getParameterValues("stuff")' on the JSP end to get the value. This worked for other forms when they were text fields.

Are you checking setAsSold[], or just setAsSold? Maybe it's being treated as an array?

DholmbladRU
May 4, 2006

Doctor w-rw-rw- posted:

Are you checking setAsSold[], or just setAsSold? Maybe it's being treated as an array?

thattt may be my problem, I am doing 'request.getParameterValues("hSold")' where 'hSold' is the name of each attribute element in the drop down.


Does anyone know what would cause a 404 error 'resources not available' in Eclipse/Tomcat(7.0). This is project specific(created test with .html and .jsp which worked), which was imported from my machine at home as a file system. The onlyyy thing I can think of is that my mahcine at home is 64-bit, and I dont remember if the IDE was 64bit or not. But I can view/edit the files jut cant see them from apache.

DholmbladRU fucked around with this message at 21:59 on Feb 7, 2012

DholmbladRU
May 4, 2006

Computer viking posted:

Let me rephrase: Not the code that creates the HTML, but the HTML that is has created. If you view source in a browser displaying the output from that code, how does the HTML look?

I'm just wondering if it outputs value="" or value="0" or value="Null" or value="i" or something else wrong - or if it actually looks fine, and the problem is elsewhere. Usually a good place to start debugging.


code:
<select name="updateP">
   		<option value="" name="homeID"></option>

   	
        
		<option name="homeID" value="1">   2 NW Washington, DC</option>
		
		
        
		<option name="homeID" value="2">   3 NW Washingtonv DC</option>
edit: I got it working. was calling wrong thing.

DholmbladRU fucked around with this message at 02:09 on Feb 8, 2012

Doc Faustus
Sep 6, 2005

Philippe is such an angry eater
I have a giant XML document formatted like this:

code:
<wrapper>
     <item>
          <element1 />
          <element2 />
     </item>

     <item>...
     </item>
 
</wrapper>
What I need (I think/hope) is to have the file divided up into many smaller files, each comprising a single <item>. The <wrapper> element appears only at the very beginnning and end, and can be ignored.

Clearly what I need here is an XML parser! Can someone recommend one suitable for something this basic (read: easy to use)? I need to do very little transformation, so I don't need anything full-powered.

fake edit: googling looks like the w3c DOM classes may do what I need? Confirm/deny?
http://www.developerfusion.com/code/2064/a-simple-way-to-read-an-xml-file-in-java/

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
If you go back a few(?) pages in this thread, there's a bunch of talk about XML parsing in Java.

That said, the stuff in that link could certainly do what you want. Just know there are probably much easier libraries to use than that horrible W3C/DOM thing, and if you want to do something more complex you would be wise to look into other choices.

Tots
Sep 3, 2007

:frogout:
Forums upgrade or equivalent for anyone willing to help me complete a java assignment tonight. I don't want someone to do it for me, rather to walk me through the whats and whys in a collab online editor.

E: Got a lot of help in the general megathread.

Tots fucked around with this message at 22:53 on Feb 21, 2012

Doctor w-rw-rw-
Jun 24, 2008

Tots posted:

Forums upgrade or equivalent for anyone willing to help me complete a java assignment tonight. I don't want someone to do it for me, rather to walk me through the whats and whys in a collab online editor.

More details, please

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
How can I name these variables better?

code:
public class MyObject {
    private List<Thingy> thingies;
    
    private List<Thingy> getThingies() {
        if (this.thingies == null) {
            this.thingies = new ArrayList<Thingy>();
            //query the db and add some thingies to the list
        }
        return this.thingies;
    }

    private void someMethod() {
         //i need to do something with my list of thingies
         List<Thingy> thingies = this.getThingies();
    }
}
So it doesn't seem like a good idea that the two List<Thingy> have the same names, seems a bit confusing. Should I use a prefix to indicate scope? i.e. m_thingies vs. simply thingies. Or something else?

Max Facetime
Apr 18, 2009

fletcher posted:

So it doesn't seem like a good idea that the two List<Thingy> have the same names, seems a bit confusing. Should I use a prefix to indicate scope? i.e. m_thingies vs. simply thingies. Or something else?

It's not a good thing, no. Your IDE probably has a warning for that, something like "local variable hides field".

Rather than a prefix, you should set your IDE to use a different color for fields.

So why is the same name most natural for both of them? If it's because they are the same thing then you should use the field directly.

If it's because the method is divorced from the instance and operates mainly with just the field, see if you can't make it a static method.

Bottom line, use the best names you can. If this leads to warnings or conflicts, there might be a problem with the overall design.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

I am in posted:

So why is the same name most natural for both of them? If it's because they are the same thing then you should use the field directly.

Look at that accessor again. It's a lazy-instantiation pattern.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I don't really have a good reason for needing lazy loading, it just seemed convenient. My IDE gives them different colors, they aren't really ambiguous to me. I just want to access thingies all willie nillie in these methods, and not have to concern myself with whether or not they have been instantiated yet.

Max Facetime
Apr 18, 2009

Jabor posted:

Look at that accessor again. It's a lazy-instantiation pattern.

Right right. I'd call the lazily initialized field something like cachedThingies, so that the name thingies is available everywhere where it's clear initialization has happened.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

I am in posted:

Right right. I'd call the lazily initialized field something like cachedThingies, so that the name thingies is available everywhere where it's clear initialization has happened.

This actually makes a lot of sense. It's certainly more meaningful than having some awkward wart to signify a class member.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

I am in posted:

Right right. I'd call the lazily initialized field something like cachedThingies, so that the name thingies is available everywhere where it's clear initialization has happened.

I like this, thanks guys!

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
In C#, the standard practice is to name private fields starting with an underscore- could work in Java, too.

Max Facetime
Apr 18, 2009

Internet Janitor posted:

In C#, the standard practice is to name private fields starting with an underscore- could work in Java, too.

Oh you :allears:

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Hungarian notation is one of those ideas that will never stop being reinvented, as long as programmers have to name things.

Paolomania
Apr 26, 2006

I don't think "adjectiveType" identifiers such as "cachedThingy", "tempFoo" or "someBar" count as Hungarian notation so much as a self-commenting literary identifiers. Ad-hoc scoping with underscores is just as open to divergence and ambiguous interpretation as other much unstated and unenforced conventions.

Max Facetime
Apr 18, 2009

Paolomania posted:

I don't think "adjectiveType" identifiers such as "cachedThingy", "tempFoo" or "someBar" count as Hungarian notation so much as a self-commenting literary identifiers. Ad-hoc scoping with underscores is just as open to divergence and ambiguous interpretation as other much unstated and unenforced conventions.

Oh gently caress, I guess I misread Internet Janitor's post.

Yes, I agree with this. I hope I can explain my thought-process for coming up with the name cachedSomething without coming off like a huge pedant.

So I have some data that's lazily-initialized, but why go for lazy initialization?

1. Naming it cachedItems says that it comes from an unreliable external source like an SQL database and my snapshot can go stale with no ill effects.
2. Naming it computedItems says it's the result from an expensive algorithm that I could rerun whenever and get the same results.
3. The lazy initialization is actually part of two-phase construction and the objects are reused in an object pool: naming it items is fine, because everything else in the object should work as if the object had been fully initialized in the constructor.

That last one is a bit of a stretch.

Max Facetime fucked around with this message at 01:23 on Feb 25, 2012

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
I'd use "things" instead of "thingies". Also mangling using underscores is punishable by death.


Unrelated, a question about caching with a SoftReference. I've got an object where one of its fields can be easily reconstructed if need be, it's a ZonedDateTime constructed out of a long. I'd like to use a SoftReference since it isn't actually necessary memory.

IBM's code here: https://www.ibm.com/developerworks/java/library/j-jtp01246/index.html
says that once a SoftReference's referent is collected, I can reset it to a new object with SoftReference#set. Except that that method doesn't exist.

Do I just do:

code:
public ZonedDateTime getCreatedDate() {
    if (dateref == null || dateref.get() == null)
        dateref = new SoftReference<ZonedDateTime>(...createdatehere...);
    return dateref.get();
}
?
(I don't know if that compiles)

e: added context

Malloc Voidstar fucked around with this message at 07:57 on Feb 25, 2012

Sedro
Dec 31, 2008
You would appear to have two race conditions:
A) Reference is dead initially, and gets GC'd between these calls:
code:
dateref = new SoftReference<ZonedDateTime>(...createdatehere...);
// GC
return dateref.get();
B) Reference is alive initially, and gets GC'd between these calls:
code:
dateref.get() == null // false
// GC
return dateref.get();
Fixed:
code:
public ZonedDateTime getCreatedDate() {
    ZonedDateTime date;
    if (dateref != null) {
        date = dateref.get();
        if (date != null) {
            return date;
        }
    }
    date = ...createdatehere...
    dateref = new SoftReference<ZonedDateTime>(date);
    return date;
}
But this is probably a premature optimization and you should not use this at all

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Sedro posted:

You would appear to have two race conditions:

But this is probably a premature optimization and you should not use this at all
Thanks for pointing that first race condition out, I wouldn't have known.

And I know it's a premature optimization, but I'm using it anyway :v: if it breaks, it'll fail loudly in any case

Doctor w-rw-rw-
Jun 24, 2008
MyBatis or JPA/Hibernate? Relative strengths?

Background:
After a lot of finagling to get Guice and JPA/Hibernate to play nice, I've finally got something hooked up to a h2 database (for testing) to where I can call entityManager.persist(foobar) or entityManager.createQuery("SELECT f FROM FooBar f").getResultList(), but I'm wondering if it's worth it. MyBatis' Guice integration looks awfully neat, and all this SessionFactory and EntityManager and persistence.xml stuff looks mighty confusing. However, JPA generates SQL schemas, which is super useful for me before I even know what my schema should be like.

I'm tinkering with Quartz, Guice, and Abdera. For now the goal is just to get an RSS feed and stuff items in a database, but ideally I'd be crawling stuff like web searches or my facebook feed and persisting the crawl. Not really sure how to approach this, and I think that choice of ORM framework would influence these.

This is sort of for a hobby thing so it's also for learning, so "Just use JDBC directly" is a boring option I'd prefer alternatives to.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Hibernate is great until it's not. Once you hit that wall you will be loving pissed at it until you invariably rip it out. But that all depends on the scale of your application. If it never grows very big Hibernate is perfectly fine. Personally, I like it for prototyping and that's about it. Using the DDL generator (like you mention) is definitely a plus, it's a very slick little tool.

MyBatis is great if you know SQL well and you don't really plan on being a DB nomad. SQL is a fine language and MyBatis is a good way of making your SQL calls less ad hoc.

Doctor w-rw-rw-
Jun 24, 2008

TRex EaterofCars posted:

Hibernate is great until it's not. Once you hit that wall you will be loving pissed at it until you invariably rip it out. But that all depends on the scale of your application. If it never grows very big Hibernate is perfectly fine. Personally, I like it for prototyping and that's about it. Using the DDL generator (like you mention) is definitely a plus, it's a very slick little tool.

MyBatis is great if you know SQL well and you don't really plan on being a DB nomad. SQL is a fine language and MyBatis is a good way of making your SQL calls less ad hoc.

Sweet. Thanks. I suppose I'll keep on going with JPA until I've got something worthwhile to make less prototype-y.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
I am a Python programmer, and I need to learn semi-basic Java. All the books I see online are really old, designed for people that have no idea how to program, and/or designed for people who are already know Java to hone their skills.

Adbot
ADBOT LOVES YOU

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Have you looked at The Java Tutorials? From when I've come across them, they seem oriented at someone who is looking for examples of Java features but isn't necessarily completely new to programming.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply