> I just want to make sure I understand exactly what 
> you want before I describe a solution

Rick, thanks for your reply - i already have a
solution working together with displaytag as i pointed
out - however i asked if there is a proper way to do
it which differs from mine.

I want not to only display data as pointed out, but be
able to manipulate all data which is currently
displayed to the user - i.e. save, update, delete
similar to the FAQ example but for every entry not
only for one.

My example approach which works is the following, i
store the currently displayed entries into a session
var - after submit i iterate through all entries in
the session var and do a lookup for every input field
using the systax
request.getParameter("somefield_"+someObj.id) - this
way i can retrieve all input fields, i need to do it
this way because i do not know which entries the
display tag library currently renders to the user
(because of pagination and sorting).

Furthermore i try to parse the pagination url params
from the request to include the url params in my
custom links or for saving the current page :

<%@ taglib uri="http://displaytag.sf.net";
prefix="display" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt";
prefix="c" %>

<%

        // list of which entires are currently displayed to
the user BEFORE submit
        // needed for save to figure out which entries should
be changed, session var is changed within the
display:column tag
        ArrayList entryListDisplayed =
(ArrayList)session.getAttribute("entryListDisplayed");


        // remember the current sorting if we save a table or
use javascript
        // retrieves current url parameters i.e.
p=21232=1&s=3232        
        String orderParams =
getDisplayTagOrderParams(request);


        String doAction = request.getParameter("doAction");     

        // example save method will update all currently
displayed user names
        if (doAction.equalsIgnoreCase("save")) {


                if(entryListDisplayed !=null) {
                        
                        for(int i=0; i < entryListDisplayed.size();
i++) {
                                
                                User currentUser =
(User)entryListDisplayed.get(i);
                                
                                String name = request.getParameter("name_"
+ currentUser.getId());
                                currentUser.setName(name);
                        
                        
myDatabaseBean().updateUser(currentUser);             
          
                                        
                                }                                               
                

                        }
                        
                }       

        }         
%>

<html>
<form action='users.jsp<%=orderParams%>'
method='POST'>
<%      

   Users[] userList = myDatabaseBean().getUsers();

   request.setAttribute("entryList",
Arrays.asList(userList) ); 

   // reset entries
   entryListDisplayed = new ArrayList();           
%>
 <display:table id="user" name="entryList"
defaultsort="1" defaultorder="ascending"
pagesize="10">
  <display:column title="User Name">
        <%     
           // memorize entires which are currently shown
          entryListDisplayed.add(user);
          session.setAttribute("entryListDisplayed", 
entryListDisplayed);
        %>
        <input type=input name="name_${user.id}"
value="${user.name}">   
  </display:column>
</display:table>

<input type="submit" value="Save">
</form>


</html>

--- Rick Herrick <[EMAIL PROTECTED]> wrote:

