aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How to set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How to set "commentList" attribute in HFSJ p. 441 example?" Watch "How to set "commentList" attribute in HFSJ p. 441 example?" New topic
Author

How to set "commentList" attribute in HFSJ p. 441 example?

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

I try to run the <c:if> example from HFSJ page 441. Please view the following 2 JSP files:

commentsProcess.jsp


inputComments.jsp


Assume a servlet somewhere set the userType attribute, based on the user's login information.

How do I set commentList

Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Originally posted by Darya Akbari:

How do I set commentList


I think the point there is just to ilustrate the c:if part. So, you should assume that commentList has also been set somewhere by any servlet.


Leandro Melo
SCJP 1.4, SCWCD 1.4
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Leandro,

beside the fact that this example holds to describe <c:if>, the provided code is near to completion and I like to fill the gap. Any help to complete this code is appreciated.

I tried to substitute ${commentList} with ${param.input} but that doesn't work out .

So how can we set ${commentList}? Any suggestions ?

Regards,
Darya
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Originally posted by Darya Akbari:

So how can we set ${commentList}? Any suggestions ?


The same way some servlet set the userType attribute!
For instance, the same servlet that set the userType attr could have set commentList attr.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Leandro,

a hardcoded solution is not the way it is intended to be .

To me is a hint that another JSP file (commentsProcess.jsp) is intended to do the job and not a Servlet. And this other JSP is to my opinion again the first JSP file I posted at the begin.

There we have a commentList attribute which must somehow be related to input attribute (<textarea> in JSP file inputComments.jsp).

How would you do it without another Servlet, only with JSP :roll: ?

Regards,
Darya
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
No Darya, I'm afraid you're wrong.
Pay a little more attention to the example.

The file commentProcess.jsp is NOT being displayed. It's just there to virtually describe the this little chunck of code should be used to someone that's posting some comment.

