Edmund Castermund

Ranch Hand
+ Follow
since May 09, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Edmund Castermund

Hi,
I'm writing my first spring boot/hibernate/jpa web app using rest controllers. I'm basically following along online resources such as
this tutorial

My question is, using that particular tutorial as an example, in a case where I make a rest call to the controller:



but in addition to the list of notes that that function returns, I also want a list of most recent comments, recently viewed notes, maybe update some info re: the users status....how do I combine all that info?

Do I use a master controller that has multiple @Auitowired repositories?

thanks!
Hi,

I'm writing a basic crud app that will be a combination of simple structured data and some narrative text. I'm wondering if the following is a good idea for a design concept, and if it's widely used. Say I have a Widget and a ThngAMaBob class, and each has a description field. would it make sense to encapsulate the text like so:




The markdown text would be the main type that the user would enter and edit. On a save, a markdown parser would create the html text, and a function would create a third text field that would strip out all the html tags, and that  plain text would be used for searching.
The advantage to doing it this way, is that I could search just the TextElement table and return any obj associated with it, as opposed to searching each and every obj that contained a text field.

Is that a design commonly used?
Hi guys,

I have been diving into hibernate lately, and am enjoying it, but am wondering if anyone has come across this particular use case. If you have lots of classes like Cat, Dog, Parakeet, etc. and you have them organized with abstract classes and interfaces, is it considered bad form to create an object such as





Then in your DogDAO you would build an AnimalEntity and save it. I think this could simplify the data layer, and add for more search  fluidity.
This seems simpler to me, but I have not come across anyone recommending that particular design. Is it widely used?

Hi

I searched around for an answer to this, but did not really find a direct answer to what I was looking for, so apologies if this is basic, or I missed something I should have found.

I'm looking for a concise description of best practices the relate to the users of a web application, how to maintain their login state, and store their passwords/usernames, etc. The upcoming iteration of this application will be very basic, only used internally and have a handful of users, so security requirements are looser now than  they will be in the future. When this app is rolled out more broadly, I'll likely use apache shiro and/or Spring for all security and user management, but right now I just  want to get something simple, I also want to code it myself, just so I am more aware of the issues to deal with allowing me to take full advantage of the libs mentioned above.