> Again, displaytag is a tag library for displaying
> things.  You're asking for
> a very open-ended form management tool.  That isn't
> what displaytag is.  It
> does the job for which it's designed very well.  It
> shouldn't be surprising
> that you find that a hammer is not so good for
> screwing in bolts.
> 
> You'll notice that there are NO functions whatsoever
> in displaytag to handle
> processing posted form data.  That's quite
> deliberate.  That doesn't mean
> that it can't be a part of your solution though. 
> Just don't ask it to do
> something it's not meant to do.
> 
> That said, I think you can quite easily use
> displaytag to generate the form
> that you want.  Can you please describe what you
> would like to do?  If you
> can create some HTML that shows an example of the
> type of form you'd like to
> show to your users would be good also.  If I
> understand what you want to do,
> I think I've implemented a number of solutions that
> do almost exactly what
> you want.  I just want to make sure I understand
> exactly what you want
> before I describe a solution, as in the past I've
> solved an entirely
> different problem from what people were asking for
> :)
> 
> Rick Herrick
> [EMAIL PROTECTED]
> 
> 
> > -----Original Message-----
> > From:
> [EMAIL PROTECTED]
> [mailto:displaytag-
> > [EMAIL PROTECTED] On Behalf Of
> Harakiri
> > Sent: Monday, May 29, 2006 6:23 AM
> > To: [email protected]
> > Subject: [displaytag-user] Editing / Saving ALL
> current displayed
> > entriespossible - but bad design
> > 
> > Hi list,
> > 
> > the demo of editing and saving entries using
> display
> > tag
> >
> http://demo.appfuse.org/appfuse/demos/users-edit.jsp
> > has the obvious limitation of only allowing ONE
> entry
> > to be manipulated at each request (save)
> > 
> > Ive found a simple way to edit all entries current
> > displayed however - the design is bad i think and
> if
> > displaytag would offer more manipulation abilities
> it
> > would not be needed.
> > 
> > Problem 1.
> > 
> > I needed to know WHICH entries the user currently
> > edits / views - displaytag does not tell me that
> on a
> > submit of a formular. If i knew which entries are
> > currently displayed i can manipulate this data
> i.e. by
> > 
> > 
> > ArrayList entryListDisplayed =
> >
>
(ArrayList)session.getAttribute("entryListDisplayed");
> > 
> > // entryListDisplayed - the list of entries which
> > // are currently being edited / viewed by the user
> > for(int i=0; i < entryListDisplayed.size(); i++) {
> > 
> > User currentUser =
> (User)entryListDisplayed.get(i);
> >
>
currentUser.setSomeField(request.getParameter("SOMEFIELD_"
> > + currentUser.getId()));
> > 
> > }
> > 
> > Request for Displaytag :
> > 
> > Displaytag could put the currently viewed members
> of
> > the list into a seperate list and that list into
> the
> > session. i.e.
> > 
> > <display:table id="user" name="entryList"
> > currentlyDisplayed="entryListDisplayed">
> > 
> > My Solution :
> > 
> > As long as display tag does not supply such data
> > manipulation - i have to use something like this :
> > <%
> >    ArrayList entryListDisplayed = new ArrayList();
> > 
> > %>
> > <display:table id="user" name="entryList">
> >   <% User currentUser =
> > (User)pageContext.getAttribute("user"); %>
> > 
> >   <display:column property="name">
> >    <%
> >        // memorize entires which are currently shown
> -
> > needed for save - can be in any column but must be
> > within <column>
> >       entryListDisplayed.add(currentUser);
> >       session.setAttribute("entryListDisplayed",
> > entryListDisplayed);
> >     %>
> >  </display:column>
> > </display:table>
> > 
> > I figured out that any code within a
> display:column
> > tag is only executed for entries which are
> currently
> > rendered i.e. displayed to the user - so now i do
> know
> > which entries the user currently sees.
> > 
> > Problem 2.
> > 
> > With the possibility of editing all currently
> > displayed data on a given page - you should (need)
> to
> > remember on which page you currently are and which
> > sorting you currently use. I.e. the user changes
> some
> > entries on page 4 - after submit he would be on
> page 1
> > again not on page 4. So not only the currently
> > displayed data needs to be hold into a session but
> > also the currently used view parameters (page
> number,
> > sorting etc)
> > 
> > Request for Displaytag :
> > 
> > Either supply a build in function for my own save
> /
> > edit links which adds the current pagination url
> > parameters to my link or store the current sorting
> > into a session var i.e.
> > 
> > <display:column title="Delete User">
> >     <a
> >
>
href="mypage.jsp?action=deleteUser=&id=${user.id}<display:getProperty
> > name=currentPaginationURL>" >Delete</a>
> >   </display:column>
> > 
> > My Solution :
> > 
> > within the list i found somebody else with the
> same
> > problem he wrote a method which extracts the
> current
> > pSOMEVALUE=1 parameters - i modified it a bit to
> > include all parameters and use it now :
> > 
> >  // find the internal url request params from the
> > display tag libary
> >     public String
> > getDisplayTagOrderParams(HttpServletRequest
> myRequest)
> > {
> > 
> >             if(myRequest == null ||
> myRequest.getParameterMap()
> > == null)
> >                     return "";
> > 
> >             java.util.Map pm = myRequest.getParameterMap();
> >             String page_par = null;
> >             String sort_par = null;
> >             String order_par = null;
> > 
> > 
> >             for( int i=0; i<pm.size(); i++){
> >                     java.util.Iterator it = pm.keySet().iterator();
> > 
> >                     while(it.hasNext()){
> >                             String next=it.next().toString();
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to