Particularly in the case of the example, you can imagine this cenario like this (take a look on the url requested by the pictures - you need to take a carefull look on the browser's bar):

Step 1 - user requested http://localhost:8080?testJSP/Tester.do (take a look at both pictures on the page and you'll see this URL).

Step 2 - some servlet that is somehow mapped to process this request sets the commentList attribute and the userType attribute like I described earlier. Then, this servlet dispatches to some view - in this case, the view is actually the JSP which has the "c:if" code. Let's call this JPS as MajorJSP.

Step 3 - The MajorJSP realizes that the userType is a member, so it tells the container to include some other code in it. This other code is actually the inputComments.jsp.

Step 4 - The user now can see the part of the page where he/she can input his/her comments. So the supposelly write a comment and hit the submit button, which has a value "Add Comment". Then, this request is send to some other JSP (the third one) called commentsProcess.jsp to proccess the user comment just added. This jsp (commentProcess.jsp) is not being showed on the page.

Got the point now?
[ July 31, 2005: Message edited by: Leandro Melo ]
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Leandro,

I appreciate your comments , however I still didn't get it all. I agree with you on Step 1, Step 3 and Step 4. However I do NOT agree on Step 2's first part:
some servlet that is somehow mapped to process this request sets the commentList attribute ...
because page inputComments.jsp contains this line:

To me it says that NOT another second servlet is handling this request BUT the JSP file commentsProcess.jsp, which takes the input from inputComments.jsp due to post, is handling the commentList attribute.

Now, let's say we have the following files:

  • MajorJSP.jsp (given)
  • inputComments.jsp (given)
  • commentsProcess.jsp (unknown so far, but I want this)
  • MemberServlet.java (Servlet that represent Tester.do and set userType = "member" upon request)
  • web.xml (mappig MemberServlet/Tester.do)



  • How does commentsProcess.jsp looks like ? Any suggestions are welcome

    Regards,
    Darya
    Leandro Melo
    Ranch Hand

    Joined: Mar 27, 2004
    Posts: 401
    Originally posted by Darya Akbari:

    How does commentsProcess.jsp looks like ? Any suggestions are welcome


    Darya, there's no second servlet!!! There's just one.
    The commentsProcess.jsp is NOT there. It's just for us to imagine how it would handle the user input comment!
    The commentList attribute has NOTHING to do with the commentsProcess.jsp. Take a look at the pictures.
    The value of the commentList attributes is this:

    ------------------------------
    This site rocks.

    This site is cool.

    This site is stupid.
    ------------------------------

    The commentList is (supposedly) set by the SAME servlet the sets the userType attribute. Take a look at both pictures on that page. The first one is for the case when the "c:if" returns TRUE. The second picture is for the case when the "c:if" returns FALSE. So, in the second picture, the inputComments.jsp is NOT present, because the "c:if" returned FALSE. So, also the is not present either. However the commentList is there anyway, because it was to by the servlet the dispatched to the MajorJSP.

    Well, that's my last shot!
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Leandro,

    whether that is your last shot or not we will see . I know what you say, it's already explained on HFSJ p. 441.

    You miss the point . The point is: I WANT TO FILL THE GAP

    Or in other words, I take this as an exercise and want to make this incomplete example (p. 441) complete. I want this example to become something tangible or better said runnable.

    If you feel you can provide a runnable solution then I very much appreciate to see your solution based on p. 441 otherwise let others come forward.

    Regards,
    Darya
    Leandro Melo
    Ranch Hand

    Joined: Mar 27, 2004
    Posts: 401
    Originally posted by Darya Akbari:

    whether that is your last shot or not we will see


    Ok, you win. That was not my last shot :roll:

    What you have been asking since your first post is "how do I set the commentList". You did not understand how this "commentList"
    thing was working. You said that it was not the way that I explained (even when I explicitly mentioned the steps).
    Ok, try this code then and you'll see how the commentList works.

    NOTE: You have to name the the first jsp on page 441 by MajorJSP, like this.
    This is Major.jsp (from page 441)


    DD


    Servlet.


    commentsProcess.jsp
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Leandro,

    no no no, I am not looking for a hardcoded solution as I said previously.

    Why do you think is the Add Comment button? It's there to add comments dynamically. So use it.

    You always ship around the real challenge. To hardcode the entries and to assign them to commentList is like you want to betray me. You are definitly not filling the gap.

    And remember you should post here a runnable version!

    Regards,
    Darya
    Leandro Melo
    Ranch Hand

    Joined: Mar 27, 2004
    Posts: 401
    Originally posted by Darya Akbari:

    no no no, I am not looking for a hardcoded solution as I said previously.


    Ok then, so just imagine that you have a DB access that returns a List with all the records. And then you create a String with the List, the same way, by calling setAttribute().

    Anyway, to build a working solution (for a real world) you'd have to have Database access (if you want that, maybe you can find some tutorials or books about accessing DB in j2ee). I'm not posting a real solution because I don't have time. I just don't get why can't you just abstract this part. Whatever...
    I hope at least, that you understand how the commentList attribute got there (which was your primary question).
    I'm done.
    Sorry I couldn't help you to build the real working solution. Anyway, if your second point is building the real thing, is better to go to the JSP/Servlet forums.
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Leandro,

    this is not an easy topic and I really appreciate your efforts to help me out to fill the gap. Unfortunately we couldn't reach a solution.

    Thanks for your patience with me .

    Now, isn't there anyone out there in the SCWCD space who can help ?

    Regards,
    Darya
    Bryan Basham
    author
    Ranch Hand

    Joined: Apr 30, 2001
    Posts: 199
    Hello Darya,

    I think what you are looking for is the code for commentsProcess.jsp.

    I would do something like this:


    Note that this JSP should really be a servlet as this is a Controller component and in an MVC application you should use servlets (or Struts action objects) for Controller components.

    Also, if this were the code for commentsProcess.jsp, then the code in major.jsp is not quite correct as the output of ${commentList} would not be formatted as the screen snapshots show.

    But, this code solves the problem you want to solve. I hope!

    Cheers,
    Bryan
    [ August 02, 2005: Message edited by: Bryan Basham ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to set "commentList" attribute in HFSJ p. 441 example?