Tuesday, March 1, 2011

Why am I getting two section headers on this grouped table?

I'm sure this is some easy-to-fix issue that I've missed, but I can't figure it out. I've got a grouped table view with 3 sections. I'm using the following code to generate section headers:

-(NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
NSString *header = @"Header 1";
return header;
}
if (section == 1) {
NSString *header = @"Header 2";
return header;
}
else {
NSString *header = @"Header 3";
return header;
}
}

When my table is displayed, there are two headers for each section - one with white text on a gray bar that stretches across the screen (like the letter separators in the Contacts app), and one in gray text on the table background (which is the one I want). Both headers have identical text. Where is the first header coming from?

From stackoverflow
  • The code you have presented looks completely normal (though it probably is generating a warning for not having a return null; at the end. The issue is somewhere else, but there's no way to determine what that is with what you've given.

    Andy : What else do you need me to post? As far as I know, this is the only place in the code that deals with table headers.
    Ed Marty : Well, the problem you describe is a really bizarre one. Is there any point where you try to change the style of the table view from plain to grouped? Or any where you combine cells from two different tables? Or do you have a method for returning a _view_ for a title instead of a string?
    Andy : Ah, okay. I don't think there's any point where I try to change the type; I drag-and-dropped the tableview onto the view in IB, and set its style to 'grouped.' Nowhere do I combine cells, although it occurs to me that I used the generic cell identifier in both tables; maybe I should change one of them? Not sure how that affects the headers, but maybe it does. And I'm only using strings for the header text; no views.
    Andy : I went into IB and changed the table style from "grouped" to "plain," without changing any of the code in Xcode. Upon running, the grouped table has changed to a plain table, but the headers with the white text on the gray bars are still there, clearly coming from my code above. So, I've managed to code the headers I don't want, but I'm somehow getting those PLUS the headers I DO want - and I STILL don't know how the ones I do want are getting there.

Monday, February 21, 2011

User Messages Database Schema?

This is probably very subjective and I have my own thoughts on this, but how would one go about constructing a database that supports user to user messages (one to one or one to many).

My original thought was to have a MESSAGE table and MESSAGE_PARTIES table

MESSAGE would include the following fields: -ID, Subject, Body, Created On, Parent MSG ID (for replies)

MESSAGE PARTIES fields would include: -ID, Message ID, Sender ID, Recipient ID, Sent On

Is this sound logic? I'm dying to know what the better/more efficient way is.

From stackoverflow
  • You're not quite right with MESSAGE PARTIES. Given your current setup, you're able to specify multiple senders and multiple dates (more precisely, you're able to specify multiple combinations of sender, recipient, and date). This is not like any messaging system I'm familiar with, and likely not what you intended (it also doesn't match your description).

    A more suitable layout would put the sender and "sent on" fields in the MESSAGE table, then just ID, Message ID, and Recipient ID in the MESSAGE PARTIES table.

Best book to learn java web programming (for an experienced perl developer)

I'm an experienced perl developer who commonly uses Catalyst/Moose etc for web development, and have some python/django knowledge. I'm interested in learning java with an eye on wicket/spring/hibernate and later on possibly moving towards groovy, scala or closure.. I'd rather not plough through all the basics.. What do you recommend book-wise to get going?

From stackoverflow
  • To learn the java web application architectural approach read Beginning Java EE 6 Platform with GlassFish 3: From Novice to Professional

    Tom : thanks for the recommendation - i shall check it out.
  • I wrote Java SE code for a year before I managed to understand the concepts behind Java EE. I only got my head around it when I read the Google App Engine starting guide.

    The most important thing to comprehend is the Servlet pattern and the JSP format. A servlet is a Java class bound to a specific URI by (most often) by XML.

    The Servlet class implements a method (doGet() or doPost()) accepting some parameters:

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    
        response.getWriter().println("Hello, World!");
    
    }
    

    Will yield "Hello, World!" when accessing the URI associated with this HttpServlet class.

    It's really the same principles as in PHP/Perl framework but with Java being a typed language the "You're not calling the Framework, the Framework is calling you" becomes more apparent.

    With regards to Hibernate/ORM libraries, no (?) Java frameworks are bundled with an ORM library as such. There are several independent implementations of the Java Persistence API with Java Persistence Annotations (JPA) being the most recent (and hottest) standard. JPA would be the persistence implementation most closely mimicking the Perl/PHP ORM method of defining a User or BlogPost class as a model. DataNucleus (a JPA implementation) has migrations built in.

    Tom : Thanks, good tip on the GAE guide. I did follow that and it got me started but I feel like I need something to get me moving on from there.

URLLoader handler in child movie not being called.

Hi I am writing a flex application that has a MainMovie that loads flex programs (ChildMovie) depending on what the user selects in the MainMovie. below is some pseudocode to help me describe my problem hopefully.

class MainMovie{

  private var request:URLRequest = new URLRequest();

  public function callPHPfile(param:String, loader:URLLoader,   
             handlerFunction:Function):void {

    var parameter:URLVariables=new URLVariables();
    parameter.param = param;
    request.method = URLRequestMethod.POST;
    request.data = parameter;
    request.url = php file on server;
    loader.addEventListener(Event.COMPLETE, handlerFunction);
    loader.load(request);
  }

}

Class ChildMovie {

   private var loaderInChild:URLLoader = new URLLoader();

   public function handlerInChild(e:Event):void {
      process data....
      loaderInChild.removeEventListerner(Event.COMPLETE, handlerInChild);
   }  



   private function buttonClickHandler(e:Event):void{
      Application.application.callPHPfile(param, loaderInChild, handlerInChild)
   }
}

I can see that the callPHPfile function is being executed and received xml data from in httpFox, the problem is that the code in the handlerInChild function is not being executed. What am I doing wrong here?

From stackoverflow
  • It was a runtime error. I forgot that i uninstalled flash player debugger in firefox and it didn't show. in the handlerInChild function, there is a line

    var data:XML = loader.data;
    

    it should be

    var data:XML = XML(loader.data);
    

    and the code will run as expected.

Mysql incremental Backup

Hello Everyone,

Can anyone help me to take incremental backup in mysql.

i had some idea about that but it is not cleared in my mind ,

please give solutions in steps

Thanks in advance!!!

Riddhi

From stackoverflow

Is it possible to add a single row to a Django form?

I have a form along the lines of:

class aForm(forms.Form):
  input1 = forms.CharField()
  input2 = forms.CharField()
  input3 = forms.CharField()

What I'm hoping to do is add an additional input3 to the form when the user clicks an "add another input3".

I've read a bunch of ways that let me add new forms using formsets, but I don't want to append a new form, I want to just add a new input3.

Is this possible?

From stackoverflow
  • I would define input3 in your form definition, not require it, and then hide it by default. The user can then show the input using JavaScript.

    If you want to allow the user to add an undefined amount of additional inputs, I would look further into formsets.

  • Perhaps something like this:

    from django import forms
    from django.utils.datastructures import SortedDict
    def some_view(request):
        data = {}
    
        # Using session to remember the row count for simplicity
        if not request.session.get('form_rows', None):
            request.session['form_rows'] = 3
    
        # If posted with add row button add one more row
        if request.method == 'POST' and request.POST.get('rows', None):
                request.session['form_rows'] += 1
                data = request.POST
    
        # Create appropriate number of form fields on the fly
        fields = SortedDict()
        for row in xrange(1, request.session['form_rows']):
            fields['value_{0}'.format(row)] = forms.IntegerField()
    
        # Create form class
        MyForm = type('MyForm', (forms.BaseForm,), { 'base_fields': fields })
    
        form = MyForm(initial=data)
    
        # When submitted...
        if request.method == 'POST' and not request.POST.get('rows', None):
            form = MyForm(request.POST)
            if form.is_valid():
                # do something
        return render_to_response('some_template.html', {
            'form':form,
        }, context_instance=RequestContext(request))
    

    With template:

    <form action="" method="post">
        {{ form }}
        <input type="submit" />
        <input type="submit" value='Add' name='rows' />
    </form>
    

    This is over simplified but it works.

    You could easily modify this example so you can make request using AJAX and just replace old form with new one.

  • for adding dynamic fields overwrite the init method.

    Something like this:

    class aForm(forms.Form):
      input1 = forms.CharField()
      input2 = forms.CharField()
    
      def __init__(self, addfields=0, *args, **kwargs):
        super(aForm, self).__init__(*args, **kwargs)
    
        #add new fields
        for i in range(3,addfields+3)
           self.fields['input%d' % i] = forms.CharField()
    

how to delete specific number of rows using jquery provided by argument

i have a sample code. This will delete entire row if nor args provided. If provided it will delete the given rows.

function deleteTableRows(tableID)
{
        rowsToDel = document.getElementById('getrows').value;
        if(document.getElementById(tableID) !== undefined)
        {
                var tbl = document.getElementById(tableID);
                var deleteAll = false;
                if(rowsToDel ==null || rowsToDel == "")
                {
                        rowsToDel = tbl.rows.length;
                        deleteAll = true;
                }
                if(deleteAll)
                {
                        while(rowsToDel > 0)
                        {
                                tbl.deleteRow(rowsToDel - 1);
                                rowsToDel = tbl.rows.length;
                        }
                }
                else
                {
                        while(rowsToDel > 0)
                        {
                                tbl.deleteRow(rowsToDel - 1);
                                rowsToDel = rowsToDel - 1;
                        }
                }
        }
}

How to do this in jquery

From stackoverflow
  • See a working example

    function deleteTableRows(table, rowsToDelete) {
        table = $(table);
        var rows = table.find('> tbody > tr');
        rows.slice(-(rowsToDelete || rows.length)).remove();
    }
    

    Moved the rowsToDelete parameter inside the function to remove the external dependency on the #getrows element.

    Also, changed the table parameter so we can pass the DOM element, or a selector, or a jQuery wrapped object to select which table.