Current plan is to do something like the following (in case of existing user):
  • user logs on with user/pw, system checks if user exists then checks if user/pw is correct (will hash/salt user and pw) if ok, sends back boolean that user is ok and is now logged on
  • will create some form of temp id and store in session obj, will send and retrieve as cookie with http requests, cookie will expire at some point
  • User obj / DB table will have name, basic profile info, and logon status. Most functions of app will require a user to be logged on, or redirect back to logon page



  • is that about right? Anything else I should be  considering, or any good documentation you can recommend?
    thanks!
    6 years ago


    In general, is it fair to say that the normal jsp stuff will only be displayed on the initial load of the page


    Of course. If you don't refresh the age, the JSP isn't going to be rerun. If that's confusing, perhaps this article on how JSP works might be helpful.

    When the Ajax returns with the new data, the elements that were original filled with JSP expression data should be updated with the JSON data.

    ooops...did not read this last sentence...I'll read that article you posted to. Is there a naming convention with regards to the obj->json? so if the java code is:





    then you would need to arrange the json as




    and then ${dude.getName()} will automatically be updated by the ajax call?
    7 years ago
    JSP
    thanks for reply and answering my question.

    As per repeating code, I populate the edit form via an object using a *.tag file. But I can't do that for a subsequent edit that has been made via an ajax call, right?

    So on the initial load the edit form renders populated via jsp, but after an ajax call a new edit form with the updated values needs to be created, and I can't use jsp since we don't have a new http request. So I'm using a javascript template that is update via json on the successful ajax return.

    Am I understanding your comment correctly?
    7 years ago
    JSP
    Hi guys,

    I think I'm doing the right thing, and I've hunted around and can't find anything that directly addresses my situation. I am writing a basic crud app, and this is an example of a basic use case:

  • The page loads and I use ${obj.method()} to populate all the relevant areas. One of the elements that is loaded is an edit form that is stored in a template. *no problem*
  • when I click the edit button, an ajax function fades out the existing html, and fades in the edit form that  is in the template. *also, no problem*
  • When I hit "save" a javascript function makes a jquery ajax call to a servlet, which updates the relevant material in the db, creates an ojb with the updated values, and builds a json obj which it sends back to the javascript function. The new data is displayed properly.  *no problem*
  • When I see I made a typo in my edit, I want to re-edit it, but when I click edit, my new changes are not there. The way I have been working thru this is to create another form edit template that is populated with the new values after the successful ajax call. *is this right??*



  • In general, is it fair to say that the normal jsp stuff will only be displayed on the initial load of the page, and from there javascript/jquery/ajax will do all the work. Is that correct?
    7 years ago
    JSP
    Hi,

    If I have a couple of classes like this:




    and I have a DAO obj for each, which has store(), update() and delete() methods,

    2 questions.

    1) If I want to loop thru a group of WidgetPurchase objects, and in order to exist as an object it has to be a part of a purchaseList, so to build the obj I need the id of the Widget, then build that and ALL of its child purchases for every purchase, so theoretically if a Widget has 3 purchcases, the Widget and the purchaseList will be build for all three purchases... in the googling I have done, hibernate does not handle that kind of thing particularly well. Is that correct?

    2) when you want to update just the one WidgetPurchase what's the best way of isolating that object?

    I suppose you could/should just create the object structure where a purchase can be created in a standalone context, but semantically a WidgetPurchase can't exist without a widget. And in just practical terms when writing web apps, one will typically be passing around db primary keys to be able to build the obj on the server side, correct? Guess I've always held the opinion that loose coupling isn't no coupling, but not sure I'm right about that. Gotta believe this is a pretty common scenario.


    thanks!
    thanks for replies...
    googling around and I think mustache.js is a good option
    8 years ago
    JSP
    so I got that part working. Essentially, when I create the page, I have an html form that is set not to display. Then when a user hits the edit button, the existing html fades out, the form fades in, and the update is done with ajax. Then I fade in the return value from the servlet.

    Is it a best practice to create a hidden form in that way, or should the jquery build the html form? Can that be done from a template?
    8 years ago
    JSP
    Hi,

    Let's say I have class:


    and I have a dogPoundDetail.jsp file that renders the dog pound info, and info about each dog.

    I want an edit button at the dog pound level and at each dog level.

    Assuming I'm updating the dog pound info, what is the best practice for this?

  • link to servlet -> build dog pound obj -> jsp form -> dog pound update servlet -> redirect to updated dog pound detail
  • edit button launches javascript function that alters relevent div to form -> form renders -> servlet to update dog pound data -> redirect to updated dog pound detail
  • edit button launches function that builds popup form with jquery-ui -> form is populated and sent to servlet via ajax -> ??? how to display new data on page this way?


  • I'm a noob with ajax, thanks!


    I also notice that based on these params:


    this forum uses the first option?
    8 years ago
    JSP
    sorry, should have searched more. I can associate the index.jsp with the welcome file list in web.xml, correct?
    8 years ago
    JSP
    Sorry...did not frame question well.

    The old version of the index page had the useBean and scriptlets. I still have the useBean, but have used the EL syntax to output its values on the jsp page.

    As for the useBean issue...in the case of a jsp page, such as an index.jsp that does not have an object that is constructed and then dispatched to the jsp by a servlet...what is the best way to create on object when you need dynamic content?
    8 years ago
    JSP
    ok, stupid, should have just tested. I am using this:



    then just using regular EL type markup in the jsp:



    is that the right way?
    8 years ago
    JSP
    Hi,
    have searched around for this and can't believe I don't know the answer...

    currently an app I'm working on has an index.jsp file that needs some dynamic content. Since that does not hit a servlet first, I am using the jsp:useBean property and using scriptlets, which I know is not the best practice.

    How do you create an obj when you are not building in a servlet, adding as an attribute to the request, and then forwarding to the jsp?
    Thanks!
    8 years ago
    JSP